// JS interop helper used by Blazor Server components to push a generated
// file (PDF / image) to the browser as a download. The bytes come over
// the SignalR circuit as base64 because that's the simplest payload that
// crosses the boundary cleanly.
window.selectpdfDownload = (filename, contentType, base64) => {
    const binary = atob(base64);
    const bytes = new Uint8Array(binary.length);
    for (let i = 0; i < binary.length; i++) {
        bytes[i] = binary.charCodeAt(i);
    }
    const blob = new Blob([bytes], { type: contentType });
    const url = URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = filename;
    document.body.appendChild(a);
    a.click();
    setTimeout(() => {
        URL.revokeObjectURL(url);
        a.remove();
    }, 0);
};
