'use client';
import { TrainingSchema } from '@/feactures/training/schemas/training';
import { Badge } from '@repo/shadcn/badge';
import { ColumnDef } from '@tanstack/react-table';
import { CellAction } from './cell-action';

interface ColumnsProps {
  apiUrl: string;
}

export function columns({ apiUrl }: ColumnsProps): ColumnDef<TrainingSchema>[] {
  return [
    {
      accessorKey: 'ospName',
      header: 'Nombre OSP',
    },
    {
      accessorKey: 'ospRif',
      header: 'RIF',
    },
    {
      accessorKey: 'ospType',
      header: 'Tipo',
    },
    {
      accessorKey: 'currentStatus',
      header: 'Estatus OSP',
      cell: ({ row }) => {
        const status = row.getValue('currentStatus') as string;
        return (
          <Badge variant={status === 'ACTIVA' ? 'default' : 'secondary'}>
            {status}
          </Badge>
        );
      },
    },
    {
      accessorKey: 'created_at',
      header: 'Fecha de creación',
      cell: ({ row }) => {
        // console.log(row.getValue('created_at'));
        const date = row.getValue('created_at') as string;
        return date ? new Date(date).toLocaleString() : 'N/A';
      },
    },
    {
      accessorKey: 'surveyStatus',
      header: '',
      cell: ({ row }) => {
        const status = row.getValue('surveyStatus') as string;
        return (
          <Badge variant={status === 'COMPLETADA' ? 'success' : 'secondary'}>
            {status}
          </Badge>
        );
      },
    },
    {
      id: 'actions',
      header: 'Acciones',
      cell: ({ row }) => <CellAction data={row.original} apiUrl={apiUrl} />,
    },
  ];
}
