import { jsx as _jsx } from "react/jsx-runtime";
import { videoBlockConfig, videoParse } from "@endexai/blocknote-core";
import { RiVideoFill } from "react-icons/ri";
import { createReactBlockSpec, } from "../../schema/ReactBlockSpec.js";
import { useResolveUrl } from "../FileBlockContent/useResolveUrl.js";
import { FigureWithCaption } from "../FileBlockContent/helpers/toExternalHTML/FigureWithCaption.js";
import { ResizableFileBlockWrapper } from "../FileBlockContent/helpers/render/ResizableFileBlockWrapper.js";
import { LinkWithCaption } from "../FileBlockContent/helpers/toExternalHTML/LinkWithCaption.js";
export const VideoPreview = (props) => {
    const resolved = useResolveUrl(props.block.props.url);
    return (_jsx("video", { className: "bn-visual-media", src: resolved.loadingState === "loading"
            ? props.block.props.url
            : resolved.downloadUrl, controls: true, contentEditable: false, draggable: false }));
};
export const VideoToExternalHTML = (props) => {
    if (!props.block.props.url) {
        return _jsx("p", { children: "Add video" });
    }
    const video = props.block.props.showPreview ? (_jsx("video", { src: props.block.props.url })) : (_jsx("a", { href: props.block.props.url, children: props.block.props.name || props.block.props.url }));
    if (props.block.props.caption) {
        return props.block.props.showPreview ? (_jsx(FigureWithCaption, { caption: props.block.props.caption, children: video })) : (_jsx(LinkWithCaption, { caption: props.block.props.caption, children: video }));
    }
    return video;
};
export const VideoBlock = (props) => {
    return (_jsx(ResizableFileBlockWrapper, { ...props, buttonText: props.editor.dictionary.file_blocks.video.add_button_text, buttonIcon: _jsx(RiVideoFill, { size: 24 }), children: _jsx(VideoPreview, { ...props }) }));
};
export const ReactVideoBlock = createReactBlockSpec(videoBlockConfig, {
    render: VideoBlock,
    parse: videoParse,
    toExternalHTML: VideoToExternalHTML,
});
//# sourceMappingURL=VideoBlockContent.js.map