import { useMemo } from 'react';
export const useDownloadInfo = ({ downloadUrls, defaultFileName, }) => {
    return useMemo(() => {
        if (downloadUrls) {
            return downloadUrls.map(({ title, url }) => ({
                url,
                title: title || getFileNameFromUrl(url, defaultFileName || 'openapi.yaml'),
                iconType: getIconTypeFromUrl(url),
            }));
        }
    }, [downloadUrls, defaultFileName]);
};
function getFileNameFromUrl(url, defaultValue) {
    const filename = url
        .split('?')[0]
        .split(/[\\\/]/) // handle backslash for Windows system
        .pop();
    if (!filename || (!filename.includes('yaml') && !filename.includes('json'))) {
        return defaultValue;
    }
    else {
        return filename;
    }
}
function getIconTypeFromUrl(url, title) {
    const filename = title ||
        url
            .split('?')[0]
            .split(/[\\\/]/) // handle backslash for Windows system
            .pop();
    if (!filename) {
        return 'file';
    }
    if (filename.includes('yaml')) {
        return 'yaml';
    }
    else if (filename.includes('json')) {
        return 'json';
    }
    return 'file';
}
//# sourceMappingURL=useDownloadInfo.js.map