import 'package:flutter/material.dart';
import 'package:flyinsono/global.dart';
import 'package:flyinsono/lab/color/lab_colors.dart';
import 'package:flyinsono/lab/manager/page_manager.dart';
import 'package:flyinsono/lab/pages/lab_data/widgets/widgets.dart';
import 'package:flyinsono/lab/router/lab_route_names.dart';
import 'package:get/get.dart';
import 'package:fis_common/index.dart';
import 'index.dart';

class LabDataPage extends GetView<LabDataController> {
  const LabDataPage({
    Key? key,
  }) : super(key: key);

  // 主视图
  Widget _buildView() {
    return Obx(
      () => controller.state.noData
          ? _buildNoPatientTip()
          : Row(
              children: [
                _buildLeftPart(),
                Expanded(
                  child: _buildMainContent(),
                ),
                SizedBox(width: 10),
              ],
            ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<LabDataController>(
      init: LabDataController(
        tabHashCode: this.hashCode,
      ),
      builder: (_) {
        return Scaffold(
          backgroundColor: LabColors.base300,
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }

  Widget _buildLeftPart() {
    return Container(
      width: 300,
      height: double.infinity,
      padding: EdgeInsets.all(10),
      child: DataSourcePanel(),
    );
  }

  Widget _buildMainContent() {
    return Obx(() {
      if (controller.state.noPatient) {
        return _buildNoPatientTip();
      }
      if (controller.state.noRecord) {
        return _buildNoRecordTip();
      }
      return Container(
        height: double.infinity,
        padding: EdgeInsets.symmetric(vertical: 10),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            // OperateBar(),
            // SizedBox(height: 5),
            RecordList(),
            SizedBox(height: 10),
            Expanded(
              child: USImagePool(),
            ),
          ],
        ),
      );
    });
  }

  Widget _buildNoRecordTip() {
    return Center(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Container(
            height: 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,
              ),
            ),
          ),
          SizedBox(
            height: 10,
          ),
          Text(
            "该样本下暂无数据",
            style: TextStyle(
              color: LabColors.text600,
              fontSize: 16,
            ),
          ),
          SizedBox(
            height: 30,
          ),
        ],
      ),
    );
  }

  Widget _buildNoPatientTip() {
    return Center(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Container(
            height: 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,
              ),
            ),
          ),
          SizedBox(
            height: 10,
          ),
          Text(
            "该项目内暂无数据",
            style: TextStyle(
              color: LabColors.text600,
              fontSize: 16,
            ),
          ),
          SizedBox(
            height: 30,
          ),
          if (!FPlatform.isPureWeb) ...[
            Column(
              children: [
                Text(
                  "请先导入数据",
                  style: TextStyle(
                    color: LabColors.text700,
                    fontSize: 14,
                  ),
                ),
                SizedBox(
                  height: 10,
                ),
                Container(
                  // width: 120,
                  height: 40,
                  child: ElevatedButton.icon(
                    icon: const Icon(Icons.file_download_outlined),
                    style: ElevatedButton.styleFrom(
                      elevation: 0.0,
                      backgroundColor: LabColors.buttonColor,
                    ),
                    label: const Text("去导入"),
                    onPressed: () {
                      PageManager.ins.openNewTab(LabRouteNames.Import, "导入数据",
                          multiple: false,
                          args: controller.selectedDataSourceId);
                    },
                  ),
                ),
              ],
            ),
          ],
        ],
      ),
    );
  }
}
