import { useState, useEffect, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { X } from 'lucide-react'; import type { InventorySpool } from '../../api/client'; import { SpoolIcon } from './SpoolIcon'; interface LinkSpoolModalProps { isOpen: boolean; onClose: () => void; tagId: string; untaggedSpools: InventorySpool[]; onLink: (spool: InventorySpool) => void; } export function LinkSpoolModal({ isOpen, onClose, tagId, untaggedSpools, onLink, }: LinkSpoolModalProps) { const { t } = useTranslation(); const [selectedSpool, setSelectedSpool] = useState(null); const handleClose = useCallback(() => { setSelectedSpool(null); onClose(); }, [onClose]); // Handle escape key const handleKeyDown = useCallback((e: KeyboardEvent) => { if (e.key === 'Escape') { handleClose(); } }, [handleClose]); useEffect(() => { if (isOpen) { document.addEventListener('keydown', handleKeyDown); document.body.style.overflow = 'hidden'; } return () => { document.removeEventListener('keydown', handleKeyDown); document.body.style.overflow = ''; }; }, [isOpen, handleKeyDown]); if (!isOpen) return null; const handleConfirm = () => { if (selectedSpool) { onLink(selectedSpool); setSelectedSpool(null); } }; return (
e.stopPropagation()} > {/* Header */}

{t('spoolbuddy.dashboard.linkTagTitle', 'Link Tag to Spool')}

{tagId}

{/* Content */}

{t('spoolbuddy.dashboard.selectSpool', 'Select a spool to link this tag to:')}

{untaggedSpools.length === 0 ? (
{t('spoolbuddy.dashboard.noUntagged', 'No spools without tags found')}
) : (
{untaggedSpools.map((spool) => ( ))}
)}
{/* Footer */}
); }