"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useCanShowPlaceholder = void 0;
const text_1 = require("@lexical/text");
const utils_1 = require("@lexical/utils");
const react_1 = require("react");
const react_core_1 = require("@selfcommunity/react-core");
function canShowPlaceholderFromCurrentEditorState(editor) {
    return editor.getEditorState().read((0, text_1.$canShowPlaceholderCurry)(editor.isComposing()));
}
function useCanShowPlaceholder(editor) {
    const [canShowPlaceholder, setCanShowPlaceholder] = (0, react_1.useState)(() => canShowPlaceholderFromCurrentEditorState(editor));
    (0, react_core_1.useIsomorphicLayoutEffect)(() => {
        function resetCanShowPlaceholder() {
            const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
            setCanShowPlaceholder(currentCanShowPlaceholder);
        }
        resetCanShowPlaceholder();
        return (0, utils_1.mergeRegister)(editor.registerUpdateListener(() => {
            resetCanShowPlaceholder();
        }), editor.registerEditableListener(() => {
            resetCanShowPlaceholder();
        }));
    }, [editor]);
    return canShowPlaceholder;
}
exports.useCanShowPlaceholder = useCanShowPlaceholder;
