"use client";
import { useEffect } from "react";
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
import { $insertNodeToNearestRoot } from "@lexical/utils";
import { COMMAND_PRIORITY_EDITOR, createCommand } from "lexical";
import { $createYouTubeNode, YouTubeNode } from "../../nodes/youtube-node/index.js";
const INSERT_YOUTUBE_COMMAND = createCommand('INSERT_YOUTUBE_COMMAND');
function YouTubePlugin() {
    const [editor] = useLexicalComposerContext();
    useEffect(()=>{
        if (!editor.hasNodes([
            YouTubeNode
        ])) throw new Error('YouTubePlugin: YouTubeNode not registered on editor');
        return editor.registerCommand(INSERT_YOUTUBE_COMMAND, (payload)=>{
            const youTubeNode = $createYouTubeNode(payload);
            $insertNodeToNearestRoot(youTubeNode);
            return true;
        }, COMMAND_PRIORITY_EDITOR);
    }, [
        editor
    ]);
    return null;
}
export { INSERT_YOUTUBE_COMMAND, YouTubePlugin };
