import { Badge, Button, Text } from '@mantine/core';
import { IconCertificate } from '@tabler/icons-react';
import type { TFunction } from 'i18next';
import type { AdvancedColumn } from '@ema-platform/ui';
import type { Bilingual, IssuedLicense } from '@ema-platform/api';

interface EndorsementColumnsArgs {
  t: TFunction;
  showDate: (date: string) => string;
  localized: (value: Bilingual | undefined) => string;
  onDownload: (licenseId: string) => void;
}

export function endorsementColumns({
  t,
  showDate,
  localized,
  onDownload,
}: EndorsementColumnsArgs): AdvancedColumn<IssuedLicense>[] {
  return [
    {
      header: t('endorsement.columns.certificateNumber', 'Certificate №'),
      accessorKey: 'certificateNumber',
      cell: ({ row }) => (
        <Text ff="monospace" size="sm" fw={600}>
          {row.original.certificateNumber}
        </Text>
      ),
    },
    {
      header: t('endorsement.columns.type', 'Type'),
      cell: ({ row }) => localized(row.original.licenseType?.name),
    },
    {
      header: t('endorsement.columns.issued', 'Issued'),
      cell: ({ row }) => showDate(row.original.issueDate),
    },
    {
      header: t('endorsement.columns.expires', 'Expires'),
      cell: ({ row }) => showDate(row.original.expiryDate),
    },
    {
      header: t('common.status'),
      cell: ({ row }) => (
        <Badge
          size="sm"
          variant="light"
          color={row.original.status === 'ACTIVE' ? 'green' : 'red'}
        >
          {t(
            `endorsement.columns.licenseStatus.${row.original.status}`,
            row.original.status,
          )}
        </Badge>
      ),
    },
    {
      header: '',
      cell: ({ row }) => (
        <Button
          size="compact-xs"
          variant="subtle"
          leftSection={<IconCertificate size={14} />}
          onClick={() => onDownload(row.original.id)}
        >
          {t('common.download')}
        </Button>
      ),
    },
  ];
}
