import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { DriveEditorContainer, DriveIcon, } from "@powerhousedao/connect/components";
import { connectConfig, defaultPHDocumentEditorConfig, defaultPHDriveEditorConfig, } from "@powerhousedao/connect/config";
import { HomeScreen, HomeScreenAddDriveItem, HomeScreenItem, } from "@powerhousedao/design-system/connect";
import { setPHDocumentEditorConfig, setPHDriveEditorConfig, setSelectedDrive, useDriveEditorModuleById, useDrives, useSelectedDocumentId, useSelectedDriveSafe, useSelectedFolder, } from "@powerhousedao/reactor-browser";
import { useEffect } from "react";
export function Content() {
    const [selectedDrive] = useSelectedDriveSafe();
    const selectedFolder = useSelectedFolder();
    const selectedDocumentId = useSelectedDocumentId();
    useEffect(() => {
        if (!selectedDocumentId) {
            setPHDocumentEditorConfig(defaultPHDocumentEditorConfig);
        }
    }, [selectedDocumentId]);
    useEffect(() => {
        if (!selectedDrive) {
            setPHDriveEditorConfig(defaultPHDriveEditorConfig);
        }
    }, [selectedDrive]);
    const showHomeScreen = !selectedDocumentId && !selectedDrive && !selectedFolder;
    return (_jsx(ContentContainer, { children: showHomeScreen ? _jsx(HomeScreenContainer, {}) : _jsx(DriveEditorContainer, {}) }));
}
function ContentContainer({ children }) {
    return (_jsx("div", { className: "flex h-full flex-col overflow-auto", id: "content-view", children: children }));
}
function DriveItem({ drive }) {
    const editorModule = useDriveEditorModuleById(drive.header.meta?.preferredEditor);
    const description = editorModule?.name || "Drive Explorer App";
    return (_jsx(HomeScreenItem, { title: drive.state.global.name, description: description, icon: _jsx(DriveIcon, { drive: drive }), onClick: () => setSelectedDrive(drive) }, drive.header.id));
}
function HomeScreenContainer() {
    const drives = useDrives();
    const config = connectConfig;
    return (_jsxs(HomeScreen, { children: [drives?.map((drive) => {
                return _jsx(DriveItem, { drive: drive }, drive.header.id);
            }), config.drives.addDriveEnabled && _jsx(HomeScreenAddDriveItem, {})] }));
}
//# sourceMappingURL=content.js.map