import React from 'react'
import { ColumnDef } from '@tanstack/react-table'

import { ActionButtons } from './ActionButtons'
import { StudyYear } from '@/src/interfaces/users/studyYears'

interface Props {
  onOpenEditModal: (studyYearId: string) => void
  onOpenDeleteModal: (studyYearId: string) => void
}

export const useColumns = ({ onOpenEditModal, onOpenDeleteModal }: Props) =>
  React.useMemo<ColumnDef<StudyYear>[]>(
    () => [
      { header: 'Ciclo Académico', accessorKey: 'year' },
      {
        header: 'Creado por',
        accessorKey: 'creatorName',
        enableSorting: false,
      },
      {
        header: 'Acciones',
        enableSorting: false,
        cell: ({ row }) => (
          <ActionButtons
            studyYearId={row.original.id}
            onEdit={onOpenEditModal}
            onDelete={onOpenDeleteModal}
          />
        ),
      },
    ],
    [],
  )

