import 'package:animate_do/animate_do.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:get/get.dart';

import 'package:nomo/app/base/base_view.dart';
import 'package:nomo/app/widgets/ix_image.dart';
import 'package:nomo/config/theme/theme_extensions/theme_extension.dart';
import '../../../constants/assets.dart';
import '../../../widgets/privacy_agreement.dart';
import '../controllers/splash_controller.dart';

class SplashView extends BaseView<SplashController> {
  const SplashView({super.key});

  @override
  bool get safeArea => false;

  @override
  bool get resizeToAvoidBottomInset => false;

  @override
  Widget buildContent(BuildContext context) {
    return SafeArea(
      child: Column(
        children: [
          Expanded(child: _buildContent()),

          // 底部内容
          _buildBottomContent(),
        ],
      ),
    );
  }

  // 已登录状态的内容
  Widget _buildContent() {
    return Center(
      child: Stack(
        alignment: Alignment.topCenter,
        children: [
          Container(
            margin: EdgeInsets.only(top: 120.w),
            child: IXImage(
              source: Assets.splashCenterBg,
              width: 356.w,
              height: 356.w,
              sourceType: ImageSourceType.asset,
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: 52.w),
            child: IXImage(
              source: Assets.splashLogo,
              width: 104.w,
              height: 148.w,
              sourceType: ImageSourceType.asset,
            ),
          ),
        ],
      ),
    );
  }

  // 构建底部内容
  Widget _buildBottomContent() {
    return Container(
      padding: EdgeInsets.only(bottom: 20.h),
      child: Obx(
        () => !controller.hasLogin
            ? FadeInUp(
                duration: const Duration(milliseconds: 700),
                delay: const Duration(milliseconds: 800),
                child: PrivacyAgreement(
                  textColor: Get.reactiveTheme.textTheme.bodyLarge!.color,
                  linkColor: Get.reactiveTheme.primaryColor,
                  height: 1.8,
                ),
              )
            : FadeInUp(
                duration: const Duration(milliseconds: 600),
                child: Column(
                  children: [
                    Obx(
                      () => controller.showLoading
                          ? SpinKitRing(
                              size: 24.w,
                              lineWidth: 2.w,
                              color: Get.reactiveTheme.primaryColor,
                            )
                          : const SizedBox.shrink(),
                    ),
                    16.verticalSpaceFromWidth,
                    Text(
                      'V${controller.versionName}',
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        color: Get.reactiveTheme.textTheme.bodyLarge!.color,
                        fontSize: 14.sp,
                      ),
                    ),
                  ],
                ),
              ),
      ),
    );
  }
}
