"use strict";

require("core-js/modules/es.symbol.js");
require("core-js/modules/es.array.filter.js");
require("core-js/modules/es.array.for-each.js");
require("core-js/modules/es.array.iterator.js");
require("core-js/modules/es.array.push.js");
require("core-js/modules/es.object.define-properties.js");
require("core-js/modules/es.object.define-property.js");
require("core-js/modules/es.object.get-own-property-descriptor.js");
require("core-js/modules/es.object.get-own-property-descriptors.js");
require("core-js/modules/es.object.keys.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/es.string.iterator.js");
require("core-js/modules/es.weak-map.js");
require("core-js/modules/esnext.iterator.constructor.js");
require("core-js/modules/esnext.iterator.filter.js");
require("core-js/modules/esnext.iterator.for-each.js");
require("core-js/modules/esnext.weak-map.delete-all.js");
require("core-js/modules/esnext.weak-map.emplace.js");
require("core-js/modules/web.dom-collections.for-each.js");
require("core-js/modules/web.dom-collections.iterator.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.MessageBubble = void 0;
require("core-js/modules/web.timers.js");
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _classnames = _interopRequireDefault(require("classnames"));
var _react = _interopRequireWildcard(require("react"));
require("./index.css");
var _lineCopyButton = require("../line-copy-button");
var _emojiMsg = require("./emoji-msg");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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) { (0, _defineProperty2["default"])(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; }
var MessageBubble = exports.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 = (0, _react.useState)(false),
    _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
    hover = _useState2[0],
    setHover = _useState2[1];
  var bubbleIsLeft = isSelf;
  var cls = (0, _classnames["default"])('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 = (0, _react.useRef)(0);
  return /*#__PURE__*/(0, _jsxRuntime.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__*/(0, _jsxRuntime.jsx)("img", {
      src: file
    }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        style: {
          whiteSpace: 'pre-wrap'
        },
        children: (0, _emojiMsg.processEmojiTextMsg)(msg)
      }), !hiddenMore && hover && /*#__PURE__*/(0, _jsxRuntime.jsx)(_lineCopyButton.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
      })]
    })
  });
};