/**
 * Generic formatting utilities shared across components.
 */
/** Extract explanation text from a rule result (works for both passed and failed) */
export function get_rule_explanation(rr) {
    if (rr.summary)
        return rr.summary;
    const first = rr.issues[0];
    if (first?.client_comment)
        return first.client_comment;
    if (first?.issue_description)
        return first.issue_description;
    if (rr.raw_response) {
        try {
            const parsed = JSON.parse(rr.raw_response.replace(/```(?:json)?\s*\n?/g, '').replace(/```/g, '').trim());
            return parsed.summary || parsed.description || parsed.reason;
        }
        catch {
            if (rr.raw_response.length <= 200)
                return rr.raw_response;
        }
    }
    return undefined;
}
/** Format file size in human-readable form */
export function format_file_size(bytes) {
    if (bytes < 1024)
        return `${bytes} B`;
    if (bytes < 1024 * 1024)
        return `${(bytes / 1024).toFixed(1)} KB`;
    return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}
/** Format a currency value with locale-aware formatting */
export function format_currency_value(value, locale = 'en-AU', currency_symbol = '$') {
    const formatted = value.toLocaleString(locale, {
        minimumFractionDigits: 2,
        maximumFractionDigits: 2,
    });
    return `${currency_symbol}${formatted}`;
}
/** Format an instance label from a date */
export function format_instance_label(date, locale = 'en-AU') {
    const d = date ?? new Date();
    return d.toLocaleDateString(locale, { day: '2-digit', month: 'short', year: 'numeric' });
}
/** Infer MIME type from file extension */
export function infer_mime_type(file_name) {
    const ext = file_name.split('.').pop()?.toLowerCase();
    switch (ext) {
        case 'pdf': return 'application/pdf';
        case 'png': return 'image/png';
        case 'jpg':
        case 'jpeg': return 'image/jpeg';
        case 'gif': return 'image/gif';
        case 'webp': return 'image/webp';
        case 'svg': return 'image/svg+xml';
        case 'doc': return 'application/msword';
        case 'docx': return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
        case 'xls': return 'application/vnd.ms-excel';
        case 'xlsx': return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
        case 'csv': return 'text/csv';
        case 'txt': return 'text/plain';
        default: return 'application/octet-stream';
    }
}
//# sourceMappingURL=format.js.map