import { ActionIcon, Group } from "@mantine/core";
import { IconEdit, IconTrash, IconDetails } from "@tabler/icons-react";
import type { TFunction } from "i18next";
import type { AdvancedColumn } from "@ema-platform/ui";
import { LICENSE_PERMISSIONS, RequirePermission } from "@ema-platform/auth";
import type { Exam } from "../../types/exam";

export function examActionsColumn(
  t: TFunction,
  handlers: {
    onEdit: (exam: Exam) => void;
    onDelete: (exam: Exam) => void;
    onDetails: (exam: Exam) => void;
  },
): AdvancedColumn<Exam> {
  return {
    header: t("exam.columns.actions"),
    align: "right",
    cell: ({ row }) => (
      <Group gap="xs">
        <RequirePermission anyOf={[LICENSE_PERMISSIONS.MANAGE_EXAMS]} hideOnly>
          <ActionIcon
            variant="subtle"
            color="blue"
            size="sm"
            onClick={() => handlers.onEdit(row.original)}
          >
            <IconEdit size={14} />
          </ActionIcon>
          <ActionIcon
            variant="subtle"
            color="red"
            size="sm"
            onClick={() => handlers.onDelete(row.original)}
          >
            <IconTrash size={14} />
          </ActionIcon>
        </RequirePermission>
        <ActionIcon
          variant="subtle"
          color="red"
          size="sm"
          onClick={() => handlers.onDetails(row.original)}
        >
          <IconDetails size={14} />
        </ActionIcon>
      </Group>
    ),
  };
}
