import {useEffect} from "react";
import {getDelay} from "../utils";

type EditorCallback = (editor: any) => void;

/**
 * @global {AppWindow} window
 */
export const useTinyMCE = (editorCallback: EditorCallback) => 
{
    const appWindow = window as AppWindow;
    useEffect(() => {
        (async () => {
            const editorCount = appWindow?.tinymce?.editors?.length;
            if (!editorCount) {
                await getDelay(2000);
            }
            appWindow?.tinymce?.editors?.forEach(editorCallback);
        })();
    }, []);
};

