import "core-js/modules/es.symbol.js";
import "core-js/modules/es.array.filter.js";
import "core-js/modules/es.array.for-each.js";
import "core-js/modules/es.array.push.js";
import "core-js/modules/es.object.define-properties.js";
import "core-js/modules/es.object.define-property.js";
import "core-js/modules/es.object.get-own-property-descriptor.js";
import "core-js/modules/es.object.get-own-property-descriptors.js";
import "core-js/modules/es.object.keys.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/esnext.iterator.constructor.js";
import "core-js/modules/esnext.iterator.filter.js";
import "core-js/modules/esnext.iterator.for-each.js";
import "core-js/modules/web.dom-collections.for-each.js";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import { useEffect, useState } from 'react';
import { FcrAvatar } from '../../avatar';
import { FcrPopover } from '../../popover';
import { CameraState } from '../../room-screen-share-state-bar/camera-state';
import { MicrophoneState } from '../../room-screen-share-state-bar/microphone-state';
import { FcrParticipantsMoreActions } from '../participants-more';
import './index.css';
import { FcrIconType } from '../../icon/type';
import { FcrIcon } from '../../icon';
import classNames from 'classnames';
import { FcrActionButton } from '../../button/action';
import { useI18n } from '../../../i18n';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export var ParticipantActionType = /*#__PURE__*/function (ParticipantActionType) {
  ParticipantActionType["MUTE_AUDIO"] = "MUTE_AUDIO";
  ParticipantActionType["UNMUTE_AUDIO"] = "UNMUTE_AUDIO";
  ParticipantActionType["MUTE_VIDEO"] = "MUTE_VIDEO";
  ParticipantActionType["UNMUTE_VIDEO"] = "UNMUTE_VIDEO";
  ParticipantActionType["PRIVATE_CHAT"] = "PRIVATE_CHAT";
  ParticipantActionType["KICK_OUT"] = "KICK_OUT";
  ParticipantActionType["FORBID_CHAT"] = "FORBID_CHAT";
  ParticipantActionType["ALLOW_CHAT"] = "ALLOW_CHAT";
  ParticipantActionType["ADD_PIN"] = "ADD_PIN";
  ParticipantActionType["REMOVE_PIN"] = "REMOVE_PIN";
  ParticipantActionType["SET_AS_HOST"] = "SET_AS_HOST";
  ParticipantActionType["SET_AS_CO_HOST"] = "SET_AS_CO_HOST";
  ParticipantActionType["SET_AS_ATTENDEE"] = "SET_AS_ATTENDEE";
  ParticipantActionType["SET_AS_AUDIENCE"] = "SET_AS_AUDIENCE";
  ParticipantActionType["RENAME"] = "RENAME";
  ParticipantActionType["ALLOW_RECORDING_CLIENT_VIDEO"] = "ALLOW_RECORDING_CLIENT_VIDEO";
  ParticipantActionType["DISALLOW_RECORDING_CLIENT_VIDEO"] = "DISALLOW_RECORDING_CLIENT_VIDEO";
  ParticipantActionType["PUT_IN_WAITING_ROOM"] = "PUT_IN_WAITING_ROOM";
  ParticipantActionType["STOP_RAISE_HAND"] = "STOP_RAISE_HAND";
  /** 主持人/联席对指定成员拒绝举手（放下手） */
  ParticipantActionType["HANDS_DOWN"] = "HANDS_DOWN";
  ParticipantActionType["SET_MAIN_SPEAKER"] = "SET_MAIN_SPEAKER";
  ParticipantActionType["MERGE_VIDEO"] = "MERGE_VIDEO";
  ParticipantActionType["RENAME_IN_MEETING"] = "RENAME_IN_MEETING";
  return ParticipantActionType;
}({});
export var FcrUserRole = /*#__PURE__*/function (FcrUserRole) {
  FcrUserRole[FcrUserRole["HOST"] = 1] = "HOST";
  FcrUserRole[FcrUserRole["COHOST"] = 2] = "COHOST";
  FcrUserRole[FcrUserRole["PARTICIPANT"] = 3] = "PARTICIPANT";
  FcrUserRole[FcrUserRole["AUDIENCE"] = 4] = "AUDIENCE";
  FcrUserRole[FcrUserRole["OBSERVER"] = 5] = "OBSERVER";
  FcrUserRole[FcrUserRole["ROBOT"] = 6] = "ROBOT";
  return FcrUserRole;
}({});

// 定义一个类型来表示该枚举的值类型

export var FcrParticipant = function FcrParticipant(props) {
  var user = props.user,
    hasPinnedStream = props.hasPinnedStream,
    _props$onParticipants = props.onParticipantsButtonClick,
    onParticipantsButtonClick = _props$onParticipants === void 0 ? function () {} : _props$onParticipants,
    _props$hideActions = props.hideActions,
    hideActions = _props$hideActions === void 0 ? [] : _props$hideActions,
    isLocalCameraInSecondaryWindow = props.isLocalCameraInSecondaryWindow;
  var userId = user.userId,
    _user$userName = user.userName,
    userName = _user$userName === void 0 ? '' : _user$userName,
    hasAudio = user.hasAudio,
    hasVideo = user.hasVideo,
    isHost = user.isHost,
    _user$isMe = user.isMe,
    isMe = _user$isMe === void 0 ? false : _user$isMe,
    _user$isScreenSharing = user.isScreenSharing,
    isScreenSharing = _user$isScreenSharing === void 0 ? false : _user$isScreenSharing,
    userType = user.userType,
    videoDeviceType = user.videoDeviceType,
    audioDeviceType = user.audioDeviceType,
    userRole = user.userRole;
  var t = useI18n();
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    isShowDropMenu = _useState2[0],
    setIsShowDropMenu = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    disableHover = _useState4[0],
    setDisableHover = _useState4[1];
  useEffect(function () {
    setDisableHover(userType !== 'normal');
  }, [userType]);
  var userActions = function userActions() {
    return /*#__PURE__*/_jsxs("div", {
      className: "attendee__user-action attendee__user-action-host ".concat(isShowDropMenu ? 'attendee__user-action-hovered' : ''),
      children: [isMe && isHost ? /*#__PURE__*/_jsx(FcrActionButton, {
        size: "small",
        onClick: function onClick() {
          onParticipantsButtonClick(hasAudio ? ParticipantActionType.MUTE_AUDIO : ParticipantActionType.UNMUTE_AUDIO, userId);
        },
        children: /*#__PURE__*/_jsx("span", {
          className: hasAudio ? 'attendee__danger-operate' : 'attendee__normal-operate',
          children: hasAudio ? t('fmt_device_label_audio_mute') : isMe ? t('fmt_device_label_audio_unmute') : t('fmt_sip_button_unmute')
        })
      }) : /*#__PURE__*/_jsx("div", {
        children: isMe ? /*#__PURE__*/_jsx(FcrActionButton, {
          size: "small",
          onClick: function onClick() {
            return onParticipantsButtonClick(hasAudio ? ParticipantActionType.MUTE_AUDIO : ParticipantActionType.UNMUTE_AUDIO, userId);
          },
          children: hasAudio ? t('fmt_device_label_audio_mute') : t('fmt_device_label_audio_unmute')
        }) : /*#__PURE__*/_jsx(FcrActionButton, {
          size: "small",
          onClick: function onClick() {
            return onParticipantsButtonClick(ParticipantActionType.PRIVATE_CHAT, userId);
          },
          children: t('fmt_chats_label_privatechat')
        })
      }), /*#__PURE__*/_jsx(FcrPopover, {
        visible: isShowDropMenu,
        overlayInnerStyle: {
          border: 0,
          boxShadow: 'var(--fcr_web_light_dropup_m)',
          borderRadius: 'var(--fcr_cornerradius_l)',
          maxWidth: '230px',
          minWidth: '210px'
        },
        overlayClassName: "attendee__more-actions",
        mouseEnterDelay: 0,
        content: /*#__PURE__*/_jsx("div", {
          onMouseEnter: function onMouseEnter() {
            return setIsShowDropMenu(true);
          },
          onMouseLeave: function onMouseLeave() {
            return setIsShowDropMenu(false);
          },
          children: /*#__PURE__*/_jsx(FcrParticipantsMoreActions, {
            hideActions: hideActions,
            hasPinnedStream: hasPinnedStream,
            onParticipantsButtonClick: onParticipantsButtonClick,
            isLocalCameraInSecondaryWindow: isLocalCameraInSecondaryWindow,
            user: user
          })
        }),
        placement: "bottomRight",
        children: /*#__PURE__*/_jsx(FcrActionButton, {
          onClick: function onClick() {
            return setIsShowDropMenu(true);
          },
          iconType: FcrIconType.FCR_DROPDOWN,
          children: t('fmt_participants_member_button_more')
        })
      })]
    });
  };
  var userAvatar = function userAvatar() {
    if (userType === 'meeting-system') {
      return {
        icon: /*#__PURE__*/_jsx(FcrIcon, {
          type: FcrIconType.FCR_SIPDEVICE,
          colors: {
            iconPrimary: 'var(--fcr_ui_scene_white10)',
            iconSecondary: 'var(--fcr_ui_scene_ramp_green6)'
          }
        }),
        backgroundColor: 'var(--fcr_ui_scene_ramp_purple7)'
      };
    }
    if (userType === 'phone') {
      return {
        icon: /*#__PURE__*/_jsx(FcrIcon, {
          type: FcrIconType.FCR_PHONECALL3
        }),
        backgroundColor: 'var(--fcr_ui_scene_ramp_green6)'
      };
    }
    return {
      icon: null,
      backgroundColor: ''
    };
  };
  return /*#__PURE__*/_jsxs("div", {
    className: classNames('attendee', {
      'attendee-active': isShowDropMenu && !disableHover
    }),
    onMouseLeave: function onMouseLeave() {
      return setIsShowDropMenu(false);
    },
    children: [/*#__PURE__*/_jsxs("div", {
      className: "attendee__user-info",
      children: [/*#__PURE__*/_jsx(FcrAvatar, _objectSpread({
        size: 24,
        nickName: userName,
        textSize: 12
      }, userAvatar())), /*#__PURE__*/_jsxs("div", {
        className: "attendee__user-info-identity",
        children: [/*#__PURE__*/_jsxs("div", {
          className: "attendee__name",
          children: [userName, isMe && /*#__PURE__*/_jsxs("span", {
            className: "attendee__me-badge",
            children: ["(", t('fmt_participant_label_Me'), ")"]
          })]
        }), isHost && /*#__PURE__*/_jsx("div", {
          className: "attendee__host-badge",
          children: t('fmt-role-host')
        })]
      })]
    }), /*#__PURE__*/_jsxs("div", {
      className: "attendee__user-media",
      children: [isScreenSharing && /*#__PURE__*/_jsx(FcrIcon, {
        type: FcrIconType.FCR_SCREENSHARING_1,
        size: 28,
        colors: {
          iconPrimary: 'var(--fcr_ui_scene_ramp_green6)'
        }
      }), audioDeviceType !== 'none' && /*#__PURE__*/_jsx(MicrophoneState, {
        isMicrophoneMuted: !hasAudio,
        size: 28,
        isPhoneMic: audioDeviceType === 'phone-mic'
      }), videoDeviceType !== 'none' && /*#__PURE__*/_jsx(CameraState, {
        isCameraMuted: !hasVideo,
        size: 28
      })]
    }), "userActions()"]
  }, userId);
};