"use client";
import { jsx } from "react/jsx-runtime";
import { createContext, useCallback, useContext, useMemo, useState } from "react";
import { DEFAULT_EDITOR_SETTINGS } from "./default.js";
function generateQuickGuid() {
    return Math.random().toString(36).substring(2, 12) + Math.random().toString(36).substring(2, 12);
}
const Context = /*#__PURE__*/ createContext({
    setOption: (_name, _value)=>{},
    config: DEFAULT_EDITOR_SETTINGS,
    uuid: generateQuickGuid()
});
const EditorConfigContext = ({ children, config: configFromProps })=>{
    const [config, setConfig] = useState(configFromProps ?? DEFAULT_EDITOR_SETTINGS);
    const [uuid] = useState(()=>generateQuickGuid());
    const setOption = useCallback((option, value)=>{
        setConfig((config)=>{
            const options = {
                ...config.options,
                [option]: value
            };
            return {
                ...config,
                options
            };
        });
    }, []);
    const editorContext = useMemo(()=>({
            setOption,
            config,
            uuid
        }), [
        setOption,
        config,
        uuid
    ]);
    return /*#__PURE__*/ jsx(Context.Provider, {
        value: editorContext,
        children: children
    });
};
const useEditorConfig = ()=>{
    const context = useContext(Context);
    if (void 0 === context) throw new Error('useEditorConfig must be used within an EditorConfigContext');
    return context;
};
export { EditorConfigContext, useEditorConfig };
