import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { GenericDriveExplorer } from "@powerhousedao/common";
import { DropZoneWrapper } from "@powerhousedao/design-system";
import { useDefaultDriveEditorModule, useDriveEditorModuleById, useSelectedDocument, useSelectedDrive, } from "@powerhousedao/reactor-browser";
import { ErrorBoundary } from "react-error-boundary";
import { DocumentEditorContainer } from "./document-editor-container.js";
function DriveEditorError({ error }) {
    return (_jsxs("div", { className: "mx-auto flex max-w-[80%] flex-1 flex-col items-center justify-center", children: [_jsx("h1", { className: "mb-2 text-xl font-semibold", children: "Error" }), _jsx("i", { children: error instanceof Error ? error.message : error }), _jsx("pre", { children: JSON.stringify(error, null, 2) })] }));
}
export function DriveEditorContainer() {
    const [selectedDrive] = useSelectedDrive();
    const [selectedDocument] = useSelectedDocument();
    const driveEditor = useDriveEditorModuleById(selectedDrive?.header.meta?.preferredEditor);
    const defaultDriveEditor = useDefaultDriveEditorModule();
    const DriveEditorComponent = driveEditor?.Component ??
        defaultDriveEditor?.Component ??
        GenericDriveExplorer.Component;
    return (_jsx(ErrorBoundary, { fallbackRender: DriveEditorError, children: _jsx(DropZoneWrapper, { className: "flex h-full flex-col overflow-auto", children: _jsx(DriveEditorComponent, { children: selectedDocument ? _jsx(DocumentEditorContainer, {}) : null }) }) }, selectedDrive.header.id));
}
//# sourceMappingURL=drive-editor-container.js.map