import React, { useEffect, useState } from 'react'; import { ArrowRight, CheckSquare, Inbox, ShoppingCart, X } from 'lucide-react'; import { api, triggerHaptic } from '../lib/api'; import type { SharedList } from '../lib/types'; // After sharing from another app: the items are already in the Quick Dump (nothing to tap), and for a // few seconds they can be sent on as a task or onto a list instead – one tap, the flow stays as fast. const AUTO_HIDE_MS = 8000; interface SharedImportToastProps { thoughtIds: string[]; // created on the server (offline captures have no id yet and get no buttons) lists: SharedList[]; onClose: () => void; onConverted: (message: string) => void; } export const SharedImportToast: React.FC = ({ thoughtIds, lists, onClose, onConverted }) => { const [choosingList, setChoosingList] = useState(false); const [busy, setBusy] = useState(false); const [failed, setFailed] = useState(false); const writableLists = lists.filter((l) => l.isOwner || l.role !== 'viewer'); const count = thoughtIds.length; // Disappears on its own unless a list is being picked or a conversion runs useEffect(() => { if (choosingList || busy) return; const timer = window.setTimeout(onClose, AUTO_HIDE_MS); return () => window.clearTimeout(timer); }, [choosingList, busy, onClose]); const convert = async (convertTo: 'task' | 'list_item', list?: SharedList) => { triggerHaptic(15); setBusy(true); setFailed(false); try { for (const id of thoughtIds) { await api.triageAction(id, 'keep', { convertTo, targetListId: list?.id }); } const what = count === 1 ? 'Eintrag' : `${count} Einträge`; onConverted(convertTo === 'task' ? `${count === 1 ? 'Als Aufgabe' : `${count} Aufgaben`} angelegt` : `${what} auf „${list?.title}“`); } catch { setFailed(true); setBusy(false); } }; const toList = () => { if (writableLists.length === 1) convert('list_item', writableLists[0]); else setChoosingList(true); }; const big = 'min-h-[52px] px-3 py-2 rounded-xl text-sm font-semibold flex items-center justify-center gap-2 touch-manipulation cursor-pointer active:scale-98 disabled:opacity-50'; return ( <> {/* Tapping anywhere else closes it (transparent, the page stays visible) */}

{count === 1 ? 'Im Quick Dump abgelegt' : `${count} Einträge im Quick Dump abgelegt`}

{choosingList ? 'Auf welche Liste?' : 'Oder gleich woanders hin:'}

{failed &&

Umwandeln hat nicht geklappt – der Eintrag bleibt im Quick Dump.

} {!choosingList ? (
0 ? 'grid-cols-2' : 'grid-cols-1'}`}> {writableLists.length > 0 && ( )}
) : (
{writableLists.map((l) => ( ))}
)}
); };