import { t as defineConfigurableModule } from "./configurable-module-Bur4JaI3.js";
import { nestedDocNodes } from "./modules/nested-doc/node.mjs";
import { ColorSchemeProvider, NestedContentRendererProvider, useColorScheme, useOptionalNestedContentRenderer, useVariant } from "@haklex/rich-editor/static";
import { useCallback, useMemo } from "react";
import { jsx } from "react/jsx-runtime";
import { NestedDocPreviewCard, NestedDocRenderer } from "@haklex/rich-ext-nested-doc/static";
//#region src/modules/nested-doc/module-config.ts
var { createModule: createNestedDocModule, useConfig: useNestedDocConfig } = defineConfigurableModule({
	name: "nested-doc",
	defaultConfig: {}
});
//#endregion
//#region src/modules/nested-doc/renderer.tsx
var TITLE_MAX_LENGTH = 80;
function extractTitle(state) {
	const first = state.root?.children?.[0];
	if (!first) return "";
	const walk = (node) => {
		if (node.text) return node.text;
		if (node.children) return node.children.map(walk).join("");
		return "";
	};
	return walk(first).slice(0, TITLE_MAX_LENGTH);
}
var ComposedNestedDocStaticRenderer = ({ contentState }) => {
	const { onExpand } = useNestedDocConfig();
	const colorScheme = useColorScheme();
	const variant = useVariant();
	const renderNestedContent = useOptionalNestedContentRenderer();
	const title = useMemo(() => extractTitle(contentState), [contentState]);
	const handleActivate = useCallback((target) => {
		if (!onExpand) return;
		onExpand({
			contentState,
			title: title || void 0,
			content: /* @__PURE__ */ jsx(ColorSchemeProvider, {
				colorScheme,
				children: /* @__PURE__ */ jsx(NestedContentRendererProvider, {
					value: renderNestedContent,
					children: /* @__PURE__ */ jsx(NestedDocRenderer, {
						value: contentState,
						variant
					})
				})
			}),
			target
		});
	}, [
		onExpand,
		colorScheme,
		variant,
		renderNestedContent,
		contentState,
		title
	]);
	return /* @__PURE__ */ jsx(NestedDocPreviewCard, {
		contentState,
		onActivate: onExpand ? handleActivate : void 0
	});
};
//#endregion
//#region src/modules/nested-doc/module.ts
var NESTED_DOC_MODULE_NAME = "nested-doc";
var nestedDocModule = createNestedDocModule({
	nodes: nestedDocNodes,
	renderers: { NestedDoc: ComposedNestedDocStaticRenderer }
});
//#endregion
export { useNestedDocConfig as i, nestedDocModule as n, ComposedNestedDocStaticRenderer as r, NESTED_DOC_MODULE_NAME as t };
