"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _Button = _interopRequireDefault(require("../../styled/Button"));
var _reactRedux = require("react-redux");
var _roomStore = require("../../../roomStore");
var _styledModalComponents = require("../styledModalComponents");
var _rooms = require("../../../networking/api-requests/rooms.api");
var _roomsSlice = require("../../../roomStore/roomsSlice");
var _reactNative = require("react-native");
var _ToastContext = require("../../../context/ToastContext");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const DeleteChatModal = ({
  isModalOpen,
  setIsModalOpen
}) => {
  const dispatch = (0, _reactRedux.useDispatch)();
  const {
    showToast
  } = (0, _ToastContext.useToast)();
  const activeRoom = (0, _reactRedux.useSelector)(state => (0, _roomStore.getActiveRoom)(state));
  const handleOpenModal = () => setIsModalOpen(true);
  const handleCloseModal = () => setIsModalOpen(false);
  const handleDeleteChat = async () => {
    try {
      await (0, _rooms.deleteRoom)(activeRoom?.jid?.split('@')[0] || '');
      dispatch((0, _roomsSlice.deleteRoom)({
        jid: activeRoom?.jid || ''
      }));
      handleCloseModal();
      showToast({
        id: Date.now().toString(),
        title: 'Success',
        message: 'Chat deleted successfully',
        type: 'success'
      });
    } catch (error) {
      console.error('Failed to delete chat:', error);
      showToast({
        id: Date.now().toString(),
        title: 'Error',
        message: 'Failed to delete chat',
        type: 'error'
      });
    }
  };
  return isModalOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styledModalComponents.ModalBackground, {
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styledModalComponents.ModalContainer, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_styledModalComponents.CloseButton, {
        onPress: handleCloseModal,
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
          style: {
            fontSize: 24
          },
          children: "\xD7"
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styledModalComponents.ModalTitle, {
        children: "Delete this chat ?"
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styledModalComponents.GroupContainer, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
          onPress: handleCloseModal,
          text: 'Cancel',
          style: {
            width: '100%'
          },
          unstyled: true,
          variant: "filled"
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
          onPress: handleDeleteChat,
          text: 'Delete',
          style: {
            width: '100%',
            borderWidth: 1,
            borderColor: 'red'
          },
          color: "red",
          unstyled: true,
          variant: "outlined"
        })]
      })]
    })
  });
};
var _default = exports.default = DeleteChatModal;
//# sourceMappingURL=DeleteChatModal.js.map