import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:location/base/base_page.dart';
import 'package:location/resource/colors.gen.dart';
import 'package:location/router/app_pages.dart';
import 'package:location/utils/common_expand.dart';
import 'package:video_player/video_player.dart';
import '../../resource/assets.gen.dart';
import '../../widget/common_view.dart';
import 'location_analyse_controller.dart';

class LocationAnalysePage extends BasePage<LocationAnalyseController> {
  LocationAnalysePage({super.key}) {
    Get.lazyPut(() => LocationAnalyseController(), fenix: true);
  }

  static void start() {
    Get.toNamed(RoutePath.locationAnalyse);
  }

  @override
  bool immersive() {
    return true;
  }

  @override
  Widget buildBody(BuildContext context) {
    return Container(
      width: double.infinity,
      height: double.infinity,
      decoration: BoxDecoration(
          gradient: LinearGradient(colors: [
        ColorName.white,
        '#D8D8FE'.color,
      ], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
      child: Stack(
        children: [buildBackBtnView(), buildAnalyseView()],
      ),
    );
  }

  Widget buildAnalyseView() {
    return SizedBox(
      width: double.infinity,
      height: double.infinity,
      child: SingleChildScrollView(
          child: Column(
        children: [
          buildAIAnalyseView(),
        ],
      )),
    );
  }

  Widget buildAIAnalyseView() {
    return Stack(
      alignment: Alignment.center,
      children: [
        Assets.images.bgLocationAnalyse.image(width: double.infinity),
        buildRobotView(),
      ],
    );
  }

  Widget buildRobotView() {
    return SizedBox(
      width: 248.w,
      height: 248.w,
      child: Stack(
        children: [
          Assets.images.bgLocationAnalyseAi
              .image(width: double.infinity, height: double.infinity),
          Center(
            child: ClipOval(
              child: SizedBox(
                width: 144.w,
                height: 144.w,
                child: Obx(() {
                  if (!controller.videoReady) {
                    return Center(child: Text('视频还没准备好'));
                  }
                  return Transform.scale(
                    scale: 1.012, // 放大 3%，可以试试 1.01 ~ 1.05
                    child: VideoPlayer(controller.bgController),
                  );
                }),
              ),
            ),
          )
        ],
      ),
    );
  }

  Widget buildBackBtnView() {
    return SafeArea(
      child: GestureDetector(
        onTap: controller.back,
        child: Container(
          margin: EdgeInsets.only(top: 14.w, left: 12.w),
          decoration: BoxDecoration(boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.05),
              blurRadius: 10.w,
              offset: Offset(0, 2.w),
            ),
          ]),
          child: CommonView.getBackBtnView(),
        ),
      ),
    );
  }
}
