File size: 2,901 Bytes
ddec551
 
d30af0c
ddec551
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d30af0c
ddec551
 
d30af0c
445c3cc
13ef64d
 
 
 
 
 
445c3cc
ddec551
 
445c3cc
13ef64d
d30af0c
ddec551
 
d30af0c
ddec551
 
 
 
 
d30af0c
 
13ef64d
 
d30af0c
 
 
ddec551
13ef64d
 
 
 
d30af0c
 
ddec551
 
445c3cc
13ef64d
 
445c3cc
906b5bb
 
 
 
 
 
 
 
 
 
 
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
import { Camera, ChevronLeft, ImagePlus, Loader2 } from 'lucide-react'
import { t } from '../lib/i18n'
import type { Lang } from '../lib/types'

interface Props {
  lang: Lang
  imageSrc: string
  imageDims: { w: number; h: number }
  busy: boolean
  modelReady: boolean
  onBack: () => void
  onRetake: () => void
  onGallery: () => void
  onCount: () => void
}

export function StepPreview({
  lang,
  imageSrc,
  imageDims,
  busy,
  modelReady,
  onBack,
  onRetake,
  onGallery,
  onCount,
}: Props) {
  const ar = imageDims.h / Math.max(imageDims.w, 1)
  const maxPreviewH = Math.min(ar * 100, 62)

  return (
    <div className="flex flex-1 flex-col overflow-hidden bg-[var(--bg)]">
      <div className="flex items-center justify-between px-4 py-2.5">
        <button
          type="button"
          className="ct-btn-ghost rise-enter flex h-9 items-center gap-1 px-3 text-sm"
          style={{ animationDelay: '0.04s' }}
          onClick={onBack}
        >
          <ChevronLeft size={16} strokeWidth={2.5} />
          {t(lang, 'previewBack')}
        </button>

        <div className="rise-enter flex gap-2" style={{ animationDelay: '0.1s' }}>
          <button type="button" className="ct-btn-ghost h-9 w-9" onClick={onRetake} aria-label={t(lang, 'retake')}>
            <Camera size={17} />
          </button>
          <button type="button" className="ct-btn-ghost h-9 w-9" onClick={onGallery} aria-label={t(lang, 'chooseFile')}>
            <ImagePlus size={17} />
          </button>
        </div>
      </div>

      <div className="flex flex-1 flex-col px-4">
        <div
          className="rise-enter overflow-hidden rounded-2xl border border-[var(--hairline)] bg-black shadow-[var(--shadow-lg)] ring-1 ring-black/5"
          style={{ flex: '1 1 auto', minHeight: '40vh', maxHeight: `${maxPreviewH}vh`, animationDelay: '0.16s' }}
        >
          <img src={imageSrc} alt="Preview" className="h-full w-full object-contain" />
        </div>

        <p
          className="rise-enter mt-2 text-center text-[11px] tabular-nums text-[var(--text-faint)]"
          style={{ fontFamily: 'var(--font-mono)', animationDelay: '0.22s' }}
        >
          {imageDims.w} × {imageDims.h}
        </p>
      </div>

      <div
        className="rise-enter shrink-0 border-t border-[var(--hairline)] bg-[var(--header-bg)] px-4 pt-3 shadow-[0_-4px_24px_rgba(15,23,42,0.06)]"
        style={{ paddingBottom: 'max(1rem, env(safe-area-inset-bottom))', animationDelay: '0.28s' }}
      >
        <div className="mx-auto w-full max-w-sm">
          <button
            type="button"
            disabled={busy || !modelReady}
            className="ct-btn-primary"
            onClick={onCount}
          >
            {busy ? <Loader2 className="animate-spin" size={22} /> : null}
            {t(lang, 'countNow')}
          </button>
        </div>
      </div>
    </div>
  )
}