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, { useRef, useState } from 'react';
import './index.css';
import { LineCopyButton } from '../line-copy-button';
import { processEmojiTextMsg } from './emoji-msg';
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
export var MessageBubble = function MessageBubble(_ref) {
  var styles = _ref.styles,
    role = _ref.role,
    _ref$isSelf = _ref.isSelf,
    isSelf = _ref$isSelf === void 0 ? false : _ref$isSelf,
    _ref$msg = _ref.msg,
    msg = _ref$msg === void 0 ? "Thank you, it's nic..." : _ref$msg,
    _onCopy = _ref.onCopy,
    _onPrivate = _ref.onPrivate,
    children = _ref.children,
    marginBottom = _ref.marginBottom,
    file = _ref.file,
    _ref$hiddenMore = _ref.hiddenMore,
    hiddenMore = _ref$hiddenMore === void 0 ? false : _ref$hiddenMore;
  var isManager = role === 'host' || role === 'union-host';
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    hover = _useState2[0],
    setHover = _useState2[1];
  var bubbleIsLeft = isSelf;
  var cls = classNames('fcr-message-bubble', _objectSpread(_objectSpread({}, role === 'participant' ? {
    'fcr-message-bubble-other-bg': true,
    'fcr-message-bubble-other-bg:hover': true
  } : {}), {}, {
    'fcr-message-bubble-host-bg': isManager,
    'fcr-message-bubble-self-bg': isSelf,
    'fcr-message-bubble-margin-b-small': marginBottom === 'small',
    'fcr-message-bubble-margin-b-large': marginBottom === 'large',
    'fcr-message-bubble-left': bubbleIsLeft,
    'fcr-message-bubble-right': !bubbleIsLeft
  }));
  var hideTimeout = useRef(0);
  return /*#__PURE__*/_jsx("div", {
    className: cls,
    style: _objectSpread({}, styles),
    onMouseEnter: function onMouseEnter() {
      clearTimeout(hideTimeout.current);
      setHover(true);
    },
    onMouseLeave: function onMouseLeave() {
      hideTimeout.current = window.setTimeout(function () {
        setHover(false);
      }, 400);
    },
    children: file ? /*#__PURE__*/_jsx("img", {
      src: file
    }) : /*#__PURE__*/_jsxs(_Fragment, {
      children: [/*#__PURE__*/_jsx("div", {
        style: {
          whiteSpace: 'pre-wrap'
        },
        children: processEmojiTextMsg(msg)
      }), !hiddenMore && hover && /*#__PURE__*/_jsx(LineCopyButton, {
        onCopy: function onCopy(type) {
          _onCopy === null || _onCopy === void 0 || _onCopy(type);
          setHover(false);
        },
        onPrivate: function onPrivate() {
          _onPrivate === null || _onPrivate === void 0 || _onPrivate();
          setHover(false);
        },
        direction: isSelf ? 'left' : 'right',
        showPrivate: !isSelf
      })]
    })
  });
};