import 'package:fis_ui/index.dart';
import 'package:fis_ui/values/spacings.dart';
import 'package:fis_ui/widgets/layout/button_group.dart';
import 'package:fis_ui/values/paddings.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:fis_ui/interface/interactive_container.dart';
import 'package:flyinsono/architecture/router/router.dart';
import 'package:flyinsono/managers/server_config_manager.dart';
import '../index.dart';
import 'package:fis_i18n/i18n.dart';
import 'package:fis_common/index.dart';
import 'package:fis_common/logger/logger.dart';
import 'package:fis_i18n/i18n.dart';
import 'package:fis_ui/base_define/page.dart';
import 'package:fis_common/event/event_type.dart';
import 'package:fis_theme/theme.dart';
import 'package:fis_ui/index.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'capture_live_view.dart';

/// 操作按钮行
class OperationButtonsRow extends FisView<ConsultationRecordViewController>
    implements FInteractiveContainer {
  const OperationButtonsRow({Key? key}) : super(key: key);
  @override
  String get pageName => 'operation_buttons_row';

  @override
  FWidget build(BuildContext context) {
    return FisBuilder<ConsultationRecordViewController>(
        id: "operation_buttons_row",
        builder: (_) {
          if (controller.isShowOperationButtonsRow) {
            return _buildButtons();
          } else {
            return Container();
          }
        });
  }

  Widget _buildButtons() {
    List<FWidget> children = [
      _buildTextButton(
        i18nBook.realTimeConsultation.patientInformation.t,
        () => controller.showPatientInfoDialog(),
      ),
      _buildTextButton(
        i18nBook.remedical.examinationDetails.t,
        () => controller.showInspectionDetailsDialog(),
      ),
      if (controller.currentRecordData?.canCollcetImg ?? false)
        _buildTextButton(
          i18nBook.remedical.startScan.t,
          () => controller.startScan(this),
        ),
      if (controller.isShowEndScan)
        _buildTextButton(
          i18nBook.remedical.endScan.t,
          () => controller.endScan(this),
        ),
      if (controller.currentRecordData?.isCanCreateReport ?? false) ...[
        _buildTextButton(
          i18nBook.remedical.writeReport.t,
          () => controller.editReport(),
        ),
      ],
      if (controller.isCanTransfer)
        _buildTextButton(
          i18nBook.remedical.transfer.t,
          () => controller.transfer(),
        ),
      if (controller.isCanShowTransferHisHistory)
        _buildTextButton(
          i18nBook.remedical.referralHistory.t,
          () => controller.showReferralHistory(),
        ),
      if (controller.isCanDelete)
        _buildTextButton(
          i18nBook.common.delete.t,
          () => controller.deleteRecord(
              controller.desktopListSelectedRecordCode, this),
        ),
      // if (kDebugMode || (FPlatform.isMacOS || FPlatform.isWindows)) ...[
      if (controller.canScreenshot &&
          (CartSystemPlatform.isCartSystemWithOldPlatform)) ...[
        _buildTextButton(
          i18nBook.common.imageCapture.t,
          () {
            controller.captureLiveController.startRtmpServer();
            router.dialog(
              () => CaptureLiveView(controller.desktopListSelectedRecordCode),
            );
          },
        ),
      ],
    ];

    return Container(
      height: 60,
      padding: EdgeInsets.symmetric(horizontal: 10),
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
          top: BorderSide(
            color: Colors.grey[300]!,
            width: 1,
          ),
        ),
      ),
      child: Align(
        alignment: Alignment.center,
        child: FButtonGroup(
          buttonPadding: FPaddings.MINI_BUTTON,
          spacing: FSpacings.MINI_BUTTON,
          children: children,
        ),
      ),
    );
  }

  FWidget _buildTextButton(String textString, Function onPressed) {
    return FElevatedButton(
      name: textString,
      businessParent: this,
      onPressed: () => onPressed.call(),
      child: FText(
        textString,
        style: TextStyle(color: Colors.white),
      ),
      style: ButtonStyle(
        fixedSize: MaterialStateProperty.all(Size(160, 35)),
        padding: MaterialStateProperty.all(
          EdgeInsets.symmetric(
            vertical: 5,
          ),
        ),
      ),
    );
  }
}
