import { useState } from 'react'; import { useI18n } from '../i18n/I18nProvider'; // Export size. The photo on the stage has a longest edge; the three fixed // answers name the sizes people ask for by name (2048/4096), the fourth takes a // number, and UNCHANGED is what the button used to do on its own. Anything // bigger than the photo is invented by the model (engine/superRes) before the // render, so the file really carries the pixels the user asked for. const CUSTOM_MAX = 8192; export function ExportModal({ longest, maxDim, onPick, onClose, }: { /** Longest edge of the photo as it stands, crop included. */ longest: number; /** The tier's own ceiling, or null for none. */ maxDim: number | null; onPick: (target: number | null) => void; onClose: () => void; }) { const { t } = useI18n(); const [custom, setCustom] = useState(String(Math.min(CUSTOM_MAX, Math.max(1024, longest * 2)))); const pick = (n: number | null) => onPick(n !== null && maxDim !== null ? Math.min(n, maxDim) : n); const customValue = Number(custom); const customOk = Number.isFinite(customValue) && customValue >= 1 && customValue <= CUSTOM_MAX; return (
e.target === e.currentTarget && onClose()}>

{t('export.title')}

{t('export.hint', { px: longest })}

{/* A capped account cannot be handed a size its tier refuses, so the two sizes over the ceiling are not offered at all. */} {maxDim === null || maxDim > 2048 ? ( <>
setCustom(e.target.value)} />
) : (

{t('export.cap', { px: maxDim })}

)}
); }