"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 { $createVimeoNode, VimeoNode } from "../../nodes/vimeo-node/index.js";
const INSERT_VIMEO_COMMAND = createCommand('INSERT_VIMEO_COMMAND');
function VimeoPlugin() {
    const [editor] = useLexicalComposerContext();
    useEffect(()=>{
        if (!editor.hasNodes([
            VimeoNode
        ])) throw new Error('VimeoPlugin: VimeoNode not registered on editor');
        return editor.registerCommand(INSERT_VIMEO_COMMAND, (payload)=>{
            const vimeoNode = $createVimeoNode(payload);
            $insertNodeToNearestRoot(vimeoNode);
            return true;
        }, COMMAND_PRIORITY_EDITOR);
    }, [
        editor
    ]);
    return null;
}
export { INSERT_VIMEO_COMMAND, VimeoPlugin };
