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";
import "core-js/modules/web.timers.js";
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 classNames from 'classnames';
import React, { useState, useEffect, forwardRef, useImperativeHandle, useRef } from 'react';
import './index.css';
import { FcrIcon } from '../icon';
import { FcrIconType } from '../icon/type';
import { useI18n } from '../../i18n';
import { FcrPopover } from '../popover';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export var LineCopyButton = /*#__PURE__*/forwardRef(function LineCopyButton(props, ref) {
  var t = useI18n();
  var styles = props.styles,
    _props$direction = props.direction,
    direction = _props$direction === void 0 ? 'left' : _props$direction,
    _props$btnText = props.btnText,
    btnText = _props$btnText === void 0 ? t('fmt_meetingInfo_window_info_meetingID_copy') : _props$btnText,
    onCopy = props.onCopy,
    onPrivate = props.onPrivate,
    showPrivate = props.showPrivate,
    _props$margins = props.margins,
    _props$margins2 = _props$margins === void 0 ? {} : _props$margins,
    _props$margins2$paren = _props$margins2.parentMarginR,
    parentMarginR = _props$margins2$paren === void 0 ? 6 : _props$margins2$paren,
    _props$margins2$grand = _props$margins2.grandParentMarginR,
    grandParentMarginR = _props$margins2$grand === void 0 ? 20 : _props$margins2$grand,
    _props$margins2$paren2 = _props$margins2.parentMarginL,
    parentMarginL = _props$margins2$paren2 === void 0 ? 6 : _props$margins2$paren2,
    _props$margins2$grand2 = _props$margins2.grandParentMarginL,
    grandParentMarginL = _props$margins2$grand2 === void 0 ? 20 : _props$margins2$grand2;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    hover = _useState2[0],
    setHover = _useState2[1];
  var cls = classNames('fcr-line-copy', {
    'fcr-line-copy-margin': hover
  });
  var divRef = React.useRef(null);
  useImperativeHandle(ref, function () {
    return {
      dom: divRef.current
    };
  });
  var _useState3 = useState(0),
    _useState4 = _slicedToArray(_useState3, 2),
    iconPositionTop = _useState4[0],
    setIconPositionTop = _useState4[1];
  var _useState5 = useState(0),
    _useState6 = _slicedToArray(_useState5, 2),
    iconPositionLeft = _useState6[0],
    setIconPositionLeft = _useState6[1];
  var btnMargin = 8;
  var avatarWidth = 34;
  useEffect(function () {
    if (divRef.current) {
      var _msgBubbleDiv$clientH, _msgBubbleDiv$clientW, _moreBtn$clientHeight, _moreBtn$clientWidth, _lineMsgView$clientWi, _lineMsgView$clientWi2, _lineMsgView$parentEl, _virtualListContainer;
      // Message bubble
      var msgBubbleDiv = divRef.current.parentElement;
      var msgBubbleHeight = (_msgBubbleDiv$clientH = msgBubbleDiv === null || msgBubbleDiv === void 0 ? void 0 : msgBubbleDiv.clientHeight) !== null && _msgBubbleDiv$clientH !== void 0 ? _msgBubbleDiv$clientH : 0;
      var msgBubbleWidth = (_msgBubbleDiv$clientW = msgBubbleDiv === null || msgBubbleDiv === void 0 ? void 0 : msgBubbleDiv.clientWidth) !== null && _msgBubbleDiv$clientW !== void 0 ? _msgBubbleDiv$clientW : 0;

      // More button
      var moreBtn = divRef.current.children[0];
      var moreBtnHeight = (_moreBtn$clientHeight = moreBtn.clientHeight) !== null && _moreBtn$clientHeight !== void 0 ? _moreBtn$clientHeight : 0;
      var moreBtnWidth = (_moreBtn$clientWidth = moreBtn === null || moreBtn === void 0 ? void 0 : moreBtn.clientWidth) !== null && _moreBtn$clientWidth !== void 0 ? _moreBtn$clientWidth : 0;
      setIconPositionTop(msgBubbleHeight ? (msgBubbleHeight - moreBtnHeight) / 2 : 0);

      // Message list Item
      var lineMsgView = divRef.current.parentElement;
      var msgLineWidth = direction === 'left' ? (_lineMsgView$clientWi = lineMsgView === null || lineMsgView === void 0 ? void 0 : lineMsgView.clientWidth) !== null && _lineMsgView$clientWi !== void 0 ? _lineMsgView$clientWi : 0 : ((_lineMsgView$clientWi2 = lineMsgView === null || lineMsgView === void 0 ? void 0 : lineMsgView.clientWidth) !== null && _lineMsgView$clientWi2 !== void 0 ? _lineMsgView$clientWi2 : 0) + avatarWidth;
      var virtualListContainer = lineMsgView === null || lineMsgView === void 0 || (_lineMsgView$parentEl = lineMsgView.parentElement) === null || _lineMsgView$parentEl === void 0 || (_lineMsgView$parentEl = _lineMsgView$parentEl.parentElement) === null || _lineMsgView$parentEl === void 0 || (_lineMsgView$parentEl = _lineMsgView$parentEl.parentElement) === null || _lineMsgView$parentEl === void 0 || (_lineMsgView$parentEl = _lineMsgView$parentEl.parentElement) === null || _lineMsgView$parentEl === void 0 ? void 0 : _lineMsgView$parentEl.parentElement;
      var listContainerWidth = (_virtualListContainer = virtualListContainer === null || virtualListContainer === void 0 ? void 0 : virtualListContainer.clientWidth) !== null && _virtualListContainer !== void 0 ? _virtualListContainer : 0;
      var currentEmbed = false;
      if (msgLineWidth + moreBtnWidth + btnMargin > listContainerWidth - (parentMarginL + parentMarginR)) {
        currentEmbed = true;
      } else {
        currentEmbed = false;
      }
      var embedSize = 10;
      switch (direction) {
        case 'left':
          if (currentEmbed) {
            setIconPositionLeft(-(moreBtnWidth - embedSize));
          } else {
            setIconPositionLeft(-(btnMargin + moreBtnWidth));
          }
          break;
        case 'right':
          if (currentEmbed) {
            setIconPositionLeft(msgBubbleWidth + embedSize - moreBtnWidth);
          } else {
            setIconPositionLeft(msgBubbleWidth + btnMargin);
          }
          break;
        default:
          break;
      }
    }
  }, []);
  return /*#__PURE__*/_jsx("div", {
    ref: divRef,
    className: classNames('fcr-line-copy-wrapper', {
      'fcr-copy__direction-left': direction === 'left',
      'fcr-copy__direction-right': direction === 'right'
    }),
    style: _objectSpread(_objectSpread({}, styles), {}, {
      top: iconPositionTop,
      left: iconPositionLeft,
      visibility: divRef.current ? 'visible' : 'hidden'
    }),
    onMouseEnter: function onMouseEnter() {
      return setHover(true);
    },
    children: /*#__PURE__*/_jsx(FcrPopover, {
      showArrow: false,
      overlayInnerStyle: {
        width: '100%',
        overflow: 'unset',
        border: 'none',
        boxShadow: 'none',
        background: 'unset',
        backgroundColor: 'unset',
        maxWidth: '100px'
      },
      visible: hover,
      onVisibleChange: function onVisibleChange(visible) {
        setHover(visible);
      },
      trigger: "hover",
      mouseLeaveDelay: 500,
      placement: direction === 'left' ? 'bottomLeft' : 'bottomRight',
      content: /*#__PURE__*/_jsxs("div", {
        className: 'fcr-copy-btn',
        children: [/*#__PURE__*/_jsx("button", {
          onClick: function onClick() {
            return onCopy === null || onCopy === void 0 ? void 0 : onCopy('singling');
          },
          children: /*#__PURE__*/_jsx("div", {
            className: 'fcr-btn-text',
            children: /*#__PURE__*/_jsx("span", {
              children: btnText
            })
          })
        }), /*#__PURE__*/_jsx("button", {
          onClick: function onClick() {
            return onCopy === null || onCopy === void 0 ? void 0 : onCopy('multiple');
          },
          children: /*#__PURE__*/_jsx("div", {
            className: 'fcr-btn-text',
            children: /*#__PURE__*/_jsx("span", {
              children: t('fmt_chat_button_MultipleChoice')
            })
          })
        }), showPrivate && /*#__PURE__*/_jsx("button", {
          onClick: function onClick() {
            onPrivate === null || onPrivate === void 0 || onPrivate();
          },
          children: /*#__PURE__*/_jsx("div", {
            className: 'fcr-btn-text',
            children: /*#__PURE__*/_jsx("span", {
              children: t('fmt_chats_label_privatechat')
            })
          })
        })]
      }),
      children: /*#__PURE__*/_jsx("div", {
        className: cls,
        children: /*#__PURE__*/_jsx(FcrIcon, {
          type: FcrIconType.FCR_MOBILE_MORE,
          size: 16,
          colors: {
            iconPrimary: "var(--fcr_web_ui_scene_mainicon2)"
          }
        })
      })
    })
  });
});
export var PrivateButton = function PrivateButton(props) {
  var _useState7 = useState(false),
    _useState8 = _slicedToArray(_useState7, 2),
    privateChatHover = _useState8[0],
    setPrivateChatHover = _useState8[1];
  var onPrivate = props.onPrivate;
  var t = useI18n();
  var hideTimeout = useRef(0);
  return /*#__PURE__*/_jsx("div", {
    onMouseEnter: function onMouseEnter() {
      clearTimeout(hideTimeout.current);
      setPrivateChatHover(true);
    },
    onMouseLeave: function onMouseLeave() {
      hideTimeout.current = window.setTimeout(function () {
        setPrivateChatHover(false);
      }, 80);
    },
    children: /*#__PURE__*/_jsx(FcrPopover, {
      overlayInnerStyle: {
        width: '100%',
        overflow: 'unset',
        border: 'none',
        boxShadow: 'none',
        background: 'unset',
        backgroundColor: 'unset'
      },
      visible: privateChatHover,
      onVisibleChange: function onVisibleChange(visible) {
        setPrivateChatHover(visible);
      },
      trigger: "hover",
      mouseLeaveDelay: 80,
      placement: 'bottomLeft',
      content: /*#__PURE__*/_jsx("div", {
        children: /*#__PURE__*/_jsx("div", {
          className: 'fcr-copy-btn fcr-single-btn',
          children: /*#__PURE__*/_jsx("button", {
            onClick: function onClick() {
              onPrivate === null || onPrivate === void 0 || onPrivate();
              setPrivateChatHover(false);
            },
            children: /*#__PURE__*/_jsx("div", {
              className: 'fcr-btn-text',
              children: /*#__PURE__*/_jsx("span", {
                children: t('fmt_chats_label_privatechat')
              })
            })
          })
        })
      }),
      children: props.children
    })
  });
};