import "core-js/modules/es.array.filter.js";
import "core-js/modules/es.array.includes.js";
import "core-js/modules/es.array.is-array.js";
import "core-js/modules/es.array.some.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/es.string.includes.js";
import "core-js/modules/esnext.array.group.js";
import "core-js/modules/esnext.iterator.constructor.js";
import "core-js/modules/esnext.iterator.filter.js";
import "core-js/modules/esnext.iterator.some.js";
import { FcrDropMenu } from '../../drop-menu';
import { FcrIcon } from '../../icon';
import { FcrIconType } from '../../icon/type';
import { FcrUserRole, ParticipantActionType } from '../attendee';
import { CameraState } from '../../room-screen-share-state-bar/camera-state';
import { t } from 'i18next';
import './index.css';

// 提取常量
import { jsx as _jsx } from "react/jsx-runtime";
var ICON_SIZE = 20;
var ICON_SIZE_GUEST = 16;
var ICON_PRIMARY_COLOR = 'var(--fcr_ui_scene_icontext5)';
var RAMP_RED_COLOR = 'var(--fcr_ui_scene_ramp_red6)';

// 封装图标创建函数
var createIcon = function createIcon(type) {
  var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ICON_SIZE;
  var colors = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
    iconPrimary: ICON_PRIMARY_COLOR
  };
  return /*#__PURE__*/_jsx(FcrIcon, {
    type: type,
    size: size,
    colors: colors
  });
};

// 封装按钮点击处理函数
var handleButtonClick = function handleButtonClick(actionType, userId, onParticipantsButtonClick) {
  return function () {
    onParticipantsButtonClick(actionType, userId);
  };
};
var FcrParticipantsMoreActions = function FcrParticipantsMoreActions(props) {
  var onParticipantsButtonClick = props.onParticipantsButtonClick,
    hasPinnedStream = props.hasPinnedStream,
    hideActions = props.hideActions,
    user = props.user,
    isLocalCameraInSecondaryWindow = props.isLocalCameraInSecondaryWindow;
  var isMe = user.isMe,
    userId = user.userId,
    hasVideo = user.hasVideo,
    userName = user.userName,
    userRole = user.userRole,
    isPin = user.isPin,
    userType = user.userType,
    allowedOperations = user.allowedOperations,
    isChatForbidden = user.isChatForbidden;
  var cameraStateType = !hasVideo ? 'primary' : 'danger';

  /**
   * 如果当前用户的类型是 'meeting-system' 且没有视频流，则不显示固定选项。
   * 如果当前用户是自己且摄像头的视频流显示在副窗口中，也不显示固定选项。
   */
  var isShowPinOption = true;
  if (userType === 'meeting-system' && !hasVideo) {
    isShowPinOption = false;
  } else if (isMe && isLocalCameraInSecondaryWindow) {
    isShowPinOption = false;
  }

  // 定义所有操作菜单
  var allOperationMenu = [{
    icon: /*#__PURE__*/_jsx(CameraState, {
      ignoreColor: true,
      isCameraMuted: true,
      renderMode: "forward-state"
    }),
    title: t('fmt_device_label_video_start'),
    key: 'start_video',
    type: cameraStateType,
    canOperation: !hasVideo && userType !== 'phone',
    onButtonClick: handleButtonClick(ParticipantActionType.UNMUTE_VIDEO, userId, onParticipantsButtonClick)
  }, {
    icon: /*#__PURE__*/_jsx(CameraState, {
      ignoreColor: true,
      isCameraMuted: true,
      renderMode: "forward-state"
    }),
    title: t('fmt_sip_button_opencamera'),
    key: 'request_start_video',
    type: 'primary',
    canOperation: !hasVideo && !isMe && userType !== 'phone',
    onButtonClick: handleButtonClick(ParticipantActionType.UNMUTE_VIDEO, userId, onParticipantsButtonClick)
  }, {
    icon: /*#__PURE__*/_jsx(CameraState, {
      isCameraMuted: false,
      renderMode: "forward-state"
    }),
    title: /*#__PURE__*/_jsx("span", {
      children: t('fmt_device_label_video_stop')
    }),
    key: 'stop_video',
    type: cameraStateType,
    canOperation: hasVideo && userType !== 'phone',
    onButtonClick: handleButtonClick(ParticipantActionType.MUTE_VIDEO, userId, onParticipantsButtonClick)
  }, {
    icon: createIcon(FcrIconType.FCR_MOBILE_CHAT3),
    title: t('fmt_attendies_label_privatechat'),
    key: 'private_chat',
    type: 'primary',
    canOperation: !isMe && userType !== 'phone',
    onButtonClick: handleButtonClick(ParticipantActionType.PRIVATE_CHAT, userId, onParticipantsButtonClick)
  }, {
    title: t('fmt_attendies_button_handsdown'),
    icon: createIcon(FcrIconType.FCR_HANDSDOWN),
    key: 'hands_down',
    type: 'danger',
    canOperation: true,
    onButtonClick: handleButtonClick(ParticipantActionType.HANDS_DOWN, userId, onParticipantsButtonClick)
  }, {
    type: 'group',
    title: t('fmt_additional_label_meet_view_own'),
    key: 'own_view'
  }, {
    icon: isPin ? createIcon(FcrIconType.FCR_UNPIN) : createIcon(FcrIconType.FCR_PINPAGE),
    title: isPin ? /*#__PURE__*/_jsx("span", {
      children: t('fmt_attendies_options_cancelfixed')
    }) : hasPinnedStream ? t('fmt_attendies_options_replacefixed') : t('fmt_attendies_options_fixfirst'),
    key: 'pin',
    type: isPin ? 'danger' : 'primary',
    canOperation: isShowPinOption,
    onButtonClick: handleButtonClick(isPin ? ParticipantActionType.REMOVE_PIN : ParticipantActionType.ADD_PIN, userId, onParticipantsButtonClick),
    group: 'own_view'
  }, {
    type: 'group',
    title: t('fmt_additional_label_attendee_permission'),
    key: 'permission'
  }, {
    title: t('fmt_attendies_options_sethost'),
    icon: createIcon(FcrIconType.FCR_HOST2),
    key: 'set_as_host',
    canOperation: userRole !== FcrUserRole.HOST && userType === 'normal',
    onButtonClick: handleButtonClick(ParticipantActionType.SET_AS_HOST, userId, onParticipantsButtonClick),
    group: 'permission'
  }, {
    title: t('fmt_attendies_options_setcohost'),
    icon: createIcon(FcrIconType.FCR_COHOST2),
    key: 'set_as_co_host',
    type: 'primary',
    canOperation: userRole !== FcrUserRole.COHOST && userType === 'normal',
    onButtonClick: handleButtonClick(ParticipantActionType.SET_AS_CO_HOST, userId, onParticipantsButtonClick),
    group: 'permission'
  }, {
    title: t('fmt_attendies_options_revokecohost'),
    icon: createIcon(FcrIconType.FCR_COHOST2),
    key: 'revoke_co_host',
    type: 'danger',
    canOperation: userRole === FcrUserRole.COHOST && userType === 'normal',
    onButtonClick: handleButtonClick(ParticipantActionType.SET_AS_ATTENDEE, userId, onParticipantsButtonClick),
    group: 'permission'
  }, {
    title: t('fmt_webinar_participant_list_more_promote_to_presenter'),
    icon: createIcon(FcrIconType.FCR_GUEST, ICON_SIZE_GUEST),
    key: 'set_as_attendee',
    type: 'primary',
    canOperation: userRole === FcrUserRole.AUDIENCE && userType === 'normal',
    onButtonClick: handleButtonClick(ParticipantActionType.SET_AS_ATTENDEE, userId, onParticipantsButtonClick),
    group: 'permission'
  }, {
    title: t('fmt_webinar_participant_list_more_move_to_attendee'),
    icon: createIcon(FcrIconType.FCR_GUEST),
    key: 'set_as_audience',
    type: 'primary',
    canOperation: userRole === FcrUserRole.PARTICIPANT && userType === 'normal',
    onButtonClick: handleButtonClick(ParticipantActionType.SET_AS_AUDIENCE, userId, onParticipantsButtonClick),
    group: 'permission'
  }, {
    title: t('fmt_additional_option_rename_in_meeting'),
    icon: createIcon(FcrIconType.FCR_RENAME2),
    key: 'change_name',
    type: 'primary',
    canOperation: true,
    onButtonClick: handleButtonClick(ParticipantActionType.RENAME_IN_MEETING, userId, onParticipantsButtonClick),
    group: 'permission'
  }, {
    title: t('fmt_modules_tips_mergevideo'),
    icon: createIcon(FcrIconType.FCR_MOBILE_CAMERA2),
    key: 'merge_video',
    type: 'primary',
    canOperation: userType === 'phone',
    onButtonClick: handleButtonClick(ParticipantActionType.MERGE_VIDEO, userId, onParticipantsButtonClick),
    group: 'permission'
  }, {
    type: 'group',
    title: t('fmt_screenshare_controlbar_button_security'),
    key: 'security'
  }, {
    title: t('fmt_attendies_options_putinwaitingroom'),
    icon: createIcon(FcrIconType.FCR_PUT_WAITING_ROOM, ICON_SIZE, {
      iconPrimary: RAMP_RED_COLOR
    }),
    key: 'put_into_waiting_room',
    type: 'danger',
    canOperation: true,
    onButtonClick: handleButtonClick(ParticipantActionType.PUT_IN_WAITING_ROOM, userId, onParticipantsButtonClick),
    group: 'security'
  }, {
    title: t('fmt_chat_options_Forbidchat'),
    icon: createIcon(FcrIconType.FCR_MOBILE_CHAT3, ICON_SIZE, {
      iconPrimary: RAMP_RED_COLOR
    }),
    key: 'forbid_chat',
    type: 'danger',
    canOperation: isChatForbidden === undefined || isChatForbidden === false,
    onButtonClick: handleButtonClick(ParticipantActionType.FORBID_CHAT, userId, onParticipantsButtonClick),
    group: 'security'
  }, {
    title: t('fmt_webinar_participant_list_more_turn_on_chat'),
    icon: createIcon(FcrIconType.FCR_MOBILE_CHAT3),
    key: 'allow_chat',
    type: 'primary',
    canOperation: isChatForbidden === true,
    onButtonClick: handleButtonClick(ParticipantActionType.ALLOW_CHAT, userId, onParticipantsButtonClick),
    group: 'security'
  }, {
    title: t('fmt_sip_button_remove'),
    icon: createIcon(FcrIconType.FCR_SETTING_NONE, ICON_SIZE, {
      iconPrimary: RAMP_RED_COLOR
    }),
    key: 'kick_out',
    type: 'danger',
    canOperation: true,
    onButtonClick: handleButtonClick(ParticipantActionType.KICK_OUT, userId, onParticipantsButtonClick),
    group: 'security'
  }];

  // 过滤允许的操作
  var filterAllowedOperations = function filterAllowedOperations(menuItems) {
    if (Array.isArray(allowedOperations) && allowedOperations.length > 0) {
      return menuItems.filter(function (item) {
        return allowedOperations.includes(item.key) && item.canOperation || item.type === 'group';
      }).filter(function (item) {
        if (hideActions && hideActions.length) {
          return !hideActions.includes(item.key);
        }
        return true;
      });
    }
    return menuItems;
  };
  var currentActions = filterAllowedOperations(allOperationMenu);

  // 过滤有分组的项
  var hasGroupItem = currentActions.filter(function (item) {
    return item.type === 'group' && currentActions.some(function (action) {
      return action.group === item.key;
    }) || item.type !== 'group';
  });
  return /*#__PURE__*/_jsx(FcrDropMenu, {
    className: "fcr-participants-more-dropmenu",
    title: userName,
    options: hasGroupItem,
    isOptionIconAlignsToLeft: true
  });
};
export { FcrParticipantsMoreActions };