import { jsx as _jsx } from "react/jsx-runtime";
import { audioBlockConfig, audioParse } from "@endexai/blocknote-core";
import { RiVolumeUpFill } 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 { FileBlockWrapper } from "../FileBlockContent/helpers/render/FileBlockWrapper.js";
import { LinkWithCaption } from "../FileBlockContent/helpers/toExternalHTML/LinkWithCaption.js";
export const AudioPreview = (props) => {
    const resolved = useResolveUrl(props.block.props.url);
    return (_jsx("audio", { className: "bn-audio", src: resolved.loadingState === "loading"
            ? props.block.props.url
            : resolved.downloadUrl, controls: true, contentEditable: false, draggable: false }));
};
export const AudioToExternalHTML = (props) => {
    if (!props.block.props.url) {
        return _jsx("p", { children: "Add audio" });
    }
    const audio = props.block.props.showPreview ? (_jsx("audio", { 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: audio })) : (_jsx(LinkWithCaption, { caption: props.block.props.caption, children: audio }));
    }
    return audio;
};
export const AudioBlock = (props) => {
    return (_jsx(FileBlockWrapper, { ...props, buttonText: props.editor.dictionary.file_blocks.audio.add_button_text, buttonIcon: _jsx(RiVolumeUpFill, { size: 24 }), children: _jsx(AudioPreview, { ...props }) }));
};
export const ReactAudioBlock = createReactBlockSpec(audioBlockConfig, {
    render: AudioBlock,
    parse: audioParse,
    toExternalHTML: AudioToExternalHTML,
});
//# sourceMappingURL=AudioBlockContent.js.map