import type { TodayWidgetKey } from '@/types/today';

/** Deep links from Today dashboard gadgets into feature tabs. */
export const todayDeepLinks = {
  tasksInProgress: '/tasks?status=IN_PROGRESS',
  importantTasks: '/tasks?importantOnly=1&status=IN_PROGRESS',
  overdueCases: '/tasks?overdueOnly=1&status=IN_PROGRESS',
  unassignedTasks: '/tasks?unassignedOnly=1&status=IN_PROGRESS',
  tasksByProsthesis: (prosthesisTypeCode: string) =>
    `/tasks?prosthesisTypeCode=${encodeURIComponent(prosthesisTypeCode)}&status=IN_PROGRESS&sortBy=prosthesis&sortDir=desc`,
  casesByClinic: (clinicOrganizationId: string) =>
    `/cases?clinicOrganizationId=${encodeURIComponent(clinicOrganizationId)}`,
  staffMissingWorkingHours: (membershipIds: string[]) => {
    if (membershipIds.length === 0) return '/staff';
    return `/staff?highlightMembershipIds=${membershipIds.map(encodeURIComponent).join(',')}`;
  },
} as const;

const KPI_HREFS: Partial<Record<TodayWidgetKey, string>> = {
  tasksInProgress: todayDeepLinks.tasksInProgress,
  importantTasks: todayDeepLinks.importantTasks,
  overdueCases: todayDeepLinks.overdueCases,
  unassignedTasks: todayDeepLinks.unassignedTasks,
};

export function todayKpiHref(key: TodayWidgetKey, fallback: string): string {
  return KPI_HREFS[key] ?? fallback;
}
