import { $canShowPlaceholderCurry } from '@lexical/text';
import { mergeRegister } from '@lexical/utils';
import { useState } from 'react';
import { useIsomorphicLayoutEffect } from '@selfcommunity/react-core';
function canShowPlaceholderFromCurrentEditorState(editor) {
    return editor.getEditorState().read($canShowPlaceholderCurry(editor.isComposing()));
}
export function useCanShowPlaceholder(editor) {
    const [canShowPlaceholder, setCanShowPlaceholder] = useState(() => canShowPlaceholderFromCurrentEditorState(editor));
    useIsomorphicLayoutEffect(() => {
        function resetCanShowPlaceholder() {
            const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
            setCanShowPlaceholder(currentCanShowPlaceholder);
        }
        resetCanShowPlaceholder();
        return mergeRegister(editor.registerUpdateListener(() => {
            resetCanShowPlaceholder();
        }), editor.registerEditableListener(() => {
            resetCanShowPlaceholder();
        }));
    }, [editor]);
    return canShowPlaceholder;
}
