import { __awaiter } from "tslib";
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
import { useToast, Modal, ModalOverlay, ModalContent, ModalHeader, ModalBody, ModalFooter, Button, } from "@chakra-ui/react";
import React from "react";
import qoreStorageClient from "../hooks/qoreStorageClient";
const DeleteApplicationModal = ({ id, name, disclosure, revalidate }) => {
    const toast = useToast();
    const { updateRow, status } = qoreStorageClient
        .table("applications")
        .useUpdateRow();
    const handleDelete = React.useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
        try {
            const res = yield updateRow(id, {
                status: "deleted",
            });
            if (res) {
                disclosure.onClose();
                revalidate();
                toast({
                    title: `Success deleted application`,
                    status: "success",
                    duration: 5000,
                    isClosable: true,
                });
            }
        }
        catch (error) {
            toast({
                title: `Failed delete application`,
                description: "Oops! an error accured while delete application. please try again in a moment.",
                status: "error",
                duration: 5000,
                isClosable: true,
            });
        }
    }), [id]);
    const isLoading = React.useMemo(() => status === "loading", [status]);
    return (_jsxs(Modal, Object.assign({ isOpen: disclosure.isOpen, onClose: disclosure.onClose, closeOnOverlayClick: !isLoading, isCentered: true }, { children: [_jsx(ModalOverlay, {}), _jsxs(ModalContent, { children: [_jsxs(ModalHeader, Object.assign({ fontSize: "16px" }, { children: ["Delete \u201C", name, "\u201D?"] })), _jsx(ModalBody, Object.assign({ fontSize: "14px" }, { children: "Your app will be deleted after your project is published." })), _jsxs(ModalFooter, Object.assign({ gap: 2 }, { children: [_jsx(Button, Object.assign({ size: "sm", variant: "outline", onClick: disclosure.onClose, isDisabled: isLoading }, { children: "Cancel" })), _jsx(Button, Object.assign({ size: "sm", colorScheme: "red", isLoading: isLoading, spinnerPlacement: "start", loadingText: "Deleting app", isDisabled: isLoading, onClick: handleDelete }, { children: "Delete app" }))] }))] })] })));
};
export default DeleteApplicationModal;
//# sourceMappingURL=DeleteApplicationModal.js.map