import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
import useLexicalEditable from '@lexical/react/useLexicalEditable';
import { useDecorators } from '../shared/useDecorators';
import { useEditorFocus } from '../shared/useEditorFocus';
import { useCanShowPlaceholder } from '../shared/useCanShowPlaceholder';
import { useRichTextSetup } from '../shared/useRichTextSetup';
export function RichTextPlugin({ contentEditable, placeholder, ErrorBoundary }) {
    const [editor] = useLexicalComposerContext();
    const decorators = useDecorators(editor, ErrorBoundary);
    useRichTextSetup(editor);
    return (_jsxs(_Fragment, { children: [contentEditable, _jsx(Placeholder, { content: placeholder }), decorators] }));
}
function Placeholder({ content }) {
    const [editor] = useLexicalComposerContext();
    const showPlaceholder = useCanShowPlaceholder(editor);
    const editable = useLexicalEditable();
    const hasFocus = useEditorFocus();
    if (!showPlaceholder || hasFocus) {
        return null;
    }
    if (typeof content === 'function') {
        return content(editable);
    }
    else {
        return content;
    }
}
