"use strict";

import React, { useMemo } from 'react';
import { Delimeter, MenuItem } from '../ContextMenu/ContextMenuComponents';
import { useSelector } from 'react-redux';
import { MESSAGE_INTERACTIONS, MESSAGE_INTERACTIONS_ICONS } from '../../helpers/constants/MESSAGE_INTERACTIONS';
import { Modal, Text, StyleSheet, View, Pressable } from 'react-native';
import * as Clipboard from 'expo-clipboard';
import { useToast } from '../../context/ToastContext';
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
const MessageInteractions = ({
  isReply,
  isUser,
  message,
  closeMenu,
  position,
  handleReplyMessage: replyMessage,
  handleDeleteMessage,
  handleEditMessage
}) => {
  const {
    showToast
  } = useToast();
  const config = 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 = 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__*/_jsx(Modal, {
    transparent: true,
    animationType: "fade",
    visible: true,
    onRequestClose: closeMenu,
    children: !message.isDeleted && /*#__PURE__*/_jsxs(View, {
      style: styles.overlayFill,
      children: [/*#__PURE__*/_jsx(Pressable, {
        style: StyleSheet.absoluteFill,
        onPress: closeMenu
      }), /*#__PURE__*/_jsxs(View, {
        style: [styles.contextMenu, memoPosition],
        children: [/*#__PURE__*/_jsxs(MenuItem, {
          onPress: () => handleCopyMessage(message.body),
          children: [/*#__PURE__*/_jsx(Text, {
            children: MESSAGE_INTERACTIONS.COPY
          }), /*#__PURE__*/_jsx(MESSAGE_INTERACTIONS_ICONS.COPY, {})]
        }), isUser && /*#__PURE__*/_jsxs(_Fragment, {
          children: [/*#__PURE__*/_jsx(Delimeter, {}), /*#__PURE__*/_jsxs(MenuItem, {
            onPress: handleEditMessage,
            children: [/*#__PURE__*/_jsx(Text, {
              children: MESSAGE_INTERACTIONS.EDIT
            }), /*#__PURE__*/_jsx(MESSAGE_INTERACTIONS_ICONS.EDIT, {})]
          }), /*#__PURE__*/_jsx(Delimeter, {}), /*#__PURE__*/_jsxs(MenuItem, {
            onPress: handleDeleteMessage,
            children: [/*#__PURE__*/_jsx(Text, {
              children: MESSAGE_INTERACTIONS.DELETE
            }), /*#__PURE__*/_jsx(MESSAGE_INTERACTIONS_ICONS.DELETE, {})]
          })]
        })]
      })]
    })
  });
};
export default MessageInteractions;
const styles = StyleSheet.create({
  overlayFill: {
    ...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