import { Badge, Progress, Text } from '@mantine/core';
import type { TFunction } from 'i18next';
import type { AdvancedColumn } from '@ema-platform/ui';
import {
  STATUS_COLORS,
  STATUS_LABELS,
  STATUS_PROGRESS,
  localized,
} from '@ema-platform/api';
import type { LicenseApplication } from '@ema-platform/api';

export function dashboardApplicationColumns(
  t: TFunction,
): AdvancedColumn<LicenseApplication>[] {
  return [
    {
      header: t('dashboard.table.application'),
      cell: ({ row }) => (
        <>
          <Text size="sm" fw={600}>
            {row.original.applicationNumber}
          </Text>
          <Text size="xs" c="dimmed">
            {row.original.companyName ?? '—'}
          </Text>
        </>
      ),
    },
    {
      header: t('applications.table.licence'),
      cell: ({ row }) => (
        <Text size="sm">{localized(row.original.licenseType?.name) || '—'}</Text>
      ),
    },
    {
      header: t('common.status'),
      cell: ({ row }) => (
        <Badge variant="light" color={STATUS_COLORS[row.original.status]}>
          {STATUS_LABELS[row.original.status]}
        </Badge>
      ),
    },
    {
      header: t('applications.table.progress'),
      size: 180,
      cell: ({ row }) => (
        <Progress
          value={STATUS_PROGRESS[row.original.status]}
          color={STATUS_COLORS[row.original.status]}
          size="sm"
          radius="xl"
        />
      ),
    },
  ];
}
