import { useState } from 'react'; import { useI18n } from '../i18n/I18nProvider'; import { download } from '../engine/imageOps'; // Removing a saved photo is not like removing a note: the looks it carried // before its last saves live in its history, and the API drops them with the // row. So the removal asks twice — a download first, then the delete — and says // plainly what goes. Shared by the studio's MY PHOTOS and the folder page. export function DeletePhotoModal({ id, name, historyCount, onConfirm, onClose, }: { id: number; name: string; historyCount: number; onConfirm: () => void; onClose: () => void; }) { const { t } = useI18n(); const [problem, setProblem] = useState(null); const [busy, setBusy] = useState(false); // The file is the clean render the folder stored, so "download first" gives // back the same photo the delete is about to take. const fetchFirst = async () => { setBusy(true); setProblem(null); try { const res = await fetch(`/api/photos/${id}/file`); if (!res.ok) throw new Error(`HTTP ${res.status}`); const bytes = new Uint8Array(await res.arrayBuffer()); const slug = name.replace(/[^\p{L}\p{N}]+/gu, '-').replace(/^-+|-+$/g, '').toLowerCase() || 'photo'; download(bytes, `${slug}.jpg`); } catch (err) { setProblem(t('err.generic', { msg: err instanceof Error ? err.message : String(err) })); } finally { setBusy(false); } }; return (
e.target === e.currentTarget && onClose()}>

{t('del.title')}

{t('del.warning', { n: historyCount })}

{problem ? (

{problem}

) : null}
); }