import type {RewardStatus} from '@/lib/api/contracts';

/**
 * Reward status → badge treatment.
 *
 * Only `expiring` and `expired` carry colour. An active reward is the normal
 * case and a paused one is a deliberate choice by the merchant — neither
 * needs attention. Colouring all four would leave nothing standing out on a
 * page whose entire job is surfacing the ones about to lapse.
 */
export const REWARD_STATUS: Record<
  RewardStatus,
  {label: string; variant: 'neutral' | 'warning' | 'error'}
> = {
  active: {label: 'Active', variant: 'neutral'},
  paused: {label: 'Paused', variant: 'neutral'},
  expiring: {label: 'Expiring', variant: 'warning'},
  expired: {label: 'Expired', variant: 'error'},
};

/** Whole days until expiry; negative once lapsed, null if it never expires. */
export function daysUntil(expiresAt: string | null, nowMs: number): number | null {
  if (!expiresAt) return null;
  return Math.ceil((new Date(expiresAt).getTime() - nowMs) / 86400000);
}

export function usageRate(claimed: number, used: number): number {
  return claimed === 0 ? 0 : Number(((used / claimed) * 100).toFixed(1));
}
