'use client';

import type { Column, ColumnDef } from '@tanstack/react-table';
import { DataTableColumnHeader } from '@/components/ui/table/data-table-column-header';
import { Badge } from '@/components/ui/badge';
import { Icons } from '@/components/icons';
import { formatDateTime } from '@/lib/format';
import type { PermissionAuditLog } from '../api/types';

export const permissionAuditLogColumns: ColumnDef<PermissionAuditLog>[] = [
  {
    accessorKey: 'actor_user_name',
    header: ({ column }: { column: Column<PermissionAuditLog, unknown> }) => (
      <DataTableColumnHeader column={column} title='Actor' />
    ),
    cell: ({ row }) => row.original.actor_user_name ?? '-',
    meta: {
      label: 'Actor',
      placeholder: 'Search audit logs...',
      variant: 'text' as const,
      icon: Icons.search
    },
    enableColumnFilter: true
  },
  {
    accessorKey: 'action',
    header: ({ column }: { column: Column<PermissionAuditLog, unknown> }) => (
      <DataTableColumnHeader column={column} title='Action' />
    ),
    cell: ({ row }) => <Badge variant='outline'>{row.original.action}</Badge>
  },
  {
    accessorKey: 'template_name',
    header: 'TEMPLATE',
    cell: ({ row }) => row.original.template_name ?? '-'
  },
  {
    accessorKey: 'reason',
    header: 'REASON',
    cell: ({ row }) => row.original.reason ?? '-'
  },
  {
    accessorKey: 'created_at',
    header: ({ column }: { column: Column<PermissionAuditLog, unknown> }) => (
      <DataTableColumnHeader column={column} title='Created At' />
    ),
    cell: ({ row }) => formatDateTime(row.original.created_at)
  }
];
