import { jsx as _jsx } from "react/jsx-runtime";
import './StorageUsageBar.scss';
const convertToBytes = (value) => {
    if (typeof value === 'number')
        return value;
    const match = value.match(/([\d.]+)\s*(KB|MB|GB)/i);
    if (!match)
        return 0;
    const parsed = parseFloat(match[1] ?? '0');
    const unit = match[2]?.toUpperCase() || '';
    switch (unit) {
        case 'GB':
            return parsed * 1024 * 1024 * 1024;
        case 'MB':
            return parsed * 1024 * 1024;
        case 'KB':
            return parsed * 1024;
        default:
            return parsed;
    }
};
/**
 * Format bytes → readable string
 */
const formatStorage = (bytes) => {
    if (bytes >= 1024 * 1024 * 1024)
        return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
    if (bytes >= 1024 * 1024)
        return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
    if (bytes >= 1024)
        return `${(bytes / 1024).toFixed(2)} KB`;
    return `${bytes} B`;
};
/**
 * Calculate percentage safely
 */
const getPercent = (usedBytes, totalBytes) => totalBytes > 0 ? Math.min((usedBytes / totalBytes) * 100, 100) : 0;
const StorageUsageBar = ({ used, total, 
// unit = 'GB', // kept for compatibility (not used internally anymore)
showValue = true, width = '216px', }) => {
    const usedBytes = convertToBytes(used);
    const totalBytes = convertToBytes(total);
    const percent = getPercent(usedBytes, totalBytes);
    return (_jsx("div", { className: "ff-storage-bar", style: { width }, children: _jsx("div", { className: "ff-storage-bar__track", children: _jsx("div", { className: "ff-storage-bar__fill", style: { width: `${percent}%` }, children: showValue && (_jsx("span", { className: "ff-storage-bar__value", children: formatStorage(usedBytes) })) }) }) }));
};
export default StorageUsageBar;
//# sourceMappingURL=StorageUsageBar.js.map