import 'package:fis_i18n/i18n.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/views/desktop/real_time_consultation/controller/real_time_consultation_controller.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/widgets/appointment_application.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/widgets/consultation_Image.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/widgets/consultation_report.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/widgets/consultation_visit.dart';

class FRealTimeConsultationMainContentView
    extends FisView<RealTimeConsultationController> implements FPage {
  const FRealTimeConsultationMainContentView({Key? key}) : super(key: key);

  @override
  String get pageName => 'FRealTimeConsultationMainContentView';
  @override
  FWidget build(BuildContext context) {
    FWidget child = FObx(
      () {
        FWidget child = FContainer();
        final selectedIndex = controller.state.selectIndex;
        if (selectedIndex == 0) {
          child = FAppointmentApplicationDialog();
        } else if (selectedIndex == 1) {
          child = ConsultationImageView();
        } else if (selectedIndex == 2) {
          child = RealtimeConsultationReport();
        } else if (selectedIndex == 3) {
          child = ConsultationVisitView();
        }
        return controller.state.consultationsRecordCardList.isEmpty
            ? FContainer(
                margin: const EdgeInsets.only(top: 80),
                child: FColumn(
                  children: [
                    FCenter(
                      child: FImage.asset(
                        "assets/images/no_data.png",
                        width: 300,
                        height: 300,
                        fit: BoxFit.cover,
                      ),
                    ),
                    FText(i18nBook.common.noneDataTip.t),
                  ],
                ),
              )
            : child;
      },
    );

    return FColumn(
      children: [
        const FSizedBox(
          height: 10,
        ),
        FContainer(
          margin: const EdgeInsets.only(left: 15, right: 15),
          child: FObx(
            () {
              return FTabButtonGroup(
                [
                  FTabButton(
                    tabTitle:
                        i18nBook.realTimeConsultation.appointmentConsultation.t,
                    index: 0,
                    activeIndex: controller.state.selectIndex,
                    onCallbackTap: () {
                      controller.state.selectIndex = 0;
                    },
                    width: i18nBook.isCurrentChinese ? 100 : 150,
                    businessParent: this,
                  ),
                  FTabButton(
                    tabTitle: i18nBook.realTimeConsultation.consultationImage.t,
                    index: 1,
                    activeIndex: controller.state.selectIndex,
                    onCallbackTap: () {
                      controller.state.selectIndex = 1;
                    },
                    padding: i18nBook.isCurrentChinese
                        ? EdgeInsets.symmetric(horizontal: 20, vertical: 8)
                        : EdgeInsets.symmetric(vertical: 8, horizontal: 5),
                    width: i18nBook.isCurrentChinese ? 100 : 150,
                    businessParent: this,
                  ),
                  FTabButton(
                    tabTitle:
                        i18nBook.realTimeConsultation.consultationReport.t,
                    index: 2,
                    padding: i18nBook.isCurrentChinese
                        ? EdgeInsets.symmetric(horizontal: 20, vertical: 8)
                        : EdgeInsets.symmetric(vertical: 8, horizontal: 5),
                    activeIndex: controller.state.selectIndex,
                    onCallbackTap: () {
                      controller.reportController.getReportInfoAsync();
                      controller.state.selectIndex = 2;
                    },
                    width: i18nBook.isCurrentChinese ? 100 : 150,
                    businessParent: this,
                  ),
                  FTabButton(
                    tabTitle:
                        i18nBook.realTimeConsultation.consultationFollowUp.t,
                    index: 3,
                    padding: i18nBook.isCurrentChinese
                        ? EdgeInsets.symmetric(horizontal: 20, vertical: 8)
                        : EdgeInsets.symmetric(vertical: 8, horizontal: 5),
                    activeIndex: controller.state.selectIndex,
                    onCallbackTap: () async {
                      await controller.visitController.getFollowUpVisitInfo();
                      controller.state.selectIndex = 3;
                    },
                    width: i18nBook.isCurrentChinese ? 100 : 170,
                    businessParent: this,
                  )
                ],
              );
            },
          ),
        ),
        FExpanded(
          child: FContainer(
            color: Colors.white,
            margin: const EdgeInsets.only(left: 15, right: 15, bottom: 15),
            child: FContainer(
              child: FScaffold(
                body: FDefaultTabController(
                  length: 4,
                  child: child,
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }
}
