import { useState, useRef, useEffect } from 'react' import { Pencil, X, Check, CheckCircle2, ExternalLink, Pause, XCircle, Link2, MoreHorizontal, FileText } from 'lucide-react' import { cn } from '@/lib/utils' import { toast } from '@/lib/toast' import type { TriageMeta } from '@/types/ai-session' interface IncidentHeaderProps { triageMeta: TriageMeta psaTicketId: string | null onFieldSave: (field: keyof TriageMeta, value: string) => void onResolve: () => void onStatusUpdate?: () => void onPause?: () => void onClose?: () => void } interface EditPopoverProps { value: string onSave: (value: string) => void onCancel: () => void } function EditPopover({ value, onSave, onCancel }: EditPopoverProps) { const [editValue, setEditValue] = useState(value) const inputRef = useRef(null) useEffect(() => { inputRef.current?.focus() inputRef.current?.select() }, []) const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter') onSave(editValue) if (e.key === 'Escape') onCancel() } return (
setEditValue(e.target.value)} onKeyDown={handleKeyDown} className="flex-1 bg-input border border-default rounded px-2 py-1 text-sm text-primary outline-none focus:border-accent" />
) } interface HeaderFieldProps { label: string value: string | null placeholder: string onSave: (value: string) => void isHypothesis?: boolean } function HeaderField({ label, value, placeholder, onSave, isHypothesis }: HeaderFieldProps) { const [editing, setEditing] = useState(false) return (
{label}
{value || placeholder}
{editing && ( { onSave(v); setEditing(false) }} onCancel={() => setEditing(false)} /> )}
) } function OverflowMenu({ onPause, onClose }: { onPause?: () => void; onClose?: () => void }) { const [open, setOpen] = useState(false) useEffect(() => { if (!open) return const handleEsc = (e: KeyboardEvent) => { if (e.key === 'Escape') setOpen(false) } document.addEventListener('keydown', handleEsc) return () => { document.removeEventListener('keydown', handleEsc) } }, [open]) const handleCopyLink = () => { navigator.clipboard.writeText(`${window.location.origin}${window.location.pathname}`) toast.success('Session link copied') setOpen(false) } return (
{open && ( <>
setOpen(false)} />
{onPause && ( )} {onClose && ( )}
)}
) } export function IncidentHeader({ triageMeta, psaTicketId, onFieldSave, onResolve, onStatusUpdate, onPause, onClose, }: IncidentHeaderProps) { return (
onFieldSave('client_name', v)} />
onFieldSave('asset_name', v)} />
onFieldSave('issue_category', v)} />
onFieldSave('triage_hypothesis', v)} isHypothesis />
{psaTicketId && ( CW #{psaTicketId} )} {onStatusUpdate && ( )}
) }