import React, { useId, useState } from 'react' import { Check, Loader2, Settings2, Tags } from 'lucide-react' import { DialogButton, DialogFooter, DialogHeader, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT, fs } from '../shared/DialogShell' import type { CollectionLabel } from '@trek/shared' import type { TranslationFn } from '../../types' interface BulkAssignLabelModalProps { isOpen: boolean labels: CollectionLabel[] /** Number of selected places the labels will be added to. */ count: number onAssign: (labelIds: number[]) => Promise | void /** Open the label manager to create labels first. */ onManage: () => void onClose: () => void t: TranslationFn } /** * Pick one or more of the list's labels to add to every selected place. Additive * — it never removes labels a place already has. When the list has no labels yet, * it points the user at the label manager instead. */ export default function BulkAssignLabelModal({ isOpen, labels, count, onAssign, onManage, onClose, t }: BulkAssignLabelModalProps): React.ReactElement { const [picked, setPicked] = useState([]) const [busy, setBusy] = useState(false) const labelId = useId() const toggle = (id: number) => setPicked(picked.includes(id) ? picked.filter(x => x !== id) : [...picked, id]) const assign = async () => { if (picked.length === 0 || busy) return setBusy(true) try { await onAssign(picked) setPicked([]) } finally { setBusy(false) } } return ( } tint={NEUTRAL_TINT} labelId={labelId} onClose={onClose} title={t('collections.labels.assignN', { count })} /> )} footer={labels.length === 0 ? undefined : ( }>{t('collections.labels.manage')} {t('common.cancel')} : } > {t('collections.labels.assign')} )} > {labels.length === 0 ? (

{t('collections.labels.emptyHint')}

}>{t('collections.labels.manage')}
) : (
{labels.map(l => { const on = picked.includes(l.id) return ( ) })}
)}
) }