"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _ContextMenuComponents = require("../ContextMenu/ContextMenuComponents");
var _reactRedux = require("react-redux");
var _MESSAGE_INTERACTIONS = require("../../helpers/constants/MESSAGE_INTERACTIONS");
var _reactNative = require("react-native");
var Clipboard = _interopRequireWildcard(require("expo-clipboard"));
var _ToastContext = require("../../context/ToastContext");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (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 (const 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); }
const MessageInteractions = ({
  isReply,
  isUser,
  message,
  closeMenu,
  position,
  handleReplyMessage: replyMessage,
  handleDeleteMessage,
  handleEditMessage
}) => {
  const {
    showToast
  } = (0, _ToastContext.useToast)();
  const config = (0, _reactRedux.useSelector)(state => state.chatSettingStore.config);
  const handleCopyMessage = async text => {
    try {
      await Clipboard.setStringAsync(text);
      showToast({
        id: Date.now().toString(),
        title: 'Success',
        message: 'Copied to clipboard!',
        type: 'success'
      });
    } catch (err) {
      console.log(err);
      showToast({
        id: Date.now().toString(),
        title: 'Copy failed',
        message: err?.message || 'Unknown error',
        type: 'error'
      });
    }
    closeMenu();
  };
  const handleReplyMessage = () => {
    replyMessage();
  };
  const memoPosition = (0, _react.useMemo)(() => {
    if (position) {
      if (isUser) {
        return {
          top: position.y,
          right: 10
        };
      }
      return {
        top: position.y,
        left: 10
      };
    }
  }, [position, isUser]);
  if (config?.disableInteractions) {
    return null;
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Modal, {
    transparent: true,
    animationType: "fade",
    visible: true,
    onRequestClose: closeMenu,
    children: !message.isDeleted && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
      style: styles.overlayFill,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
        style: _reactNative.StyleSheet.absoluteFill,
        onPress: closeMenu
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
        style: [styles.contextMenu, memoPosition],
        children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_ContextMenuComponents.MenuItem, {
          onPress: () => handleCopyMessage(message.body),
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
            children: _MESSAGE_INTERACTIONS.MESSAGE_INTERACTIONS.COPY
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_MESSAGE_INTERACTIONS.MESSAGE_INTERACTIONS_ICONS.COPY, {})]
        }), isUser && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ContextMenuComponents.Delimeter, {}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ContextMenuComponents.MenuItem, {
            onPress: handleEditMessage,
            children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
              children: _MESSAGE_INTERACTIONS.MESSAGE_INTERACTIONS.EDIT
            }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_MESSAGE_INTERACTIONS.MESSAGE_INTERACTIONS_ICONS.EDIT, {})]
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ContextMenuComponents.Delimeter, {}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ContextMenuComponents.MenuItem, {
            onPress: handleDeleteMessage,
            children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
              children: _MESSAGE_INTERACTIONS.MESSAGE_INTERACTIONS.DELETE
            }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_MESSAGE_INTERACTIONS.MESSAGE_INTERACTIONS_ICONS.DELETE, {})]
          })]
        })]
      })]
    })
  });
};
var _default = exports.default = MessageInteractions;
const styles = _reactNative.StyleSheet.create({
  overlayFill: {
    ..._reactNative.StyleSheet.absoluteFillObject,
    backgroundColor: 'transparent'
  },
  contextMenu: {
    position: 'absolute',
    backgroundColor: 'white',
    paddingVertical: 8,
    paddingHorizontal: 16,
    borderRadius: 8,
    shadowColor: '#000',
    shadowOffset: {
      width: 0,
      height: 2
    },
    shadowOpacity: 0.25,
    shadowRadius: 4,
    elevation: 5,
    minWidth: 180
  }
});
//# sourceMappingURL=MessageInteractions.js.map