import { jsx as _jsx } from "react/jsx-runtime";
import { clearReactorStorage } from "@powerhousedao/connect";
import { ConnectConfirmationModal } from "@powerhousedao/design-system";
import { closePHModal, setSelectedDrive, setSelectedNode, showPHModal, usePHModal, } from "@powerhousedao/reactor-browser";
import { childLogger } from "document-drive";
import { useState } from "react";
import { useTranslation } from "react-i18next";
const logger = childLogger(["ClearStorage"]);
export function ClearStorageModal() {
    const phModal = usePHModal();
    const open = phModal?.type === "clearStorage";
    const { t } = useTranslation();
    const [loading, setLoading] = useState(false);
    function clearStorage() {
        setLoading(true);
        clearReactorStorage()
            .then(() => {
            logger.info("Storage cleared");
            setSelectedDrive(undefined);
            setSelectedNode(undefined);
            window.location.reload();
        })
            .catch((error) => {
            logger.error("Error clearing storage", error);
            setLoading(false);
        });
    }
    return (_jsx(ConnectConfirmationModal, { open: open, header: t("modals.clearStorage.title"), title: t("modals.clearStorage.title"), body: t("modals.connectSettings.clearStorage.confirmation.body"), cancelLabel: t("common.cancel"), continueLabel: t("modals.connectSettings.clearStorage.confirmation.clearButton"), onCancel: () => showPHModal({ type: "settings" }), onContinue: clearStorage, onOpenChange: (status) => {
            if (!status)
                return closePHModal();
        }, continueButtonProps: {
            disabled: loading,
        } }));
}
//# sourceMappingURL=ClearStorageModal.js.map