import { Badge } from '@mantine/core';
import type { TFunction } from 'i18next';
import type { AdvancedColumn } from '@ema-platform/ui';
import type { LocationType } from '../../types/location';

export function locationTypeColumns(
  t: TFunction,
  locale: 'en' | 'am',
): AdvancedColumn<LocationType>[] {
  return [
    {
      header: t('location.level'),
      cell: ({ row }) => (
        <Badge size="sm" variant="light" color="gray">
          {row.original.level}
        </Badge>
      ),
    },
    {
      header: t('location.code'),
      cell: ({ row }) => (
        <Badge size="sm" variant="light" color="blue">
          {row.original.code}
        </Badge>
      ),
    },
    {
      header: t('location.name'),
      // Falls back like the type Select: a row missing this locale shows its
      // English name, then its code, rather than an empty cell.
      cell: ({ row }) =>
        row.original.names[locale] || row.original.names.en || row.original.code,
    },
  ];
}
