import { a as FolderItem, h as useWindowSize, i as FileItem, m as PowerhouseButton, o as useVirtualizer } from "./connect-BMrgEG7X.js";
import { C as twMerge } from "./dist-D8H48e8N.js";
import { O as useUserPermissions, i as isFolderNodeKind, r as isFileNodeKind, s as showCreateDocumentModal, u as useDocumentModelModules, v as useNodesInSelectedDriveOrFolder } from "./dist-B6zWOl4d.js";
import React, { useRef } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
//#region editors/generic-drive-explorer/components/create-document.tsx
function getDocumentSpec(doc) {
	return doc.documentModel.global;
}
function CreateDocument() {
	const { isAllowedToCreateDocuments } = useUserPermissions();
	const nonDriveDocumentModelModules = useDocumentModelModules()?.filter((module) => module.documentModel.global.id !== "powerhouse/document-drive");
	if (!isAllowedToCreateDocuments) return null;
	return /* @__PURE__ */ jsxs("div", {
		className: "px-6 py-4",
		children: [/* @__PURE__ */ jsx("h3", {
			className: "mb-3 text-xl font-bold text-gray-700 dark:text-slate-200",
			children: "New document"
		}), /* @__PURE__ */ jsx("div", {
			className: "flex w-full flex-wrap gap-4",
			children: nonDriveDocumentModelModules?.map((doc) => {
				const spec = getDocumentSpec(doc);
				const versionLabel = doc.version ? ` v${doc.version}` : "";
				return /* @__PURE__ */ jsx(PowerhouseButton, {
					color: "light",
					title: `${spec.name}${versionLabel}`,
					"aria-description": spec.description,
					onClick: () => showCreateDocumentModal(spec.id),
					children: /* @__PURE__ */ jsxs("span", {
						className: "text-sm",
						children: [spec.name, versionLabel]
					})
				}, `${spec.id}-v${doc.version ?? 1}`);
			})
		})]
	});
}
//#endregion
//#region editors/generic-drive-explorer/components/file-content-view.tsx
const GAP = 8;
const ITEM_WIDTH = 256;
const ITEM_HEIGHT = 48;
const USED_SPACE = 420;
function FileContentView() {
	const parentRef = useRef(null);
	const availableWidth = useWindowSize().innerWidth - USED_SPACE;
	const fileNodes = useNodesInSelectedDriveOrFolder().filter((n) => isFileNodeKind(n));
	const columnCount = Math.floor(availableWidth / (ITEM_WIDTH + GAP)) || 1;
	const rowVirtualizer = useVirtualizer({
		count: Math.ceil(fileNodes.length / columnCount),
		getScrollElement: () => parentRef.current,
		estimateSize: (index) => {
			if (index > 0) return ITEM_HEIGHT + GAP;
			return ITEM_HEIGHT;
		},
		overscan: 5
	});
	const columnVirtualizer = useVirtualizer({
		horizontal: true,
		count: columnCount,
		getScrollElement: () => parentRef.current,
		estimateSize: (index) => {
			if (index > 0) return ITEM_WIDTH + GAP;
			return ITEM_WIDTH;
		},
		overscan: 5
	});
	const getItemIndex = (rowIndex, columnIndex) => rowIndex * columnCount + columnIndex;
	const getItem = (rowIndex, columnIndex) => {
		return fileNodes[getItemIndex(rowIndex, columnIndex)] || null;
	};
	if (fileNodes.length === 0) return /* @__PURE__ */ jsx("div", {
		className: "mb-8 text-sm text-gray-400 dark:text-slate-200",
		children: "No documents or files 📄"
	});
	const renderItem = (rowIndex, columnIndex) => {
		const fileNode = getItem(rowIndex, columnIndex);
		if (!fileNode) return null;
		return /* @__PURE__ */ jsx("div", {
			style: { marginLeft: columnIndex === 0 ? 0 : GAP },
			children: /* @__PURE__ */ jsx(FileItem, { fileNode }, fileNode.id)
		});
	};
	return /* @__PURE__ */ jsx("div", {
		ref: parentRef,
		style: {
			width: `100%`,
			overflow: "auto"
		},
		children: /* @__PURE__ */ jsx("div", {
			style: {
				height: `${rowVirtualizer.getTotalSize()}px`,
				width: `${columnVirtualizer.getTotalSize()}px`,
				position: "relative"
			},
			children: rowVirtualizer.getVirtualItems().map((virtualRow) => /* @__PURE__ */ jsx(React.Fragment, { children: columnVirtualizer.getVirtualItems().map((virtualColumn) => /* @__PURE__ */ jsx("div", {
				style: {
					position: "absolute",
					top: 0,
					left: 0,
					marginTop: virtualRow.index === 0 ? 0 : GAP,
					width: `${virtualColumn.size}px`,
					height: `${ITEM_HEIGHT}px`,
					overflow: "hidden",
					transform: `translateX(${virtualColumn.start}px) translateY(${virtualRow.start}px)`
				},
				children: renderItem(virtualRow.index, virtualColumn.index)
			}, virtualColumn.key)) }, virtualRow.key))
		})
	});
}
//#endregion
//#region editors/generic-drive-explorer/components/layout.tsx
function DriveLayout({ children, className, ...props }) {
	return /* @__PURE__ */ jsx(DriveLayout.Container, {
		className,
		...props,
		children
	});
}
DriveLayout.Container = function DriveLayoutContainer({ children, className, containerProps, ...props }) {
	return /* @__PURE__ */ jsx("div", {
		className: twMerge("flex grow flex-col overflow-auto", className),
		...containerProps,
		...props,
		children
	});
};
DriveLayout.Header = function DriveLayoutHeader({ children, className, containerProps, ...props }) {
	return /* @__PURE__ */ jsx("div", {
		className: twMerge("flex-0", className),
		...containerProps,
		...props,
		children
	});
};
DriveLayout.Content = function DriveLayoutContent({ children, className, containerProps, ...props }) {
	return /* @__PURE__ */ jsx("div", {
		className: twMerge("mb-5 flex-1 px-4", className),
		...containerProps,
		...props,
		children
	});
};
DriveLayout.ContentSection = function DriveLayoutContentSection({ title, children, className, containerProps, ...props }) {
	return /* @__PURE__ */ jsxs("div", {
		className: twMerge(className),
		...containerProps,
		...props,
		children: [title && /* @__PURE__ */ jsx("div", {
			className: "mb-4 text-base font-semibold text-gray-700 dark:text-slate-200",
			children: title
		}), /* @__PURE__ */ jsx("div", {
			className: "flex flex-wrap gap-2",
			children
		})]
	});
};
DriveLayout.Footer = function DriveLayoutFooter({ children, className, containerProps, ...props }) {
	return /* @__PURE__ */ jsx("div", {
		className: twMerge("flex-0", className),
		...containerProps,
		...props,
		children
	});
};
//#endregion
//#region editors/generic-drive-explorer/components/folder-view.tsx
function FolderView(props) {
	const { className } = props;
	const folderNodes = useNodesInSelectedDriveOrFolder().filter((n) => isFolderNodeKind(n));
	return /* @__PURE__ */ jsxs("div", {
		className: twMerge("rounded-md border-2 border-transparent p-2", className),
		children: [/* @__PURE__ */ jsx(DriveLayout.ContentSection, {
			title: "Folders",
			className: "mb-4",
			children: folderNodes.length > 0 ? folderNodes.map((folderNode) => /* @__PURE__ */ jsx(FolderItem, { folderNode }, folderNode.id)) : /* @__PURE__ */ jsx("div", {
				className: "mb-8 text-sm text-gray-400 dark:text-slate-200",
				children: "No documents or files 📄"
			})
		}), /* @__PURE__ */ jsx(DriveLayout.ContentSection, {
			title: "Documents and files",
			children: /* @__PURE__ */ jsx("div", {
				className: "w-full",
				children: /* @__PURE__ */ jsx(FileContentView, {})
			})
		})]
	});
}
//#endregion
export { CreateDocument as i, DriveLayout as n, FileContentView as r, FolderView as t };

//# sourceMappingURL=folder-view-D9jBl4kJ.js.map