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 "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.map.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 React, { useMemo, useState } from 'react';
import { FcrIconType } from '../icon/type';
import { FcrDropMenu } from '../drop-menu';
import { FcrToolTip } from '../tooltip';
import { FcrIconButton } from '../icon-button';
import { useI18n } from '../../i18n';
import { FcrPopover } from '../popover';
import { IconText } from '../icon-text';
import './index.css';
import { jsx as _jsx } from "react/jsx-runtime";
var ChatLevelOption = function ChatLevelOption(_ref) {
  var txt = _ref.txt,
    _ref$selected = _ref.selected,
    selected = _ref$selected === void 0 ? false : _ref$selected;
  return /*#__PURE__*/_jsx(IconText, {
    icon: FcrIconType.FCR_CHOOSEIT,
    txt: txt,
    colors: selected ? {
      iconPrimary: 'var(--fcr_ui_scene_icontext1)'
    } : {},
    classnames: selected ? {
      'fcr-icon-text--selected': true
    } : {}
  });
};
export var ChatManager = function ChatManager(_ref2) {
  var isManager = _ref2.isManager,
    setAllowChat = _ref2.setAllowChat,
    setAllowChatWithPayload = _ref2.setAllowChatWithPayload,
    allowChatLevel = _ref2.allowChatLevel,
    _ref2$showArrow = _ref2.showArrow,
    showArrow = _ref2$showArrow === void 0 ? false : _ref2$showArrow;
  var t = useI18n();
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    managerVisible = _useState2[0],
    setManagerVisible = _useState2[1];
  var actions = [{
    title: /*#__PURE__*/_jsx(ChatLevelOption, {
      txt: t('fmt_chat_send_open'),
      selected: allowChatLevel === 'everyone'
    }),
    key: 'everyone',
    onButtonClick: function onButtonClick() {
      if (allowChatLevel === 'everyone') {
        return;
      }
      // 开放聊天
      setAllowChat === null || setAllowChat === void 0 || setAllowChat(true);
      setManagerVisible(false);
    }
  },
  // TODO: 环信暂不支持
  // {
  //   title: (
  //     <ChatLevelOption txt={t('chat_permission_public')} selected={allowChatLevel === 'public'} />
  //   ),
  //   key: 'public',
  //   onButtonClick: () => {
  //     if (allowChatLevel === 'public') {
  //       return;
  //     }
  //     setAllowChatWithPayload?.('public');
  //   },
  // },
  // {
  //   title: (
  //     <ChatLevelOption
  //       txt={t('fmt_additional_options_onlyprivatechat')}
  //       selected={allowChatLevel === 'private_to_manager'}
  //     />
  //   ),
  //   key: 'private_to_manager',
  //   onButtonClick: () => {
  //     if (allowChatLevel === 'private_to_manager') {
  //       return;
  //     }
  //     setAllowChatWithPayload?.('private_to_manager');
  //   },
  // },
  {
    title: /*#__PURE__*/_jsx(ChatLevelOption, {
      txt: t('fmt_chat_send_limit'),
      selected: allowChatLevel === 'no_one'
    }),
    key: 'no_one',
    onButtonClick: function onButtonClick() {
      if (allowChatLevel === 'no_one') {
        return;
      }
      // 全员禁言
      setAllowChat === null || setAllowChat === void 0 || setAllowChat(false);
      setManagerVisible(false);
    }
  }];
  var closePopover = function closePopover() {
    setManagerVisible(false);
  };
  var popoverContent = useMemo(function () {
    return /*#__PURE__*/_jsx("div", {
      onClick: closePopover,
      className: "fcr_chat_drop_menu",
      children: /*#__PURE__*/_jsx(FcrDropMenu, {
        title: t('fmt_chat_setting_value'),
        options: actions.map(function (data) {
          return _objectSpread(_objectSpread({}, data), {}, {
            classNames: allowChatLevel === data.key ? 'fcr-drop-menu-option-primary-selected' : ''
          });
        })
      })
    });
  }, [allowChatLevel, actions]);
  if (!isManager) return null;
  return /*#__PURE__*/_jsx("div", {
    id: "fcr_chat_manager",
    children: /*#__PURE__*/_jsx(FcrPopover, {
      getTooltipContainer: function getTooltipContainer(e) {
        return e.parentElement || e;
      },
      showArrow: showArrow,
      visible: managerVisible,
      overlayClassName: 'fcr_chat_manager_popover_overlay',
      trigger: "click",
      placement: "bottom",
      overlayInnerStyle: {
        border: 'none',
        minWidth: '200px',
        maxWidth: '280px',
        width: 'fit-content'
      },
      verticalOffset: -90,
      content: popoverContent,
      onVisibleChange: function onVisibleChange(visible) {
        setManagerVisible(visible);
      },
      children: /*#__PURE__*/_jsx(FcrToolTip, {
        content: t('fmt_participants_member_button_more'),
        mouseEnterDelay: 0,
        trigger: "hover",
        placement: "bottom",
        children: /*#__PURE__*/_jsx("div", {
          children: /*#__PURE__*/_jsx(FcrIconButton, {
            className: "frc-window-header__icon frc-window-header-setting__icon  fcr-no-drag",
            icon: FcrIconType.FCR_DIALOG_MORE,
            onClick: function onClick() {
              setManagerVisible(true);
            }
          })
        })
      })
    })
  });
};