import { jsx } from "react/jsx-runtime";
import { Suspense, lazy } from "react";
import { Shimmer } from "@byline/ui/react";
let editorBundlePromise = null;
function loadEditorBundle() {
    if (!editorBundlePromise) editorBundlePromise = (async ()=>{
        const [richtextMod, defaultMod, extensionsMod, lodashMod] = await Promise.all([
            import("./richtext-field.js"),
            import("./field/config/default.js"),
            import("./field/config/default-extensions.js"),
            import("lodash-es")
        ]);
        return {
            RichTextField: richtextMod.RichTextField,
            defaultEditorConfig: defaultMod.defaultEditorConfig,
            defaultExtensionsList: extensionsMod.defaultExtensionsList,
            cloneDeep: lodashMod.cloneDeep
        };
    })();
    return editorBundlePromise;
}
function lexicalEditor(configure) {
    const Lazy = /*#__PURE__*/ lazy(async ()=>{
        const { RichTextField, defaultEditorConfig, defaultExtensionsList, cloneDeep } = await loadEditorBundle();
        let baked;
        if (configure) {
            const seed = {
                ...cloneDeep(defaultEditorConfig),
                extensions: defaultExtensionsList()
            };
            baked = configure(seed);
        }
        const Configured = (props)=>/*#__PURE__*/ jsx(RichTextField, {
                ...props,
                editorConfig: baked
            });
        return {
            default: Configured
        };
    });
    const ConfiguredEditor = (props)=>/*#__PURE__*/ jsx(Suspense, {
            fallback: /*#__PURE__*/ jsx(EditorPlaceholder, {}),
            children: /*#__PURE__*/ jsx(Lazy, {
                ...props
            })
        });
    return ConfiguredEditor;
}
function EditorPlaceholder() {
    return /*#__PURE__*/ jsx("div", {
        className: "byline-field-richtext",
        children: /*#__PURE__*/ jsx("div", {
            className: "byline-field-richtext-body",
            children: /*#__PURE__*/ jsx(Shimmer, {
                height: "35vh"
            })
        })
    });
}
export { lexicalEditor };
