import { useEffect, useRef, useState } from 'react' import { Paperclip, Link2, FileText } from 'lucide-react' import { useTranslation } from '../../i18n' import type { TripFile } from '../../types' /** * The file actions of a booking or transport dialog: attach a new file, and * once the record exists link a file the trip already has. Two equal buttons * side by side, the same row the Costs block uses below them. */ export function BookingFileButtons({ canAttach, uploading, onAttach, linkable, onLink }: { canAttach: boolean uploading: boolean onAttach: () => void /** Files of the trip this record could take; empty (or before the first save) hides the link button. */ linkable: TripFile[] /** Links one; resolves true when it worked, which closes the list. */ onLink: (file: TripFile) => Promise }) { const { t } = useTranslation() const [open, setOpen] = useState(false) const pickerRef = useRef(null) useEffect(() => { if (!open) return const closeOnOutsidePointer = (event: PointerEvent) => { if (!pickerRef.current?.contains(event.target as Node)) setOpen(false) } document.addEventListener('pointerdown', closeOnOutsidePointer) return () => document.removeEventListener('pointerdown', closeOnOutsidePointer) }, [open]) const canLink = linkable.length > 0 if (!canAttach && !canLink) return null const buttonClass = 'bg-surface-secondary border border-edge text-content transition-colors hover:bg-surface-tertiary disabled:cursor-default disabled:opacity-60' const buttonStyle = { width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8, padding: '8px 13px', borderRadius: 10, fontSize: 'calc(13px * var(--fs-scale-body, 1))', fontWeight: 600, cursor: 'pointer', fontFamily: 'inherit', } as const return (
{canAttach && ( )} {canLink && (
{open && (
{linkable.map(f => ( ))}
)}
)}
) }