const DEFAULT_WORK_PERCENT = 100;
function to_number(v, fallback = 0) {
    if (typeof v === 'number' && Number.isFinite(v))
        return v;
    if (typeof v === 'string' && v.trim() !== '') {
        const n = Number(v);
        return Number.isFinite(n) ? n : fallback;
    }
    return fallback;
}
export function clamp_work_percent(v, fallback = DEFAULT_WORK_PERCENT) {
    const n = to_number(v, fallback);
    const clamped = Math.max(0, Math.min(100, n));
    return Math.round(clamped);
}
export function is_split_value(v) {
    if (!v || typeof v !== 'object')
        return false;
    const obj = v;
    return 'total' in obj && typeof obj.total === 'number' && Number.isFinite(obj.total);
}
export function parse_split_value(v, default_work_percent = DEFAULT_WORK_PERCENT) {
    if (v === null || v === undefined || v === '') {
        return { total: 0, work_percent: default_work_percent };
    }
    // Check for object-like shape with a 'total' property (may need coercion)
    if (v && typeof v === 'object' && 'total' in v) {
        const obj = v;
        const total = to_number(obj.total, 0);
        const has_wp = 'work_percent' in obj && obj.work_percent !== undefined && obj.work_percent !== null;
        const work_percent = has_wp
            ? clamp_work_percent(obj.work_percent, default_work_percent)
            : default_work_percent;
        return { total, work_percent };
    }
    return { total: to_number(v, 0), work_percent: default_work_percent };
}
export function compute_deductible(value) {
    const raw = value.total * (value.work_percent / 100);
    return parseFloat(raw.toFixed(2));
}
//# sourceMappingURL=split_amount.js.map