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

export function applicationColumns(
  t: TFunction,
  deps: {
    language: string;
    showDate: (date: string) => string;
    statusLabel: (status: LicenseStatus) => string;
  },
): AdvancedColumn<LicenseApplication>[] {
  return [
    {
      header: t('applications.table.licence'),
      cell: ({ row }) => (
        <Box>
          <Text size="sm" fw={600}>
            {localized(row.original.licenseType?.name, deps.language) || '—'}
          </Text>
          <Text size="xs" c="dimmed">
            {row.original.applicationNumber}
          </Text>
        </Box>
      ),
    },
    {
      header: t('applications.table.applicant'),
      cell: ({ row }) => <Text size="sm">{applicantOrCompanyName(row.original) ?? '—'}</Text>,
    },
    {
      header: t('common.status'),
      cell: ({ row }) => (
        <Badge color={STATUS_COLORS[row.original.status]} variant="light">
          {deps.statusLabel(row.original.status)}
        </Badge>
      ),
    },
    {
      header: t('applications.table.progress'),
      size: 140,
      cell: ({ row }) => (
        <Progress
          value={STATUS_PROGRESS[row.original.status]}
          color={STATUS_COLORS[row.original.status]}
          size="sm"
          radius="xl"
        />
      ),
    },
    {
      header: t('common.date'),
      cell: ({ row }) => (
        <Text size="sm" c="dimmed">
          {row.original.submittedAt
            ? deps.showDate(row.original.submittedAt)
            : t('applications.card.notFiled')}
        </Text>
      ),
    },
  ];
}
