import 'package:flutter/material.dart';
import 'package:flyinsono/lab/color/lab_colors.dart';
import 'package:flyinsono/lab/components/lab_loading_wrapper.dart';
import 'package:flyinsono/lab/pages/lab_image/widgets/image_trace/view.dart';
import 'package:flyinsono/lab/pages/lab_image/widgets/widgets.dart';
import 'package:get/get.dart';
import 'index.dart';
import 'widgets/widgets.dart';

class LabBatchAnalysisPage extends GetView<LabBatchAnalysisController> {
  const LabBatchAnalysisPage({Key? key, this.initArguments}) : super(key: key);

  final dynamic initArguments;

  get tabHashCode => this.hashCode.toString();

  @override
  String? get tag => tabHashCode;

  // 主视图
  Widget _buildView() {
    return Row(
      children: [
        _buildLeftPart(),
        Expanded(
          child: Row(
            children: [
              Expanded(
                child: _buildMainContent(),
              ),
              _buildRightPart()
            ],
          ),
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<LabBatchAnalysisController>(
      init: LabBatchAnalysisController(
        tabHashCode: this.hashCode,
        initArguments: initArguments,
      ),
      tag: tabHashCode, // 如果一个页面要想实现多开，必须加 tag，且 tag 要传入每一个子组件
      id: LabBatchAnalysisController.labBatchAnalysisId,
      builder: (_) {
        return Scaffold(
          backgroundColor: LabColors.base300,
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }

  Widget _buildLeftPart() {
    return Container(
      width: 300,
      height: double.infinity,
      padding: EdgeInsets.all(10),
      child: ImageDataToAnalysis(
        tabHashCode: tabHashCode,
        initController: controller.imageDataToAnalysisController,
      ),
    );
  }

  Widget _buildMainContent() {
    return Container(
      height: double.infinity,
      padding: EdgeInsets.symmetric(vertical: 10),
      child: Obx(
        () => LabLoadingWrapper(
          loading: controller.state.isImageDownloading,
          child: Container(
            decoration: BoxDecoration(
              color: Colors.black,
              borderRadius: BorderRadius.circular(5),
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                SizedBox(height: 40),
                Expanded(
                  child: Stack(
                    children: [
                      ImageDataPlayer(
                        initController: controller.imageDataPlayerController,
                        tabHashCode: tabHashCode,
                      ),
                      ImageRoiOverlay(
                        initController: controller.imageRoiOverlayController,
                        tabHashCode: tabHashCode,
                      ),
                    ],
                  ),
                ),
                ProgressPanel(
                  initController: controller.progressController,
                  tabHashCode: tabHashCode,
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  Widget _buildRightPart() {
    return Container(
      width: 350,
      height: double.infinity,
      padding: EdgeInsets.all(10),
      child: UrmOperatePanel(
        initController: controller.urmOperatePanelController,
        tabHashCode: tabHashCode,
        parentController: controller,
      ),
    );
  }
}
