Spaces:
Runtime error
Runtime error
File size: 6,747 Bytes
d30af0c e205988 ddec551 06bdaca ddec551 06bdaca d600757 ddec551 06bdaca d30af0c ddec551 593439e e205988 445c3cc 593439e e205988 593439e e205988 593439e e205988 445c3cc 593439e 445c3cc 593439e 445c3cc 593439e d600757 593439e d600757 e205988 593439e e205988 d600757 d30af0c d600757 06bdaca d600757 ddec551 445c3cc d600757 593439e d600757 d30af0c d600757 d30af0c d600757 593439e d600757 593439e 445c3cc d600757 d30af0c 445c3cc d600757 593439e 445c3cc 593439e 445c3cc ddec551 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | import { AlertTriangle, Camera, ImagePlus, RotateCcw } from 'lucide-react'
import { ASSETS } from '../lib/assets'
import { t } from '../lib/i18n'
import type { Lang } from '../lib/types'
type Engine = 'checking' | 'local' | 'server' | 'none'
interface Props {
lang: Lang
engine: Engine
modelError?: string
onRetryModel?: () => void
onCamera: () => void
onGallery: () => void
}
export function StepCapture({ lang, engine, modelError, onRetryModel, onCamera, onGallery }: Props) {
const hasError = engine === 'none' || Boolean(modelError)
const ready = engine === 'local' || engine === 'server'
return (
<div className="grain relative flex flex-1 flex-col overflow-hidden">
<img
src={ASSETS.bg}
alt=""
aria-hidden
className="absolute inset-0 h-full w-full object-cover"
/>
<div
className="absolute inset-0"
style={{ background: 'linear-gradient(180deg, rgba(0,73,115,0.88) 0%, rgba(0,49,77,0.92) 100%)' }}
/>
<div className="relative z-10 flex flex-1 flex-col items-center justify-center px-8">
<div className="mb-10 flex flex-col items-center gap-6">
{/* Logo + live status dot — staggered entrance */}
<div className="rise-enter relative" style={{ animationDelay: '0ms' }}>
<span
aria-hidden
className="pointer-events-none absolute left-1/2 top-1/2 h-32 w-32 -translate-x-1/2 -translate-y-1/2 rounded-full blur-2xl"
style={{ background: 'radial-gradient(circle, rgba(255,255,255,0.22), transparent 70%)' }}
/>
<img
src={ASSETS.logo}
alt=""
className="relative h-[72px] w-auto max-w-[220px]"
style={{
animation: 'breathe 3.5s ease-in-out infinite',
filter: 'drop-shadow(0 10px 26px rgba(0,0,0,0.32))',
}}
/>
<span
className={`absolute -right-2 -top-1 h-5 w-5 rounded-full border-[3px] border-[#00314d] transition-all duration-700 ${
engine === 'none'
? 'bg-[var(--danger)]'
: ready
? 'bg-[var(--success)]'
: 'animate-pulse bg-[var(--warning)]'
}`}
style={{ boxShadow: 'var(--shadow-sm)' }}
/>
</div>
{/* Title block */}
<div className="rise-enter text-center" style={{ animationDelay: '60ms' }}>
<h1
className="text-white"
style={{
font: 'var(--type-h1)',
letterSpacing: 'var(--tracking-tight)',
textShadow: '0 2px 14px rgba(0,0,0,0.20)',
}}
>
{t(lang, 'title')}
</h1>
<p
className="mt-2 text-white/70"
style={{ font: 'var(--type-body)' }}
>
{t(lang, 'captureSubtitle')}
</p>
</div>
{/* Status badge / retry — premium glass treatment */}
{hasError ? (
<button
type="button"
onClick={onRetryModel}
className="rise-enter ct-badge ct-badge--danger"
style={{ animationDelay: '120ms', boxShadow: 'var(--shadow-sm)' }}
>
<RotateCcw size={12} />
{t(lang, 'retry')}
</button>
) : (
<div
className="rise-enter ct-badge backdrop-blur-md"
style={{
animationDelay: '120ms',
border: '1px solid rgba(255,255,255,0.18)',
background: ready ? 'rgba(255,255,255,0.16)' : 'rgba(255,255,255,0.10)',
color: ready ? '#fff' : 'rgba(255,255,255,0.9)',
boxShadow: 'var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,0.22)',
}}
>
<span
className={`h-1.5 w-1.5 rounded-full ${
ready ? 'bg-[var(--success)]' : 'animate-pulse bg-[var(--warning)]'
}`}
/>
{ready ? t(lang, 'modelReady') : t(lang, 'loadingModel')}
</div>
)}
</div>
{hasError && (
<div
className="overlay-enter mb-4 w-full max-w-sm border border-red-300/40 bg-white/95 p-4"
style={{
borderRadius: 'var(--r-xl)',
boxShadow: 'var(--shadow-lg)',
animationDelay: '120ms',
}}
>
<div className="flex items-start gap-2.5">
<AlertTriangle size={18} className="mt-0.5 shrink-0 text-[var(--danger)]" />
<div className="min-w-0">
<p className="text-sm font-semibold text-[var(--danger)]">{t(lang, 'modelErrorTitle')}</p>
<p className="mt-1 break-words text-xs text-[var(--text-dim)]">{modelError}</p>
<button
type="button"
onClick={onRetryModel}
className="mt-3 flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold text-white"
style={{ background: 'var(--danger)', borderRadius: 'var(--r-md)', boxShadow: 'var(--shadow-sm)' }}
>
<RotateCcw size={13} />
{t(lang, 'retry')}
</button>
</div>
</div>
</div>
)}
{/* CTA column — staggered last */}
<div className="rise-enter w-full max-w-sm space-y-3" style={{ animationDelay: '180ms' }}>
<button
type="button"
disabled={hasError}
className="ct-btn-primary"
onClick={onCamera}
>
<Camera size={22} strokeWidth={2.5} />
{t(lang, 'takePhoto')}
</button>
<button
type="button"
disabled={hasError}
className="flex min-h-14 w-full items-center justify-center gap-3 bg-white/10 text-white backdrop-blur-md transition-all active:scale-[0.98] active:bg-white/20 disabled:opacity-50 disabled:active:scale-100"
onClick={onGallery}
style={{
borderRadius: 'var(--r-lg)',
border: '1px solid rgba(255,255,255,0.20)',
fontSize: 'var(--text-md)',
fontWeight: 'var(--weight-semibold)',
letterSpacing: 'var(--tracking-snug)',
boxShadow: 'var(--shadow-md), inset 0 1px 0 rgba(255,255,255,0.18)',
}}
>
<ImagePlus size={22} strokeWidth={2} />
{t(lang, 'chooseFile')}
</button>
</div>
</div>
</div>
)
}
|