"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const postMessage_1 = require("../../common/postMessage.js");
const useMainEditorStore_1 = require("./useMainEditorStore.js");
const usePostMessageEvents_1 = require("./usePostMessageEvents.js");
const useMainEditorInitialize = (content) => {
    const { requestPostMessage } = (0, usePostMessageEvents_1.usePostMessageEvents)();
    const { initialize, setConfig, setContent } = (0, useMainEditorStore_1.useMainEditorStore)();
    (0, postMessage_1.usePostMessageAPIListener)('ON_INIT', () => {
        initialize();
        requestPostMessage('GET_SUPPORTED_BLOCKS', {});
        if (!content) {
            requestPostMessage('GET_INITIAL_CONTENT', {});
        }
    }, [requestPostMessage]);
    React.useEffect(() => {
        if (content) {
            setContent(content, true);
        }
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [content]);
    (0, postMessage_1.usePostMessageAPIListener)('ON_INITIAL_CONTENT', (data) => {
        setContent(data, true);
    });
    (0, postMessage_1.usePostMessageAPIListener)('ON_SUPPORTED_BLOCKS', (data) => {
        setConfig(data);
    });
};
exports.default = useMainEditorInitialize;
//# sourceMappingURL=useMainEditorInitialize.js.map
