import { jsx as _jsx } from "react/jsx-runtime";
import { CreateDocumentModal as ConnectCreateDocumentModal } from "@powerhousedao/design-system";
import { addDocument, closePHModal, setSelectedNode, useDocumentModelModuleById, useParentFolderForSelectedNode, usePHModal, useSelectedDriveSafe, useSelectedFolder, } from "@powerhousedao/reactor-browser";
export const CreateDocumentModal = () => {
    const phModal = usePHModal();
    const open = phModal?.type === "createDocument";
    const documentType = open ? phModal.documentType : undefined;
    const documentModel = useDocumentModelModuleById(documentType);
    const [selectedDrive] = useSelectedDriveSafe();
    const selectedFolder = useSelectedFolder();
    const parentFolder = useParentFolderForSelectedNode();
    const onCreateDocument = async (documentName) => {
        closePHModal();
        if (!selectedDrive || !documentModel)
            return;
        const node = await addDocument(selectedDrive.header.id, documentName || `New ${documentModel.documentModel.global.name}`, documentModel.documentModel.global.id, selectedFolder?.id ?? parentFolder?.id);
        setSelectedNode(node);
    };
    return (_jsx(ConnectCreateDocumentModal, { open: open, onContinue: onCreateDocument, onOpenChange: (status) => {
            if (!status)
                return closePHModal();
        } }));
};
//# sourceMappingURL=CreateDocumentModal.js.map