"use strict";

require("core-js/modules/es.object.define-property.js");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FcrParticipantsMoreActions = void 0;
require("core-js/modules/es.array.filter.js");
require("core-js/modules/es.array.includes.js");
require("core-js/modules/es.array.is-array.js");
require("core-js/modules/es.array.some.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/es.string.includes.js");
require("core-js/modules/esnext.array.group.js");
require("core-js/modules/esnext.iterator.constructor.js");
require("core-js/modules/esnext.iterator.filter.js");
require("core-js/modules/esnext.iterator.some.js");
var _dropMenu = require("../../drop-menu");
var _icon = require("../../icon");
var _type = require("../../icon/type");
var _attendee = require("../attendee");
var _cameraState = require("../../room-screen-share-state-bar/camera-state");
var _i18next = require("i18next");
require("./index.css");
var _jsxRuntime = require("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__*/(0, _jsxRuntime.jsx)(_icon.FcrIcon, {
    type: type,
    size: size,
    colors: colors
  });
};

// 封装按钮点击处理函数
var handleButtonClick = function handleButtonClick(actionType, userId, onParticipantsButtonClick) {
  return function () {
    onParticipantsButtonClick(actionType, userId);
  };
};
var FcrParticipantsMoreActions = exports.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,
    hasClientRecordingPermission = user.hasClientRecordingPermission,
    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__*/(0, _jsxRuntime.jsx)(_cameraState.CameraState, {
      ignoreColor: true,
      isCameraMuted: true,
      renderMode: "forward-state"
    }),
    title: (0, _i18next.t)('fmt_device_label_video_start'),
    key: 'start_video',
    type: cameraStateType,
    canOperation: !hasVideo && userType !== 'phone',
    onButtonClick: handleButtonClick(_attendee.ParticipantActionType.UNMUTE_VIDEO, userId, onParticipantsButtonClick)
  }, {
    icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_cameraState.CameraState, {
      ignoreColor: true,
      isCameraMuted: true,
      renderMode: "forward-state"
    }),
    title: (0, _i18next.t)('fmt_sip_button_opencamera'),
    key: 'request_start_video',
    type: 'primary',
    canOperation: !hasVideo && !isMe && userType !== 'phone',
    onButtonClick: handleButtonClick(_attendee.ParticipantActionType.UNMUTE_VIDEO, userId, onParticipantsButtonClick)
  }, {
    icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_cameraState.CameraState, {
      isCameraMuted: false,
      renderMode: "forward-state"
    }),
    title: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      children: (0, _i18next.t)('fmt_device_label_video_stop')
    }),
    key: 'stop_video',
    type: cameraStateType,
    canOperation: hasVideo && userType !== 'phone',
    onButtonClick: handleButtonClick(_attendee.ParticipantActionType.MUTE_VIDEO, userId, onParticipantsButtonClick)
  }, {
    icon: createIcon(_type.FcrIconType.FCR_MOBILE_CHAT3),
    title: (0, _i18next.t)('fmt_attendies_label_privatechat'),
    key: 'private_chat',
    type: 'primary',
    canOperation: !isMe && userType !== 'phone',
    onButtonClick: handleButtonClick(_attendee.ParticipantActionType.PRIVATE_CHAT, userId, onParticipantsButtonClick)
  }, {
    title: (0, _i18next.t)('fmt_attendies_button_handsdown'),
    icon: createIcon(_type.FcrIconType.FCR_HANDSDOWN),
    key: 'hands_down',
    type: 'danger',
    canOperation: true,
    onButtonClick: handleButtonClick(_attendee.ParticipantActionType.HANDS_DOWN, userId, onParticipantsButtonClick)
  }, {
    type: 'group',
    title: (0, _i18next.t)('fmt_additional_label_meet_view_own'),
    key: 'own_view'
  }, {
    icon: isPin ? createIcon(_type.FcrIconType.FCR_UNPIN) : createIcon(_type.FcrIconType.FCR_PINPAGE),
    title: isPin ? /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      children: (0, _i18next.t)('fmt_attendies_options_cancelfixed')
    }) : hasPinnedStream ? (0, _i18next.t)('fmt_attendies_options_replacefixed') : (0, _i18next.t)('fmt_attendies_options_fixfirst'),
    key: 'pin',
    type: isPin ? 'danger' : 'primary',
    canOperation: isShowPinOption,
    onButtonClick: handleButtonClick(isPin ? _attendee.ParticipantActionType.REMOVE_PIN : _attendee.ParticipantActionType.ADD_PIN, userId, onParticipantsButtonClick),
    group: 'own_view'
  }, {
    type: 'group',
    title: (0, _i18next.t)('fmt_additional_label_attendee_permission'),
    key: 'permission'
  }, {
    title: (0, _i18next.t)('fmt_attendies_options_sethost'),
    icon: createIcon(_type.FcrIconType.FCR_HOST2),
    key: 'set_as_host',
    canOperation: userRole !== _attendee.FcrUserRole.HOST && userType === 'normal',
    onButtonClick: handleButtonClick(_attendee.ParticipantActionType.SET_AS_HOST, userId, onParticipantsButtonClick),
    group: 'permission'
  }, {
    title: (0, _i18next.t)('fmt_attendies_options_setcohost'),
    icon: createIcon(_type.FcrIconType.FCR_COHOST2),
    key: 'set_as_co_host',
    type: 'primary',
    canOperation: userRole !== _attendee.FcrUserRole.COHOST && userType === 'normal',
    onButtonClick: handleButtonClick(_attendee.ParticipantActionType.SET_AS_CO_HOST, userId, onParticipantsButtonClick),
    group: 'permission'
  }, {
    title: (0, _i18next.t)('fmt_attendies_options_revokecohost'),
    icon: createIcon(_type.FcrIconType.FCR_COHOST2),
    key: 'revoke_co_host',
    type: 'danger',
    canOperation: userRole === _attendee.FcrUserRole.COHOST && userType === 'normal',
    onButtonClick: handleButtonClick(_attendee.ParticipantActionType.SET_AS_ATTENDEE, userId, onParticipantsButtonClick),
    group: 'permission'
  }, {
    title: hasClientRecordingPermission ? (0, _i18next.t)('fmt_localrecord_option_disable_localrecord') : (0, _i18next.t)('fmt_localrecord_option_enable_localrecord'),
    icon: hasClientRecordingPermission ? createIcon(_type.FcrIconType.FCR_STOPRECORD_CIRCLE_FILL_3) : createIcon(_type.FcrIconType.FCR_RECORD_CIRCLE_FILL_1),
    key: 'allow_record_local_video',
    type: hasClientRecordingPermission ? 'danger' : 'primary',
    canOperation: !isMe && userRole === _attendee.FcrUserRole.PARTICIPANT && userType === 'normal',
    onButtonClick: handleButtonClick(hasClientRecordingPermission ? _attendee.ParticipantActionType.DISALLOW_RECORDING_CLIENT_VIDEO : _attendee.ParticipantActionType.ALLOW_RECORDING_CLIENT_VIDEO, userId, onParticipantsButtonClick),
    group: 'permission'
  }, {
    title: (0, _i18next.t)('fmt_webinar_participant_list_more_promote_to_presenter'),
    icon: createIcon(_type.FcrIconType.FCR_GUEST, ICON_SIZE_GUEST),
    key: 'set_as_attendee',
    type: 'primary',
    canOperation: userRole === _attendee.FcrUserRole.AUDIENCE && userType === 'normal',
    onButtonClick: handleButtonClick(_attendee.ParticipantActionType.SET_AS_ATTENDEE, userId, onParticipantsButtonClick),
    group: 'permission'
  }, {
    title: (0, _i18next.t)('fmt_webinar_participant_list_more_move_to_attendee'),
    icon: createIcon(_type.FcrIconType.FCR_GUEST),
    key: 'set_as_audience',
    type: 'primary',
    canOperation: userRole === _attendee.FcrUserRole.PARTICIPANT && userType === 'normal',
    onButtonClick: handleButtonClick(_attendee.ParticipantActionType.SET_AS_AUDIENCE, userId, onParticipantsButtonClick),
    group: 'permission'
  }, {
    title: (0, _i18next.t)('fmt_additional_option_rename_in_meeting'),
    icon: createIcon(_type.FcrIconType.FCR_RENAME2),
    key: 'change_name',
    type: 'primary',
    canOperation: true,
    onButtonClick: handleButtonClick(_attendee.ParticipantActionType.RENAME_IN_MEETING, userId, onParticipantsButtonClick),
    group: 'permission'
  }, {
    title: (0, _i18next.t)('fmt_modules_tips_mergevideo'),
    icon: createIcon(_type.FcrIconType.FCR_MOBILE_CAMERA2),
    key: 'merge_video',
    type: 'primary',
    canOperation: userType === 'phone',
    onButtonClick: handleButtonClick(_attendee.ParticipantActionType.MERGE_VIDEO, userId, onParticipantsButtonClick),
    group: 'permission'
  }, {
    type: 'group',
    title: (0, _i18next.t)('fmt_screenshare_controlbar_button_security'),
    key: 'security'
  }, {
    title: (0, _i18next.t)('fmt_attendies_options_putinwaitingroom'),
    icon: createIcon(_type.FcrIconType.FCR_PUT_WAITING_ROOM, ICON_SIZE, {
      iconPrimary: RAMP_RED_COLOR
    }),
    key: 'put_into_waiting_room',
    type: 'danger',
    canOperation: true,
    onButtonClick: handleButtonClick(_attendee.ParticipantActionType.PUT_IN_WAITING_ROOM, userId, onParticipantsButtonClick),
    group: 'security'
  }, {
    title: (0, _i18next.t)('fmt_chat_options_Forbidchat'),
    icon: createIcon(_type.FcrIconType.FCR_MOBILE_CHAT3, ICON_SIZE, {
      iconPrimary: RAMP_RED_COLOR
    }),
    key: 'forbid_chat',
    type: 'danger',
    canOperation: isChatForbidden === undefined || isChatForbidden === false,
    onButtonClick: handleButtonClick(_attendee.ParticipantActionType.FORBID_CHAT, userId, onParticipantsButtonClick),
    group: 'security'
  }, {
    title: (0, _i18next.t)('fmt_webinar_participant_list_more_turn_on_chat'),
    icon: createIcon(_type.FcrIconType.FCR_MOBILE_CHAT3),
    key: 'allow_chat',
    type: 'primary',
    canOperation: isChatForbidden === true,
    onButtonClick: handleButtonClick(_attendee.ParticipantActionType.ALLOW_CHAT, userId, onParticipantsButtonClick),
    group: 'security'
  }, {
    title: (0, _i18next.t)('fmt_sip_button_remove'),
    icon: createIcon(_type.FcrIconType.FCR_SETTING_NONE, ICON_SIZE, {
      iconPrimary: RAMP_RED_COLOR
    }),
    key: 'kick_out',
    type: 'danger',
    canOperation: true,
    onButtonClick: handleButtonClick(_attendee.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__*/(0, _jsxRuntime.jsx)(_dropMenu.FcrDropMenu, {
    className: "fcr-participants-more-dropmenu",
    title: userName,
    options: hasGroupItem,
    isOptionIconAlignsToLeft: true
  });
};