import type { PayPeriodLabel } from "src/modules/timesheets/models/ui.models";

export const formatPayPeriodLabel = (
    raw_label: string | undefined,
    locale: string,
    extractDate: (_input: string, _mask: string) => Date,
    opts: Intl.DateTimeFormatOptions
): PayPeriodLabel => {
    const label = raw_label ?? '';
    const dates = label.split('.');
    if(dates.length < 2) return { start_date: '—', end_date:'—' };

    const fmt   = new Intl.DateTimeFormat(locale, opts);
    const start = fmt.format(extractDate(dates[0]!, 'YYYY-MM-DD'));
    const end   = fmt.format(extractDate(dates[1]!, 'YYYY-MM-DD'));
    return { start_date: start, end_date: end };
}