import 'package:fis_common/event/event_type.dart';
import 'package:fis_common/index.dart';
import 'package:fis_i18n/i18n.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'package:fis_lib_media_rt/interface/index.dart';
import 'package:fis_lib_media_rt/widgets/index.dart';
import 'package:fis_theme/theme.dart';
import 'package:fis_ui/base_define/page.dart';
import 'package:fis_ui/index.dart';
import 'package:fis_ui/values/spacings.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/architecture/router/index.dart';
import 'package:flyinsono/architecture/states/states.dart';
import 'package:flyinsono/managers/interfaces/entities/consultation_member.dart';
import 'package:flyinsono/managers/interfaces/live_consultation.dart';
import 'package:flyinsono/views/desktop/appointment_consultation/index.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/live_consultation/controller.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/live_consultation/widgets/record_botton.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/live_consultation/widgets/recording_mark.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/live_consultation/widgets/volume_setting_panel.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/widgets/image_capture_list.dart';
import 'package:flyinsono/views/mobile/confirm_application_page/controller.dart';
import 'package:flyinsono/views/mobile/confirm_application_page/widgets/add_participant.dart';
import 'package:get/get.dart';

import 'preview_member_calling_status.dart';
import 'preview_member_status.dart';
import 'retry_button.dart';
import 'video_loading.dart';

class LiveConsulationMobilePage extends FStatefulWidget {
  ///父级节点
  final FPage businessParent;

  LiveConsulationMobilePage(this.businessParent);

  @override
  FState<FStatefulWidget> createState() {
    return _MobileLayoutState();
  }
}

class _MobileLayoutState extends FState<LiveConsulationMobilePage> {
  static const double iconSize = 30;
  static const double memberListWidth = 180;

  static const double buttonSpacing = 15;
  final controller = Get.find<LiveConsultationController>();
  final confirmApplicationPageController =
      Get.put(ConfirmApplicationPageController());
  final TextStyle _previewMemberTextStyle = TextStyle(color: Colors.white);
  final double _previewMemberHeadTitle = 20;
  final double _smallLivePreviewHeight = 100;
  final ScrollController _scrollController = ScrollController();
  var manager = Get.find<ILiveConsultationManager>();

  ///添加参与人
  FWidget addParticipantsWidget() {
    return FInkWell(
      child: FContainer(
        width: 150,
        height: 150,
        decoration: BoxDecoration(
          color: Colors.grey[900],
          border: Border.all(color: Colors.grey[800]!),
          boxShadow: [
            BoxShadow(
              color: FColorHelper.mixColor(
                Colors.black12,
                Colors.black38,
                70,
              ),
              offset: Offset(3.0, 3.0), //阴影y轴偏移量
              blurRadius: 6, //阴影模糊程度
              spreadRadius: 0, //阴影扩散程度
            ),
          ],
        ),
        child: FRow(
          children: [
            FIcon(
              Icons.add,
              color: Colors.white,
            ),
            FText(
              i18nBook.realTimeConsultation.addParticipants.t,
              style: TextStyle(
                color: Colors.white,
              ),
            )
          ],
          mainAxisAlignment: MainAxisAlignment.center,
        ),
      ),
      onTap: () async {
        router.dialog(
          () => FAddParticipant(
            hasAssistantPhysicianCode:
                controller.state.memberStatus.length == 4,
            isConsultation: true,
            confirmCallback: (value) {
              controller.addConsultationMember(value);
              router.back();
            },
          ),
          dismissible: false,
        );
      },
    );
  }

  @override
  FWidget build(BuildContext context) {
    return QuickFWidget(WillPopScope(
      onWillPop: () async {
        FConfirmAlert.show(
          context: Get.context!,
          title: i18nBook.common.tip.t,
          subTitle: i18nBook.realTimeConsultation.confirmLeaveConsultation.t,
          confrimLabel: i18nBook.common.confirm.t,
          cancelLabel: i18nBook.common.cancel.t,
          businessParent: this.widget.businessParent,
          onConfirm: () {
            controller.sendInteractiveBoardData('', true);
            controller.onClearCanavsHandler.emit(this, Store.user.code);
            controller.leaveConsultation();
          },
          onCancel: () {},
        );
        // 返回true表示拦截返回事件，返回false表示不拦截返回事件
        return true;
      },
      child: FContainer(
        color: Colors.black,
        child: FSafeArea(
          bottom: false,
          child: FRow(
            children: [
              _buildLeftAreaView(),
              _buildMainUSView(),
            ],
          ),
        ),
      ),
    ));
  }

  FWidget _buildConsultationInfo() {
    Color color = Colors.grey;
    var textStyle = TextStyle(color: color);
    return FPositioned(
      left: FSpacings.M,
      right: FSpacings.M,
      child: FObx(() {
        return FSizedBox(
          height: 50,
          child: FAlign(
            alignment: Alignment.centerLeft,
            child: FFittedBox(
              child: FColumn(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  FTitleField(
                    i18nBook.realTimeConsultation.applicantMechanism.t,
                    FText(
                      controller
                              .state.consultationDetail.applyOrganizationName ??
                          '',
                      style: textStyle,
                    ),
                    isBold: false,
                    titleColor: color,
                    sizeBetween: 12,
                  ),
                  FTitleField(
                    i18nBook.remedical.patientDisplayName.t,
                    FText(
                      controller.state.consultationDetail.patientName ?? '',
                      style: textStyle,
                    ),
                    isBold: false,
                    titleColor: color,
                    sizeBetween: 12,
                  ),
                  FTitleField(
                    i18nBook.user.ulrSoundsMachine.t,
                    FText(
                      controller.state.consultationDetail.displayName ?? '',
                      style: textStyle,
                    ),
                    isBold: false,
                    titleColor: color,
                    sizeBetween: 12,
                  ),
                ],
              ),
            ),
          ),
        );
      }),
    );
  }

  ///左侧区域视图
  FWidget _buildLeftAreaView() {
    return FContainer(
      height: MediaQuery.of(Get.context!).size.height,
      width: memberListWidth,
      child: FColumn(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildReturnView(),
          const FSizedBox(height: FSpacings.M),
          _buildMembersView(),
          _buildTime(),
        ],
      ),
    );
  }

  ///预览摄像头内容
  FWidget _buildLiveContent(ConsultationMember member) {
    return FObx(() {
      var channel = controller.getMemberPreviewChannel(member);
      var memberStatus = controller.state.memberStatus[member.id];
      bool videoOpend = true;
      if (memberStatus != null && !memberStatus.videoOpend) {
        videoOpend = false;
      }
      Widget channelView;
      Size? size = Size(
        memberListWidth,
        _smallLivePreviewHeight,
      );
      if (member.mergedChannel) {
        channelView = _buildMergedCamera(member);
      } else {
        if (channel is IPublishChannel) {
          channelView = SizedBox();
          if (videoOpend) {
            channelView = FRTPublishPreviewView(
              channel,
              size: size,
            );
          }
        } else if (channel != null) {
          if (member.videoDeviceInfos != null &&
              member.videoDeviceInfos!.length > 1) {
            // 10 = (padding-right 8)+(border 2)
            size = Size(
              memberListWidth - 10,
              (memberListWidth - 10) *
                  manager.getVideoDeviceInfoHeight(
                      videoDeviceInfos: member.videoDeviceInfos!,
                      videoDeviceSourceType: VideoDeviceSourceTypeEnum.Camera) /
                  manager.getVideoDeviceInfoWidth(
                      videoDeviceInfos: member.videoDeviceInfos!,
                      videoDeviceSourceType: VideoDeviceSourceTypeEnum.Camera),
            );
          }

          channelView = FRTPlayChannelView(
            channel as IPlayChannel,
            size: size,
          );
        } else {
          channelView = SizedBox();
        }
      }

      if (channel != null || member.mergedChannel) {
        if (videoOpend) {
          return QuickFWidget(
            Container(
              // height: _smallLivePreviewHeight,
              width: memberListWidth,
              color: Colors.black,
              child: channelView,
            ),
          );
        } else {
          return FStack(
            children: [
              QuickFWidget(
                Container(
                  height: _smallLivePreviewHeight,
                  width: memberListWidth,
                  color: Colors.black,
                  child: channelView,
                ),
              ),
              _buildUserHeadImage(member),
            ],
          );
        }
      }
      return _buildUserHeadImage(member);
    });
  }

  ///超声画面
  FWidget _buildMainUSContentView() {
    return FStack(
      fit: StackFit.expand,
      children: [
        FObx(
          () {
            final IPlayChannel? channel = controller.state.deviceDesktopChannel;
            if (channel != null) {
              ConsultationMember device = controller.state.memberStatus.values
                  .firstWhere(
                      (element) => element.memberType == LiveMemberEnum.Device);
              if (device.mergedChannel &&
                  device.videoDeviceInfos != null &&
                  device.videoDeviceInfos!.length > 0) {
                var outWidth = manager.getVideoDeviceInfoWidth(
                    videoDeviceInfos: device.videoDeviceInfos!);
                var outHeight = manager.getVideoDeviceInfoHeight(
                    videoDeviceInfos: device.videoDeviceInfos!);
                print(
                    "合图模式 ⭐⭐⭐ 合流的画面宽度 ${device.mergedVideoOutputWidth}x${device.mergedVideoOutputHeight} ⭐⭐⭐");
                print("合图模式 ⭐⭐⭐ 视图 ${outWidth}x$outHeight ⭐⭐⭐");
                return QuickFWidget(
                  // 合图模式
                  FRTMergedChannelView(
                    isSubView: false,
                    videoSize: Size(
                      device.mergedVideoOutputWidth.toDouble(),
                      device.mergedVideoOutputHeight.toDouble(),
                    ),
                    viewSize: Size(
                      outWidth,
                      outHeight,
                    ),
                    viewAlignment: Alignment.topLeft,
                    key: controller.recordingController.mainUSViewKey,
                    channel,
                  ),
                );
              }
              return QuickFWidget(
                FRTDeviceChannelView(
                  key: controller.recordingController.mainUSViewKey,
                  viewSize: Size(
                    manager.getVideoDeviceInfoWidth(
                        videoDeviceInfos: device.videoDeviceInfos!),
                    manager.getVideoDeviceInfoHeight(
                        videoDeviceInfos: device.videoDeviceInfos!),
                  ),
                  channel,
                ),
              );
            }
            if (controller.state.showRetryButton) {
              return RetryButton(
                onTap: controller.retryLoadDevice,
              );
            }
            return QuickFWidget(
              VideoLoadingWidget(),
            );
          },
        ),
        FObx(() {
          final IPlayChannel? channel = controller.state.deviceDesktopChannel;
          if (channel == null) {
            return FSizedBox();
          }
          ConsultationMember device = controller.state.memberStatus.values
              .firstWhere(
                  (element) => element.memberType == LiveMemberEnum.Device);
          if (device.videoDeviceInfos == null) {
            return FSizedBox();
          }
          if (controller.state.initBoardDatas == null) {
            return FSizedBox();
          }
          return FClipRRect(
            child: Center(
              child: AspectRatio(
                aspectRatio: manager.getVideoDeviceInfoWidth(
                        videoDeviceInfos: device.videoDeviceInfos!) /
                    manager.getVideoDeviceInfoHeight(
                        videoDeviceInfos: device.videoDeviceInfos!),
                child: FWhiteBoard(
                  sendData: (value) {
                    controller.sendInteractiveBoardData(value);
                  },
                  paintType: controller.state.paintType,
                  userId: Store.user.code,
                  onReceiveData: Get.find<ILiveConsultationManager>()
                      .onWhiteboardDataReceive,
                  onClearCanavs: controller.onClearCanavsHandler,
                  initData: controller.state.initBoardDatas!,
                  patientColor: controller.currectColor(),
                ),
              ),
            ),
          );
        }),
        FObx(() {
          if (controller.state.isVidCapturerRecording) {
            return FPositioned(
              left: FSpacings.XXL,
              top: FSpacings.XXL,
              child: RecordingMark(
                startTime: controller.state.vidCapturerStartTime,
              ),
            );
          } else {
            return FSizedBox();
          }
        }),
        FObx(() {
          if (!controller.state.isVidCapturerRecording &&
              controller.state.isMobilePageShowButtons) {
            return _buildConsultationInfo();
          } else {
            return FSizedBox();
          }
        }),
        FObx(() => FAlign(
            alignment: Alignment.centerLeft,
            child: VolumeSettingPanel(
              ifShowPanel: controller.state.isShowVolumeSetting4Mobile,
            ))),
        FAlign(
          alignment: Alignment.bottomLeft,
          child: ImageCaptureList(),
        ),
      ],
    );
  }

  //超声直播画面
  FWidget _buildMainUSView() {
    return FExpanded(
      child: FGestureDetector(
        businessParent: widget.businessParent,
        name: 'MainUSView',
        onTap: () {
          controller.state.isMobilePageShowButtons =
              !controller.state.isMobilePageShowButtons;
          print('MainUSView');
          if (!controller.state.isMobilePageShowButtons) {
            controller.closeVolumeSetting();
          }
        },
        child: FRow(
          children: [
            FExpanded(child: _buildMainUSContentView()),
            FContainer(
              margin: EdgeInsets.only(
                right: buttonSpacing,
                top: buttonSpacing,
                bottom: buttonSpacing,
              ),
              child: _operateButtons(),
            ),
          ],
        ),
      ),
    );
  }

  ///会诊成员画板颜色
  FWidget _buildMemberIcon(Color currectPatientColor) {
    return FIcon(
      Icons.circle,
      color: currectPatientColor,
      size: 14,
    );
  }

  ///会诊成员名称
  FWidget _buildMemberName(
    String name,
  ) {
    return FAlign(
      alignment: Alignment.center,
      child: FText(
        name,
        style: _previewMemberTextStyle,
      ),
    );
  }

  ///成员信息
  FWidget _buildMembersView() {
    return FObx(() {
      final memberLiveDatas = controller.state.memberStatus;
      List<ConsultationMember> consultationMembers =
          memberLiveDatas.values.toList();
      List<FWidget> children = [];

      var deviceMember = consultationMembers.firstWhereOrNull(
          (element) => element.memberType == LiveMemberEnum.Device);
      if (deviceMember != null && deviceMember.videoDeviceInfos!.length > 1) {
        children.add(
          _buildPreviewItem(
            deviceMember,
            Colors.transparent,
          ),
        );
      }
      var selfMember = consultationMembers
          .firstWhereOrNull((element) => element.id == Store.user.code);
      if (selfMember != null) {
        children.add(
          _buildPreviewItem(
            selfMember,
            controller.whiteboardController.getColorByIndex(selfMember.index),
          ),
        );
      }

      consultationMembers = consultationMembers
          .where(
            (element) =>
                element.memberType == LiveMemberEnum.User &&
                element.id != Store.user.code,
          )
          .toList();
      consultationMembers.sort((a, b) => a.sortLevel.compareTo(b.sortLevel));
      for (int i = 0; i < consultationMembers.length; i++) {
        children.add(
          _buildPreviewItem(
            consultationMembers[i],
            controller.whiteboardController
                .getColorByIndex(consultationMembers[i].index),
          ),
        );
      }
      if (Store.user.code ==
          controller.state.consultationDetail.expertUserCode) {
        children.add(addParticipantsWidget());
      }

      return FExpanded(
        child: FAlwaysScrollListView(
          child: QuickFWidget(ScrollConfiguration(
            behavior:
                ScrollConfiguration.of(context).copyWith(scrollbars: false),
            child: FListView(
              controller: _scrollController,
              shrinkWrap: true,
              padding: EdgeInsets.only(top: 0, right: 8),
              children: [
                FColumn(
                  children: children,
                )
              ],
            ),
          )),
          scrollController: _scrollController,
        ),
      );
    });
  }

  /// 构建合图模式下的摄像头
  Widget _buildMergedCamera(ConsultationMember member) {
    final IPlayChannel? deviceChannel = controller.state.deviceDesktopChannel;
    if (deviceChannel != null &&
        member.videoDeviceInfos != null &&
        member.videoDeviceInfos!.length > 1) {
      double mainWidth = manager.getVideoDeviceInfoWidth(
          videoDeviceInfos: member.videoDeviceInfos!,
          videoDeviceSourceType: VideoDeviceSourceTypeEnum.Desktop);
      double mainHeight = manager.getVideoDeviceInfoHeight(
          videoDeviceInfos: member.videoDeviceInfos!,
          videoDeviceSourceType: VideoDeviceSourceTypeEnum.Desktop);
      double cameraWidth = manager.getVideoDeviceInfoWidth(
          videoDeviceInfos: member.videoDeviceInfos!,
          videoDeviceSourceType: VideoDeviceSourceTypeEnum.Camera);
      double cameraHeight = manager.getVideoDeviceInfoHeight(
          videoDeviceInfos: member.videoDeviceInfos!,
          videoDeviceSourceType: VideoDeviceSourceTypeEnum.Camera);
      print(
          "合图模式 ⭐⭐⭐ 合流的画面宽度 ${member.mergedVideoOutputWidth}x${member.mergedVideoOutputHeight} ⭐⭐⭐");
      print("合图模式 ⭐⭐⭐ 视图 ${cameraWidth}x$cameraHeight ⭐⭐⭐");
      if (member.isOldPlatform) {
        return Center(
          child: FRTMergedChannelSubViewOldVersion(
            videoSize: Size(
              member.mergedVideoOutputWidth.toDouble(),
              member.mergedVideoOutputHeight.toDouble(),
            ),
            mainViewSize: Size(
              mainWidth,
              mainHeight,
            ),
            cameraViewSize: Size(
              cameraWidth,
              cameraHeight,
            ),
            viewAlignment: Alignment.topRight,
            deviceChannel,
          ),
        );
      } else {
        return Center(
          child: FRTMergedChannelView(
            isSubView: true,
            videoSize: Size(
              member.mergedVideoOutputWidth.toDouble(),
              member.mergedVideoOutputHeight.toDouble(),
            ),
            viewSize: Size(
              cameraWidth,
              cameraHeight,
            ),
            viewAlignment: Alignment.topRight,
            deviceChannel,
          ),
        );
      }
    } else {
      return Container(
        width: memberListWidth,
        height: _smallLivePreviewHeight,
        color: Color.fromARGB(255, 22, 22, 22),
      );
    }
  }

  //自定义图标按钮
  FWidget _buildOperateIconButton(IconData icon, VoidCallback onPressed,
      [bool? isChecked = false, Color iconColor = Colors.white]) {
    return FInkWell(
      child: FIcon(
        icon,
        color: isChecked! ? FTheme.ins.colorScheme.primary : iconColor,
        size: iconSize,
      ),
      onTap: onPressed,
    );
  }

  ///摄像头预览、单个视图
  FWidget _buildPreviewItem(
    ConsultationMember member,
    Color currectPatientColor,
  ) {
    return FContainer(
      decoration: BoxDecoration(
        color: Colors.grey[900],
        border: Border.all(color: Colors.grey[800]!),
      ),
      margin: EdgeInsets.only(bottom: FSpacings.L),
      width: memberListWidth,
      child: FColumn(
        mainAxisAlignment: MainAxisAlignment.end,
        mainAxisSize: MainAxisSize.max,
        children: [
          FRow(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              FSizedBox(
                width: 14,
              ),
              _buildMemberName(member.name ?? ''),
              _buildMemberIcon(currectPatientColor),
            ],
          ),
          FStack(
            children: [
              _buildLiveContent(member),
              PreviewMemberStatus(member),
            ],
          ),
          if (member.memberType == LiveMemberEnum.User) ...[
            PreviewMemberCallingStatus(member),
          ],
        ],
      ),
    );
  }

  //返回
  FWidget _buildReturnView() {
    return FObx(
      () {
        var state = controller.state;
        if (!state.isMobilePageShowButtons) {
          return const FSizedBox(height: iconSize);
        }
        return FRow(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.end,
          children: [
            FGestureDetector(
              businessParent: this.widget.businessParent,
              name: 'switchVolumeSetting',
              behavior: HitTestBehavior.opaque,
              child: FContainer(
                  padding:
                      EdgeInsets.only(left: 30, right: 10, top: 5, bottom: 5),
                  child: FRow(
                    children: [
                      FIcon(
                        Icons.settings_outlined,
                        size: 20,
                        color: Colors.white,
                      ),
                      const FSizedBox(width: FSpacings.M),
                    ],
                  )),
              onTap: () {
                controller.switchVolumeSetting();
              },
            ),
          ],
        );
      },
    );
  }

  //计时显示
  FWidget _buildTime() {
    return FObx(
      () {
        var state = controller.state;
        if (!state.isMobilePageShowButtons) {
          return FSizedBox(height: FSpacings.XXL);
        }
        return FContainer(
          height: FSpacings.XXL,
          margin: EdgeInsets.only(bottom: FSpacings.M),
          alignment: Alignment.topCenter,
          child: FText(
            i18nBook.measure.playLocationDurationLabel.t +
                '${state.minute.padLeft2()}' +
                ':' +
                '${state.seconds.padLeft2()}',
            style: _previewMemberTextStyle,
          ),
        );
      },
    );
  }

  FWidget _buildUserHeadImage(ConsultationMember member) {
    var headImageToken = member.headImageToken ?? '';
    FWidget child;
    if (headImageToken.isEmpty) {
      child = FImage(
        image: AssetImage("assets/images/avatar_man.jpg"),
        fit: BoxFit.fill,
        height: _smallLivePreviewHeight - _previewMemberHeadTitle,
        width: memberListWidth,
      );
    } else {
      child = FImage.network(
        headImageToken,
        fit: BoxFit.fill,
        height: _smallLivePreviewHeight - _previewMemberHeadTitle,
        width: memberListWidth,
      );
    }
    return FContainer(
      color: Colors.grey,
      height: _smallLivePreviewHeight,
      child: member.memberType == LiveMemberEnum.User
          ? child
          : QuickFWidget(
              VideoLoadingWidget(),
            ),
    );
  }

  /// 清除画笔
  void _clearPaint() {
    HapticFeedback.mediumImpact();
    controller.sendInteractiveBoardData('', true);
    controller.onClearCanavsHandler.emit(this, Store.user.code);
  }

  //右侧悬浮按钮：白板、截图、录制
  FWidget _operateButtons() {
    return FColumn(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: [
        /// 线段
        _buildOperateIconButton(
          FIcons.fis_line_segment,
          () => _switchLineType(PaintType.straightLine),
          controller.state.paintType == PaintType.straightLine,
        ),

        /// 曲线
        _buildOperateIconButton(
          Icons.mode_edit_outline_outlined,
          () => _switchLineType(PaintType.curvedLine),
          controller.state.paintType == PaintType.curvedLine,
        ),
        // 清除
        _buildOperateIconButton(
          Icons.delete,
          () => _clearPaint(),
        ),
        FObx(() {
          if (controller.state.isVidFileCapturing &&
              !controller.state.isVidFileCapturingByRecording) {
            return FContainer(
              padding: EdgeInsets.all(5),
              width: iconSize,
              height: iconSize,
              child: FCircularProgressIndicator(
                  valueColor: AlwaysStoppedAnimation<Color>(Colors.white)),
            );
          } else {
            return _buildOperateIconButton(Icons.photo_camera, () {
              controller.captureOneFrame();
            });
          }
        }),

        FObx(() {
          /// 正在处理视频捕获
          var _isCapturing = controller.state.isVidFileCapturing &&
              controller.state.isVidFileCapturingByRecording;
          if (_isCapturing) {
            return FContainer(
              padding: EdgeInsets.all(5),
              width: iconSize,
              height: iconSize,
              child: FCircularProgressIndicator(
                  valueColor: AlwaysStoppedAnimation<Color>(Colors.white)),
            );
          } else {
            return RecordButton4Mobile(
              onStartRecord: controller.startRecording,
              onStopRecord: controller.endRecording,
            );
          }
        }),
        // 调参
        FObx(() {
          if (controller.state.canRemoteParameter &&
              controller.state.isUSDevice) {
            return _buildOperateIconButton(
              Icons.format_list_bulleted_rounded,
              () {
                controller.controlParameterAsync();
              },
              false,
              Colors.white,
            );
          }
          return FSizedBox();
        }),
        // 挂断
        _buildOperateIconButton(
          Icons.call_end,
          () {
            FConfirmAlert.show(
              context: Get.context!,
              title: i18nBook.common.tip.t,
              subTitle:
                  i18nBook.realTimeConsultation.confirmLeaveConsultation.t,
              confrimLabel: i18nBook.common.confirm.t,
              cancelLabel: i18nBook.common.cancel.t,
              businessParent: this.widget.businessParent,
              onConfirm: () {
                controller.sendInteractiveBoardData('', true);
                controller.onClearCanavsHandler.emit(this, Store.user.code);
                controller.leaveConsultation();
              },
            );
          },
          false,
          Colors.red,
        ),
      ],
    );
  }

  /// 切换线类型
  void _switchLineType(PaintType lineType) {
    HapticFeedback.mediumImpact();
    controller.state.paintType = lineType;
    setState(() {});
  }
}
