"use strict";

import React from 'react';
import Button from '../../styled/Button';
import { useDispatch, useSelector } from 'react-redux';
import { getActiveRoom } from '../../../roomStore';
import { CloseButton, GroupContainer, ModalBackground, ModalContainer, ModalTitle } from '../styledModalComponents';
import { deleteRoom as deleteRoomApi } from '../../../networking/api-requests/rooms.api';
import { deleteRoom as deleteRoomAction } from '../../../roomStore/roomsSlice';
import { Text } from 'react-native';
import { useToast } from '../../../context/ToastContext';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const DeleteChatModal = ({
  isModalOpen,
  setIsModalOpen
}) => {
  const dispatch = useDispatch();
  const {
    showToast
  } = useToast();
  const activeRoom = useSelector(state => getActiveRoom(state));
  const handleOpenModal = () => setIsModalOpen(true);
  const handleCloseModal = () => setIsModalOpen(false);
  const handleDeleteChat = async () => {
    try {
      await deleteRoomApi(activeRoom?.jid?.split('@')[0] || '');
      dispatch(deleteRoomAction({
        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__*/_jsx(ModalBackground, {
    children: /*#__PURE__*/_jsxs(ModalContainer, {
      children: [/*#__PURE__*/_jsx(CloseButton, {
        onPress: handleCloseModal,
        children: /*#__PURE__*/_jsx(Text, {
          style: {
            fontSize: 24
          },
          children: "\xD7"
        })
      }), /*#__PURE__*/_jsx(ModalTitle, {
        children: "Delete this chat ?"
      }), /*#__PURE__*/_jsxs(GroupContainer, {
        children: [/*#__PURE__*/_jsx(Button, {
          onPress: handleCloseModal,
          text: 'Cancel',
          style: {
            width: '100%'
          },
          unstyled: true,
          variant: "filled"
        }), /*#__PURE__*/_jsx(Button, {
          onPress: handleDeleteChat,
          text: 'Delete',
          style: {
            width: '100%',
            borderWidth: 1,
            borderColor: 'red'
          },
          color: "red",
          unstyled: true,
          variant: "outlined"
        })]
      })]
    })
  });
};
export default DeleteChatModal;
//# sourceMappingURL=DeleteChatModal.js.map