import 'package:flutter/material.dart';
import 'package:flyinsono/global.dart';
import 'package:flyinsono/lab/color/lab_colors.dart';
import 'package:flyinsono/lab/components/control_panel_item/control_item_slider.dart';
import 'package:flyinsono/lab/pages/lab_batch_analysis/index.dart';
import 'package:flyinsono/lab/pages/lab_image/widgets/image_roi_sync/view.dart';
import 'package:flyinsono/lab/style/lab_box_decoration.dart';
import 'package:get/get.dart';
import 'index.dart';

class UrmOperatePanel extends GetView<UrmOperatePanelController> {
  const UrmOperatePanel({
    Key? key,
    required this.initController,
    required this.parentController,
    required this.tabHashCode,
  }) : super(key: key);

  @override
  String? get tag => tabHashCode;

  final String tabHashCode;

  final UrmOperatePanelController initController;
  final LabBatchAnalysisController parentController;

  @override
  Widget build(BuildContext context) {
    return GetBuilder<UrmOperatePanelController>(
      init: initController,
      tag: tabHashCode,
      id: UrmOperatePanelController.urmOperatePanelId,
      builder: (_) {
        return Column(
          children: [
            Expanded(
              child: _buildAdjustPanelInUrmMode(),
            ),
            SizedBox(
              height: 10,
            ),
            _buildUrmInfoPanel(),
          ],
        );
      },
    );
  }

  Widget _buildAdjustPanelInUrmMode() {
    return Column(
      children: [
        Expanded(
          child: Container(
            decoration: LabBoxDecoration.operatePanel,
            padding: EdgeInsets.all(10),
            child: Column(
              children: [
                Expanded(
                  child: controller.isURMData
                      ? _buildUrmAdjustPanel()
                      : _buildUnsupportUrmTip(),
                ),
              ],
            ),
          ),
        ),
      ],
    );
  }

  Widget _buildUrmAdjustPanel() {
    return ListView(
      children: [
        // ControlItemSlider(
        //   itemText: "VSpeckle",
        //   minValue: 0,
        //   maxValue: 3,
        //   currentValue: 2,
        // ),
        // SizedBox(
        //   height: 10,
        // ),
        // ControlItemSlider(
        //   itemText: "运动补偿",
        //   minValue: 0,
        //   maxValue: 7,
        //   currentValue: 2,
        // ),
        RoiSyncView(
          iniitController: parentController.imageRoiSyncController,
        ),
        SizedBox(
          height: 10,
        ),
      ],
    );
  }

  Widget _buildUnsupportUrmTip() {
    return SizedBox.expand(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Flexible(
            child: Container(
              constraints: BoxConstraints(
                maxHeight: 200,
              ),
              child: ColorFiltered(
                colorFilter:
                    ColorFilter.mode(LabColors.base400, BlendMode.srcIn),
                child: Image.asset(
                  Global.isVStationSlave
                      ? "assets/images/logo_icon_0.png"
                      : "assets/images/logo_icon.png",
                  filterQuality: FilterQuality.medium,
                  isAntiAlias: true,
                  fit: BoxFit.contain,
                ),
              ),
            ),
          ),
          Flexible(
            child: SizedBox(
              height: 10,
            ),
          ),
          Flexible(
            child: Text(
              "该图像不支持 URM 分析",
              style: TextStyle(
                color: LabColors.text600,
                fontSize: 16,
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildUrmInfoPanel() {
    return GetBuilder<UrmOperatePanelController>(
      tag: tabHashCode,
      id: UrmOperatePanelController.urmInfoPanelId,
      builder: (_) {
        return Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                Text(
                  "已框选 ROI：",
                  style: TextStyle(fontSize: 16, color: LabColors.text700),
                ),
                Text(
                  "${controller.roiSelectedCount} / ${controller.totalUrmCount}",
                  style: TextStyle(
                    fontSize: 20,
                    color: LabColors.text800,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ],
            ),
            SizedBox(
              height: 5,
            ),
            Text(
              "注：未框选 ROI 的图像将执行全图分析",
              style: TextStyle(fontSize: 12, color: LabColors.text700),
            ),
            SizedBox(
              height: 10,
            ),
            Container(
              width: double.infinity,
              height: 50,
              child: ElevatedButton.icon(
                icon: const Icon(Icons.play_arrow_outlined),
                style: ElevatedButton.styleFrom(
                  elevation: 0.0,
                  backgroundColor: LabColors.buttonColor,
                ),
                label: const Text("开始批量分析"),
                onPressed: controller.onClickUrmBatchAnalysis,
              ),
            ),
          ],
        );
      },
    );
  }
}
