import { Badge, Text } from '@mantine/core';
import type { TFunction } from 'i18next';
import type { AdvancedColumn } from '@ema-platform/ui';
import type { PickupAppointment, PickupOffice } from '@ema-platform/api';

const STATUS_COLOR: Record<PickupAppointment['status'], string> = {
  SCHEDULED: 'cyan',
  CHECKED_IN: 'yellow',
  ISSUED: 'green',
  NO_SHOW: 'red',
  RESCHEDULED: 'gray',
  CANCELLED: 'gray',
};

export function pickupDeskColumns(
  t: TFunction,
  officesById: Map<string, PickupOffice>,
): AdvancedColumn<PickupAppointment>[] {
  return [
    {
      header: t('pickupDesk.columns.time', 'Time'),
      cell: ({ row }) => (
        <Text size="sm" fw={600} ff="monospace">
          {row.original.slotStartTime}
        </Text>
      ),
    },
    {
      header: t('pickupDesk.columns.appointment', 'Appointment'),
      cell: ({ row }) => (
        <Text size="sm" ff="monospace">
          {row.original.appointmentNumber}
        </Text>
      ),
    },
    {
      header: t('pickupDesk.columns.office', 'Office'),
      cell: ({ row }) => (
        <Text size="sm">{officesById.get(row.original.officeId)?.name ?? '—'}</Text>
      ),
    },
    {
      header: t('pickupDesk.columns.status', 'Status'),
      cell: ({ row }) => (
        <Badge size="sm" variant="light" color={STATUS_COLOR[row.original.status]}>
          {row.original.status.replace('_', ' ')}
        </Badge>
      ),
    },
  ];
}
