import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useUserSession } from "@vertesia/ui/session";
import { Popover } from "@vertesia/ui/widgets";
import { CloudDownload } from "lucide-react";
import { getResourceUrl } from "./PdfPageProvider";
export function DownloadPopover({ object }) {
    const { client } = useUserSession();
    const onDownload = (name) => {
        getResourceUrl(client, object.id, name).then(url => window.open(url, '_blank'));
    };
    const getProcessorType = () => {
        if (object.metadata?.type === "document") {
            const docMetadata = object.metadata;
            return docMetadata.content_processor?.type || "xml";
        }
        return "xml"; // default
    };
    const processorType = getProcessorType();
    const renderDownloadOptions = () => {
        if (processorType === "markdown") {
            return (_jsx("button", { className: "p-2 cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-100", onClick: () => onDownload("document.md"), children: "document.md" }));
        }
        // Default XML processor options
        return (_jsxs(_Fragment, { children: [_jsx("button", { className: "p-2 cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-100", onClick: () => onDownload("annotated.pdf"), children: "annotated.pdf" }), _jsx("button", { className: "p-2 cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-100", onClick: () => onDownload("document.xml"), children: "document.xml" }), _jsx("button", { className: "p-2 cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-100", onClick: () => onDownload("analyzed-pages.json"), children: "analyzed-pages.json" })] }));
    };
    return (_jsx("div", { className: "absolute bottom-[58px] right-[20px] w-[36px] h-[36px] cursor-pointer text-indigo-400 border-indigo-400 hover:border-indigo-500 hover:text-indigo-500 border-2 rounded-full shadow-xs flex items-center justify-center", children: _jsxs(Popover, { strategy: 'absolute', placement: 'top-end', zIndex: 100, offset: 20, children: [_jsx(Popover.Trigger, { click: true, children: _jsx(CloudDownload, { className: 'size-6' }) }), _jsx(Popover.Content, { children: _jsx("div", { className: "rounded-md shadow-md border border-gray-100 bg-white dark:bg-slate-50 dark:border-slate-100 min-w-[200px] flex flex-col divide-y", children: renderDownloadOptions() }) })] }) }));
}
//# sourceMappingURL=DownloadPopover.js.map