import { t } from '../../i18n' import { CircleDot, ListPlus, Minus, Plus, Tag, Trash2, X } from 'lucide-react' import { useMemo, useState, type ReactNode } from 'react' import { useBackToClose } from '../../lib/backNav' import { allTags, cleanTag, hasTag } from '../../lib/bulk' import { STATUSES } from '../../lib/constants' import { useEscape } from '../../lib/escape' import { cx, normalizeText } from '../../lib/utils' import { useMedia } from '../../store' import type { MediaItem, WatchStatus } from '../../types' import { StatusDot } from '../Badges' import ConfirmDialog from '../ConfirmDialog' import { NewListForm } from '../ListsView' import { useLibraryActions } from './useLibraryActions' type Panel = null | 'status' | 'list' | 'tag' | 'delete' interface Props { /** Fiches sélectionnées */ selected: MediaItem[] /** Action terminée : on quitte le mode sélection */ onDone: () => void } /** Barre d'actions groupées (en bas, à la place de la barre de navigation). */ export default function SelectionBar({ selected, onDone }: Props) { const actions = useLibraryActions() const [panel, setPanel] = useState(null) const ids = selected.map((i) => i.id) const none = selected.length === 0 const run = async (fn: () => Promise) => { setPanel(null) await fn() onDone() } return ( <>
} label={t('select.status')} onClick={() => setPanel('status')} disabled={none} /> } label={t('select.list')} onClick={() => setPanel('list')} disabled={none} /> } label={t('select.tag')} onClick={() => setPanel('tag')} disabled={none} /> } label={t('common.delete')} onClick={() => setPanel('delete')} disabled={none} danger />
{panel === 'status' && ( setPanel(null)}> {STATUSES.map((s) => { const already = selected.every((i) => i.status === s.value) return ( ) })} )} {panel === 'list' && setPanel(null)} run={run} />} {panel === 'tag' && setPanel(null)} run={run} />} void run(() => actions.deleteItems(ids))} onCancel={() => setPanel(null)} /> ) } function BarButton({ icon, label, onClick, disabled, danger }: { icon: ReactNode; label: string; onClick: () => void; disabled?: boolean; danger?: boolean }) { return ( ) } /** Petite feuille en bas de l'écran ; Échap ou le geste retour la ferment sans quitter la sélection. */ function PickerSheet({ title, onClose, children }: { title: string; onClose: () => void; children: ReactNode }) { useEscape(onClose) useBackToClose(onClose) return (
e.stopPropagation()} >

{title}

{children}
) } type Run = (fn: () => Promise) => Promise function ListPicker({ selected, onClose, run }: { selected: MediaItem[]; onClose: () => void; run: Run }) { const { lists } = useMedia() const actions = useLibraryActions() const ids = selected.map((i) => i.id) return ( {lists.length === 0 &&

{t('select.noLists')}

}
    {lists.map((l) => { const inside = selected.filter((i) => i.listIds?.includes(l.id)).length return (
  • {l.name}

    {t('select.inList', { n: inside, total: selected.length })}

  • ) })}
void run(() => actions.addToList(ids, l.id, l.name))} />
) } function TagPicker({ selected, onClose, run }: { selected: MediaItem[]; onClose: () => void; run: Run }) { const { items } = useMedia() const actions = useLibraryActions() const ids = selected.map((i) => i.id) const existing = useMemo(() => allTags(items), [items]) // Tags déjà portés par au moins une fiche sélectionnée (pour les retirer) const present = useMemo(() => allTags(selected), [selected]) const [text, setText] = useState('') const q = normalizeText(text) const suggestions = existing.filter((tag) => !selected.every((i) => hasTag(i, tag)) && (!q || normalizeText(tag).includes(q))).slice(0, 16) const add = (raw: string) => { const tag = cleanTag(raw, existing) if (tag) void run(() => actions.addTag(ids, tag)) } return (
{ e.preventDefault() add(text) }} > setText(e.target.value)} placeholder={t('tags.placeholder')} maxLength={40} autoFocus enterKeyHint="done" aria-label={t('tags.label')} />
{suggestions.length > 0 && (
{suggestions.map((tag) => ( ))}
)} {present.length > 0 && (
{t('select.removeTag')}
{present.map((tag) => ( ))}
)}

{t('tags.private')}

) }