import 'package:fis_i18n/i18n.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'package:fis_jsonrpc/services/liveConsultation.m.dart';
import 'package:fis_ui/base_define/page.dart';
import 'package:fis_ui/index.dart';
import 'package:fis_ui/usual/tab_button.dart';
import 'package:fis_ui/usual/tab_button_group.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/pages/remedical/consultation/controller.dart';
import 'package:flyinsono/pages/remedical/consultation/widgets/exam_records.dart';
import 'package:flyinsono/pages/remedical/consultation/widgets/patient_info_view.dart';
import 'package:flyinsono/pages/remedical/consultation/widgets/report/report_card.dart';
import 'package:flyinsono/pages/remedical/consultation_record_view/index.dart';
import 'package:get/get.dart';

class MainContentView extends FisView<ConsultationController> {
  MainContentView(this.businessParent, {Key? key}) : super(key: key);

  ///父级节点
  final FPage businessParent;
  @override
  FWidget build(BuildContext context) {
    FWidget child = FObx(
      () {
        FWidget child = FContainer();
        final selectedIndex = controller.state.selectIndex;
        if (selectedIndex == 2) {
          child = PatientInfoContentView();
        } else if (selectedIndex == 1) {
          child = ReportList();
        } else if (selectedIndex == 0) {
          child = ExamRecord();
        }
        return child;
      },
    );

    return FColumn(
      children: [
        const FSizedBox(height: 10),
        FContainer(
          margin: EdgeInsets.only(left: 15, right: 15),
          child: FObx(
            () {
              return FRow(
                children: [
                  FTabButtonGroup(
                    [
                      FTabButton(
                        businessParent: businessParent,
                        tabTitle: i18nBook.remedical.checkRecord.t,
                        index: 0,
                        activeIndex: controller.state.selectIndex,
                        onCallbackTap: () {
                          controller.state.selectIndex = 0;
                        },

                        /// TODO:[Gavin] 多语言-UI-整合
                        width: i18nBook.isCurrentChinese ? 100 : 200,
                      ),
                      FTabButton(
                        businessParent: businessParent,
                        name: "checkReport",
                        tabTitle: i18nBook.remedical.checkReport.t,
                        index: 1,
                        activeIndex: controller.state.selectIndex,
                        onCallbackTap: () {
                          controller.state.selectIndex = 1;
                        },

                        /// TODO:[Gavin] 多语言-UI-整合
                        width: i18nBook.isCurrentChinese ? 100 : 200,
                      ),
                      FTabButton(
                        businessParent: businessParent,
                        name: "patientDetail",
                        tabTitle: controller.state.patientType ==
                                OrganizationPatientTypeEnum.Person
                            ? i18nBook.remedical.patientDetail.t
                            : i18nBook.remedical.caseDetail.t,
                        index: 2,
                        activeIndex: controller.state.selectIndex,
                        onCallbackTap: () {
                          controller.state.selectIndex = 2;
                        },

                        /// TODO:[Gavin] 多语言-UI-整合
                        width: i18nBook.isCurrentChinese ? 100 : 200,
                      ),
                    ],
                  ),
                  FExpanded(child: FSizedBox()),
                  FIconButton(
                      icon: FIcon(Icons.close),
                      onPressed: () {
                        Get.find<ConsultationRecordViewController>()
                            .closePatientInfoDialog();
                      },
                      businessParent: businessParent,
                      name: 'close'),
                ],
              );
            },
          ),
        ),
        FExpanded(
          child: FContainer(
            color: Colors.white,
            margin: EdgeInsets.only(left: 15, right: 15, bottom: 15),
            child: FContainer(
              child: FScaffold(
                body: FDefaultTabController(
                  length: 4,
                  child: child,
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }
}
