export const generateAttachmentId = () => {
    const globalCrypto = typeof globalThis !== 'undefined'
        ? globalThis.crypto
        : undefined;
    if (globalCrypto?.randomUUID) {
        return globalCrypto.randomUUID();
    }
    return `attachment-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
};
export const readFileAsDataUrl = async (file) => {
    return await new Promise((resolve, reject) => {
        const reader = new FileReader();
        reader.onload = () => {
            if (typeof reader.result === 'string') {
                resolve(reader.result);
            }
            else {
                reject(new Error('Unexpected FileReader result type'));
            }
        };
        reader.onerror = () => {
            reject(reader.error ?? new Error('Failed to read attachment file.'));
        };
        reader.readAsDataURL(file);
    });
};
