import { useQuery } from '@tanstack/react-query'; import { Clock, Calendar, ChevronRight } from 'lucide-react'; import { Link } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { api } from '../api/client'; import { formatRelativeTime } from '../utils/date'; import { filterCompatibleQueueItems } from '../utils/printer'; interface PrinterQueueWidgetProps { printerId: number; printerModel?: string | null; loadedFilamentTypes?: Set; loadedFilaments?: Set; // "TYPE:rrggbb" pairs for filament override color matching loadedVariants?: Set; // "TYPE:rrggbb:idx" triples for PLA sub-variant matching (#2650) variant?: 'card' | 'panelExtension'; } export function PrinterQueueWidget({ printerId, printerModel, loadedFilamentTypes, loadedFilaments, loadedVariants, variant = 'card' }: PrinterQueueWidgetProps) { const { t } = useTranslation(); const { data: queue } = useQuery({ queryKey: ['queue', printerId, 'pending', printerModel], queryFn: () => api.getQueue(printerId, 'pending', printerModel || undefined), refetchInterval: 30000, }); // Filter queue to items this printer can actually print (filament type + color check) const compatibleQueue = queue ? filterCompatibleQueueItems(queue, loadedFilamentTypes, loadedFilaments, loadedVariants) : undefined; const totalPending = compatibleQueue?.length || 0; if (totalPending === 0) { return null; } const nextItem = compatibleQueue?.[0]; // Passive next-in-queue preview. Plate-clear acknowledgment is handled by the // card-level "Mark plate as cleared" button (PrintersPage.tsx). Having a // second button in this widget caused the two controls to overlap whenever // the plate-clear gate was up with auto-dispatch items queued — both POSTed // to the same /clear-plate endpoint, so the widget button was pure noise. const linkClassName = variant === 'panelExtension' ? 'block mt-2 border-t border-bambu-dark-tertiary pt-2 pl-1 hover:opacity-90 transition-opacity' : 'block mb-3 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors'; return (

{t('queue.nextInQueue')}

{nextItem?.archive_name || nextItem?.library_file_name || `File #${nextItem?.archive_id || nextItem?.library_file_id}`}

{nextItem?.scheduled_time ? formatRelativeTime(nextItem.scheduled_time, 'system', t) : t('time.waiting')} {totalPending > 1 && ( +{totalPending - 1} )}
); }