'use client';
import { useMemo } from 'react';
import type { ColumnDef } from '@tanstack/react-table';
import { CalendarClock, ClipboardCheck } from 'lucide-react';
import { Badge } from '@/components/ui/badge';
import type { TicketListItem } from '@/types';
import { formatDate } from '@/utils/date';
function TicketAttention({ ticket }: { ticket: TicketListItem }) {
const summary = ticket.attention_summary;
const reviewCount = summary?.pending_repair_review_count ?? 0;
const extensionCount = summary?.pending_extension_request_count ?? 0;
const showReview = reviewCount > 0;
const showExtension = extensionCount > 0;
if (!showReview && !showExtension) return null;
return (
{showReview ? (
Review
{reviewCount}
) : null}
{showExtension ? (
Extension
+{extensionCount}
) : null}
);
}
export function useTicketColumns(): ColumnDef[] {
return useMemo(
() => [
{
accessorKey: 'ticket_name',
header: 'Ticket',
size: 180,
cell: ({ row }) => (
{row.original.ticket_name}
),
},
{
accessorKey: 'chainage_name',
header: 'Segment',
size: 180,
cell: ({ row }) => row.original.chainage_name || 'N/A',
},
{
accessorKey: 'detection_count',
header: 'Detections',
size: 120,
},
{
id: 'attention',
header: 'Attention',
size: 210,
meta: { disableTruncate: true },
cell: ({ row }) => ,
},
{
accessorKey: 'is_closed',
header: 'Status',
size: 100,
meta: { disableTruncate: true },
cell: ({ row }) => (
{row.original.is_closed ? 'Closed' : 'Open'}
),
},
{
id: 'created_by',
header: 'Uploaded By',
size: 220,
cell: ({ row }) => (
{row.original.created_by_name || 'N/A'}
{row.original.created_by_email ? (
{row.original.created_by_email}
) : null}
),
},
{
accessorKey: 'updated_at',
header: 'Updated',
size: 180,
cell: ({ row }) => formatDate(row.original.updated_at),
},
],
[],
);
}