import { type ColumnDef } from '@tanstack/react-table' import { type Role } from '@/types/roles.types' import { Badge } from '@/components/ui/badge' import { DataTableColumnHeader } from '@/components/data-table' import { LongText } from '@/components/long-text' import { DataTableRowActions } from './data-table-row-actions' const roleStatusLabels: Record = { active: 'فعال', inactive: 'غیرفعال', } export const rolesColumns: ColumnDef[] = [ { accessorKey: 'id', header: ({ column }) => ( ), cell: ({ row }) =>
#{row.original.id}
, }, { accessorKey: 'name', header: ({ column }) => ( ), cell: ({ row }) => ( {row.original.name} ), }, { accessorKey: 'status', header: ({ column }) => ( ), cell: ({ row }) => ( {roleStatusLabels[row.original.status] ?? row.original.status} ), }, { id: 'activity_fields', accessorFn: (row) => row.activity_fields?.map((field) => field.name).join(', ') ?? '', header: ({ column }) => ( ), cell: ({ row }) => { const fields = row.original.activity_fields ?? [] if (fields.length === 0) { return — } const visibleFields = fields.length > 3 ? fields.slice(0, 2) : fields const hiddenCount = fields.length - visibleFields.length return (
{visibleFields.map((field) => ( {field.name} ))} {hiddenCount > 0 && +{hiddenCount}}
) }, }, { id: 'permissions_count', accessorFn: (row) => row.permissions.length, header: ({ column }) => ( ), cell: ({ row }) => ( {row.original.permissions.length} ), }, { accessorKey: 'created_at', header: ({ column }) => ( ), cell: ({ row }) => (
{new Date(row.original.created_at).toLocaleDateString('fa-IR')}
), }, { id: 'actions', cell: DataTableRowActions, enableSorting: false, }, ]