import { Button } from "@mantine/core";
import type { TFunction } from "i18next";
import type { LicenseApplication } from "@ema-platform/api";
import type { AdvancedColumn } from "@ema-platform/ui";
import { LICENSE_PERMISSIONS, RequirePermission } from "@ema-platform/auth";

export function licenseQueueActionsColumn(
  t: TFunction,
  handlers: {
    claiming: boolean;
    onClaim: (id: string) => void;
    onOpen: (id: string) => void;
  },
): AdvancedColumn<LicenseApplication> {
  return {
    header: "",
    label: t("queue.actionsColumn", "Actions"),
    align: "right",
    size: 140,
    cell: ({ row }) =>
      row.original.assignedOfficerId === null &&
      row.original.status === "SUBMITTED" ? (
        <RequirePermission
          anyOf={[LICENSE_PERMISSIONS.CLAIM_APPLICATION]}
          hideOnly
        >
          <Button
            size="xs"
            loading={handlers.claiming}
            onClick={() => handlers.onClaim(row.original.id)}
          >
            {t("queue.claim", "Claim")}
          </Button>
        </RequirePermission>
      ) : (
        <Button
          size="xs"
          variant="light"
          onClick={() => handlers.onOpen(row.original.id)}
        >
          {t("queue.review", "Review")}
        </Button>
      ),
  };
}
