import { Button } from '@mantine/core';
import { IconEdit } from '@tabler/icons-react';
import type { TFunction } from 'i18next';
import type { LicenseType } from '@ema-platform/api';
import type { AdvancedColumn } from '@ema-platform/ui';
import { LICENSE_PERMISSIONS, RequirePermission } from '@ema-platform/auth';

export function paymentConfigActionsColumn(
  t: TFunction,
  handlers: { onEdit: (type: LicenseType) => void },
): AdvancedColumn<LicenseType> {
  return {
    header: '',
    size: 90,
    align: 'right',
    cell: ({ row }) => (
      <RequirePermission
        anyOf={[LICENSE_PERMISSIONS.UPDATE_LICENSE_TYPE]}
        hideOnly
      >
        <Button
          size="xs"
          variant="light"
          leftSection={<IconEdit size={14} />}
          onClick={() => handlers.onEdit(row.original)}
        >
          {t('paymentConfig.edit', 'Edit')}
        </Button>
      </RequirePermission>
    ),
  };
}
