import { useQuery } from '@tanstack/react-query' import { api } from '@/lib/api-client' import type { RepairTicket } from '@/types/repair' import type { PaginatedResponse } from '@lunarfront/shared/schemas' import { Badge } from '@/components/ui/badge' const STATUS_GROUPS = [ { label: 'New', statuses: ['new', 'in_transit', 'intake'], color: 'bg-blue-500/10 text-blue-500 border-blue-500/20' }, { label: 'Diagnosing', statuses: ['diagnosing', 'pending_approval'], color: 'bg-yellow-500/10 text-yellow-500 border-yellow-500/20' }, { label: 'In Progress', statuses: ['approved', 'in_progress', 'pending_parts'], color: 'bg-orange-500/10 text-orange-500 border-orange-500/20' }, { label: 'Ready', statuses: ['ready'], color: 'bg-green-500/10 text-green-500 border-green-500/20' }, ] interface RepairStatusBarProps { activeFilter: string | null onFilterChange: (statuses: string[] | null) => void } export function RepairStatusBar({ activeFilter, onFilterChange }: RepairStatusBarProps) { // Fetch all non-terminal tickets for counts const { data } = useQuery({ queryKey: ['repair-tickets', 'station-counts'], queryFn: () => api.get>('/v1/repair-tickets', { page: 1, limit: 1, q: undefined, sort: undefined, order: 'asc' }), staleTime: 30_000, }) // We need per-status counts — fetch a larger list for counting const { data: allData } = useQuery({ queryKey: ['repair-tickets', 'station-all'], queryFn: () => api.get>('/v1/repair-tickets', { page: 1, limit: 500, q: undefined, sort: undefined, order: 'asc' }), staleTime: 30_000, }) const tickets = allData?.data ?? [] return (
{STATUS_GROUPS.map((group) => { const count = tickets.filter(t => group.statuses.includes(t.status)).length const isActive = activeFilter === group.label return ( ) })}
) }