import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/architecture/router/mobile/names.dart';
import 'package:flyinsono/views/wechat_mini_program/wx_public_widgets/wx_scaffold.dart';
import 'package:flyinsono/views/wechat_mini_program/wx_public_widgets/wx_screen_direction_lock.dart';
import 'index.dart';

class WxConsultationDetailPage extends FisView<WxConsultationDetailController> {
  const WxConsultationDetailPage({Key? key}) : super(key: key);

  @override
  FWidget build(BuildContext context) {
    return FisBuilder<WxConsultationDetailController>(
      builder: (_) {
        return WxScreenDirectionLock(
            direction: ScreenDirection.vertical,
            page: WxScaffold(
              title: "会诊详情",
              parentRoute: MobileRouteNames.Wechat.MiniProgramConsultation,
              body: Column(
                children: [
                  FExpanded(child: _buildView()),
                  Container(
                    padding: EdgeInsets.all(10),
                    color: Color.fromARGB(255, 247, 247, 247),
                    child: InkWell(
                      onTap: () {
                        controller.handleStartConsultation();
                      },
                      child: Container(
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(5),
                            color: Colors.blue,
                          ),
                          padding: EdgeInsets.all(10),
                          child: Center(
                              child: Text(
                            '开始会诊',
                            style: TextStyle(color: Colors.white),
                          ))),
                    ),
                  ),
                ],
              ),
            ));
      },
    );
  }

  // 主视图
  FWidget _buildView() {
    return QuickFWidget(
      FListView(
        children: [
          _buildTextDividingLine("患者信息"),
          _buildSingleLineInfo("姓名", controller.state.name),
          _buildDividingLine(),
          _buildSingleLineInfo("性别", controller.state.sex),
          _buildDividingLine(),
          _buildSingleLineInfo("出生日期", controller.state.birthday),
          _buildDividingLine(),
          _buildSingleLineInfo("年龄", controller.state.age),
          _buildDividingLine(),
          _buildSingleLineInfo("手机号码", controller.state.mobile),
          _buildDividingLine(),
          _buildSingleLineInfo("ID", controller.state.id),
          _buildDividingLine(),
          _buildMultiLineInfo("既往病史", controller.state.pastMedicalHistory),
          _buildDividingLine(),
          _buildMultiLineInfo("初步诊断", controller.state.preliminaryDiagnosis),
          _buildTextDividingLine("会诊信息"),
          _buildSingleLineInfo("会诊医院", controller.state.consultationHospital),
          _buildDividingLine(),
          _buildSingleLineInfo("会诊专家", controller.state.consultationExpert),
          _buildDividingLine(),
          _buildSingleLineInfo("申请医院", controller.state.applicationHospital),
          _buildDividingLine(),
          _buildSingleLineInfo("扫查医生", controller.state.scanningDoctor),
          _buildDividingLine(),
          _buildSingleLineInfo("检查部位", controller.state.examinationSite),
          _buildDividingLine(),
          _buildSingleLineInfo("设备型号", controller.state.equipmentModel),
          _buildDividingLine(),
          _buildSingleLineInfo("会诊日期", controller.state.consultationDate),
        ],
      ),
    );
  }

  FWidget _buildSingleLineInfo(String title, String content) {
    return FRow(
      children: [
        FContainer(
          constraints: BoxConstraints(minWidth: 100),
          margin: EdgeInsets.only(left: 8, right: 8, top: 8, bottom: 8),
          child: FText(
            title,
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.bold,
              color: Color.fromARGB(255, 77, 77, 77),
            ),
          ),
        ),
        FExpanded(
          child: FContainer(
            margin: EdgeInsets.only(right: 8, top: 8, bottom: 8),
            child: FText(
              content,
              style: TextStyle(
                fontSize: 16,
                color: Color.fromARGB(255, 77, 77, 77),
              ),
            ),
          ),
        ),
      ],
    );
  }

  FWidget _buildMultiLineInfo(String title, String content) {
    return FColumn(
      children: [
        FRow(
          children: [
            FContainer(
              constraints: BoxConstraints(minWidth: 80),
              margin: EdgeInsets.only(left: 8, right: 8, top: 8, bottom: 8),
              child: FText(
                title,
                style: TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                  color: Color.fromARGB(255, 77, 77, 77),
                ),
              ),
            ),
            FExpanded(
              child: FContainer(
                margin: EdgeInsets.only(right: 8, top: 8, bottom: 8),
                child: FText(
                  content,
                  style: TextStyle(
                    fontSize: 14,
                    color: Color.fromARGB(255, 77, 77, 77),
                  ),
                ),
              ),
            ),
          ],
        ),
      ],
    );
  }

  FWidget _buildTextDividingLine(String title) {
    return FContainer(
      margin: EdgeInsets.only(top: 16, bottom: 8),
      child: FRow(
        children: [
          FContainer(
            height: 1,
            width: 16,
            color: Color.fromARGB(255, 136, 136, 136),
          ),
          FContainer(
            margin: EdgeInsets.symmetric(horizontal: 8),
            child: FText(
              title,
              style: TextStyle(
                fontSize: 14,
                // fontWeight: FontWeight.bold,
                color: Color.fromARGB(255, 136, 136, 136),
              ),
            ),
          ),
          FExpanded(
            child: FContainer(
              height: 1,
              width: 8,
              color: Color.fromARGB(255, 136, 136, 136),
            ),
          ),
        ],
      ),
    );
  }

  FWidget _buildDividingLine() {
    return FContainer(
      margin: EdgeInsets.only(left: 8, right: 8),
      child: FRow(
        children: [
          FExpanded(
            child: FContainer(
              height: 1,
              color: Color.fromARGB(255, 241, 241, 241),
            ),
          ),
        ],
      ),
    );
  }
}
