// #region Imports
// #endregion
/**
 * Creates a typed {@link ThumbnailPreview} from a {@link File}.
 * Falls back to an 'other' preview if the media type cannot be determined.
 *
 * Note: The returned preview will use an Object URL. Call {@link URL.revokeObjectURL}
 * when you no longer need it to avoid memory leaks.
 *
 * @public
 */
export function createThumbnailPreviewFromFile(file) {
    const mime = (file.type || '').toLowerCase();
    const url = URL.createObjectURL(file);
    if (mime.startsWith('image/')) {
        const preview = {
            type: 'image',
            url,
            alt: file.name
        };
        return preview;
    }
    if (mime.startsWith('video/')) {
        const preview = {
            type: 'video',
            url
        };
        return preview;
    }
    if (mime.startsWith('audio/')) {
        const preview = {
            type: 'audio',
            url
        };
        return preview;
    }
    // Fallback by extension when MIME is missing or generic
    const ext = extractExtension(file.name);
    if (isImageExt(ext)) {
        const preview = {
            type: 'image',
            url,
            alt: file.name
        };
        return preview;
    }
    if (isVideoExt(ext)) {
        const preview = {
            type: 'video',
            url
        };
        return preview;
    }
    if (isAudioExt(ext)) {
        const preview = {
            type: 'audio',
            url
        };
        return preview;
    }
    const fallback = { type: 'other' };
    return fallback;
}
// #region Helpers
function extractExtension(name) {
    const idx = name.lastIndexOf('.');
    return idx >= 0 ? name.slice(idx + 1).toLowerCase() : '';
}
function isImageExt(ext) {
    return ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'svg', 'avif', 'heif', 'heic'].includes(ext);
}
function isVideoExt(ext) {
    return ['mp4', 'webm', 'ogg', 'ogv', 'mov', 'm4v', 'avi', 'mkv'].includes(ext);
}
function isAudioExt(ext) {
    return ['mp3', 'wav', 'ogg', 'oga', 'm4a', 'aac', 'flac'].includes(ext);
}
// #endregion
//# sourceMappingURL=ThumbnailPreviewFactory.js.map