import { jsx } from "react/jsx-runtime";
import { BlockWithAlignableContents } from "@lexical/react/LexicalBlockWithAlignableContents";
import { DecoratorBlockNode } from "@lexical/react/LexicalDecoratorBlockNode";
function VimeoComponent({ className, format, nodeKey, videoID }) {
    return /*#__PURE__*/ jsx(BlockWithAlignableContents, {
        className: className,
        format: format,
        nodeKey: nodeKey,
        children: /*#__PURE__*/ jsx("iframe", {
            style: {
                aspectRatio: '16 / 9',
                width: '100%'
            },
            src: `https://player.vimeo.com/video/${videoID}`,
            allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",
            allowFullScreen: true,
            title: "Vimeo Video"
        })
    });
}
function convertVimeoElement(domNode) {
    const videoID = domNode.getAttribute('data-lexical-vimeo');
    if (null != videoID) {
        const node = $createVimeoNode(videoID);
        return {
            node
        };
    }
    return null;
}
class VimeoNode extends DecoratorBlockNode {
    static getType() {
        return 'vimeo';
    }
    static clone(node) {
        return new VimeoNode(node.__id, node.__format, node.__key);
    }
    static importJSON(serializedNode) {
        const node = $createVimeoNode(serializedNode.videoID);
        node.setFormat(serializedNode.format);
        return node;
    }
    exportJSON() {
        return {
            ...super.exportJSON(),
            type: 'vimeo',
            version: 1,
            videoID: this.__id
        };
    }
    exportDOM() {
        const element = document.createElement('iframe');
        element.setAttribute('data-lexical-vimeo', this.__id);
        element.setAttribute('width', '560');
        element.setAttribute('height', '315');
        element.setAttribute('src', `https://player.vimeo.com/video/${this.__id}`);
        element.setAttribute('frameborder', '0');
        element.setAttribute('allow', 'autoplay; fullscreen; picture-in-picture"');
        element.setAttribute('allowfullscreen', 'true');
        element.setAttribute('title', 'Vimeo video');
        return {
            element
        };
    }
    static importDOM() {
        return {
            iframe: (domNode)=>{
                if (!domNode.hasAttribute('data-lexical-vimeo')) return null;
                return {
                    conversion: convertVimeoElement,
                    priority: 1
                };
            }
        };
    }
    updateDOM() {
        return false;
    }
    getId() {
        return this.__id;
    }
    getTextContent(_includeInert, _includeDirectionless) {
        return `https://vimeo.com/${this.__id}`;
    }
    decorate(_editor, config) {
        const embedBlockTheme = config.theme.embedBlock ?? {};
        const className = {
            base: embedBlockTheme.base ?? '',
            focus: embedBlockTheme.focus ?? ''
        };
        return /*#__PURE__*/ jsx(VimeoComponent, {
            className: className,
            format: this.__format,
            nodeKey: this.getKey(),
            videoID: this.__id
        });
    }
    constructor(id, format, key){
        super(format, key);
        this.__id = id;
    }
}
function $createVimeoNode(videoID) {
    return new VimeoNode(videoID);
}
function $isVimeoNode(node) {
    return node instanceof VimeoNode;
}
export { $createVimeoNode, $isVimeoNode, VimeoNode };
