export type RateType = 'HOURLY' | 'DAILY' | 'WEEKLY' | 'MONTHLY';

export const RATE_TYPE_OPTIONS: { value: RateType; label: string; short: string }[] = [
  { value: 'HOURLY', label: 'Per hour', short: 'hr' },
  { value: 'DAILY', label: 'Per day', short: 'day' },
  { value: 'WEEKLY', label: 'Per week', short: 'wk' },
  { value: 'MONTHLY', label: 'Per month', short: 'mo' },
];

export function getRateTypeLabel(rateType?: RateType | string | null): string {
  return RATE_TYPE_OPTIONS.find((o) => o.value === rateType)?.label ?? 'Per hour';
}

export function getRateTypeShort(rateType?: RateType | string | null): string {
  return RATE_TYPE_OPTIONS.find((o) => o.value === rateType)?.short ?? 'hr';
}

export function formatWorkerRate(
  amount: number | string | null | undefined,
  rateType?: RateType | string | null
): string | null {
  if (amount == null || amount === '') return null;
  const num = Number(amount);
  if (Number.isNaN(num)) return null;
  const formatted = new Intl.NumberFormat('en-PH', {
    style: 'currency',
    currency: 'PHP',
    minimumFractionDigits: 0,
    maximumFractionDigits: 0,
  }).format(num);
  return `${formatted}/${getRateTypeShort(rateType)}`;
}
