'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const getUploaderTitle = ({ file, uploaderTitle, }) => {
    if (file && typeof file !== 'string') {
        return file.name;
    }
    return uploaderTitle;
};
const getUploaderDescription = ({ file, maxSizeDescription, }) => {
    if (file && typeof file !== 'string') {
        return `${(file.size / 1000).toFixed(2)}KB`;
    }
    return maxSizeDescription;
};
const getImageUrlFromFile = ({ file, fileId, }) => {
    if (!file) {
        return null;
    }
    else {
        const uploaderThumbnail = document.getElementById(fileId);
        if (uploaderThumbnail) {
            if (typeof file === 'string') {
                // File is a URL
                uploaderThumbnail.src = file;
            }
            else {
                // File type
                const reader = new FileReader();
                reader.onload = (e) => {
                    if (e.target && e.target.result) {
                        const imgUrl = e.target.result;
                        uploaderThumbnail.src = typeof imgUrl === 'string' ? imgUrl : '';
                    }
                };
                reader.readAsDataURL(file);
            }
        }
    }
};
const openFileExplorer = ({ file, errorMessage, inputId, }) => {
    if (!file || errorMessage) {
        const input = document.getElementById(inputId);
        if (input) {
            input.click();
        }
    }
};
const isImageFile = (file) => {
    if (typeof file === 'string' || !file) {
        return false;
    }
    switch (file.type) {
        case 'image/apng':
        case 'image/avif':
        case 'image/gif':
        case 'image/jpeg':
        case 'image/png':
        case 'image/svg+xml':
        case 'image/webp':
            return true;
        default:
            return false;
    }
};

exports.getImageUrlFromFile = getImageUrlFromFile;
exports.getUploaderDescription = getUploaderDescription;
exports.getUploaderTitle = getUploaderTitle;
exports.isImageFile = isImageFile;
exports.openFileExplorer = openFileExplorer;
