Spaces:
Sleeping

File size: 4,273 Bytes
611725d
 
 
aa69780
611725d
 
 
aa69780
611725d
 
 
 
 
aa69780
611725d
 
aa69780
 
 
 
 
 
 
 
 
 
611725d
aa69780
 
 
 
 
 
 
 
 
611725d
 
aa69780
 
 
 
611725d
 
 
 
 
 
 
 
 
 
 
aa69780
611725d
 
aa69780
 
 
 
 
 
 
 
611725d
 
 
 
 
 
 
 
 
aa69780
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
611725d
 
 
 
 
 
 
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
import { useState, useEffect } from 'react'

const analysisSteps = [
  { text: 'Reading image metadata...', icon: 'πŸ“·' },
  { text: 'Analyzing depth of field...', icon: 'πŸ”' },
  { text: 'Detecting light sources...', icon: 'πŸ’‘' },
  { text: 'Extracting color palette...', icon: '🎨' },
  { text: 'Analyzing tone curve...', icon: 'πŸ“Š' },
  { text: 'Generating recommendations...', icon: '✨' },
]

function LoadingAnalysis({ imagePreview }) {
  const [currentStep, setCurrentStep] = useState(0)
  const [elapsedTime, setElapsedTime] = useState(0)

  useEffect(() => {
    // Progress through steps without looping
    const stepInterval = setInterval(() => {
      setCurrentStep((prev) => {
        // Stop at the last step instead of looping
        if (prev >= analysisSteps.length - 1) {
          return prev
        }
        return prev + 1
      })
    }, 800)

    // Track elapsed time for the progress bar
    const timeInterval = setInterval(() => {
      setElapsedTime((prev) => prev + 100)
    }, 100)

    return () => {
      clearInterval(stepInterval)
      clearInterval(timeInterval)
    }
  }, [])

  // Estimate progress (assume ~5 seconds typical analysis time)
  const estimatedDuration = 5000
  const progress = Math.min((elapsedTime / estimatedDuration) * 100, 95)

  return (
    <div className="max-w-4xl mx-auto">
      <div className="grid md:grid-cols-2 gap-8 items-center">
        <div className="relative">
          <img
            src={imagePreview}
            alt="Uploaded"
            className="w-full rounded-xl shadow-2xl"
          />
          <div className="absolute inset-0 bg-gradient-to-t from-slate-900/80 to-transparent rounded-xl" />
          <div className="absolute bottom-4 left-4 right-4">
            <div className="flex items-center gap-3 text-white mb-2">
              <div className="animate-spin w-5 h-5 border-2 border-white border-t-transparent rounded-full" />
              <span className="text-sm font-medium">Processing image...</span>
              <span className="ml-auto text-xs text-slate-300">{Math.round(progress)}%</span>
            </div>
            {/* Progress bar */}
            <div className="h-1 bg-slate-700 rounded-full overflow-hidden">
              <div
                className="h-full bg-gradient-to-r from-amber-500 to-orange-500 transition-all duration-300 ease-out"
                style={{ width: `${progress}%` }}
              />
            </div>
          </div>
        </div>

        <div className="space-y-4">
          <h3 className="text-xl font-bold text-white mb-6">
            Analyzing Your Shot
          </h3>

          {analysisSteps.map((step, index) => {
            const isActive = index === currentStep
            const isComplete = index < currentStep
            const isLast = index === analysisSteps.length - 1
            const isWaiting = isActive && isLast && progress > 80

            return (
              <div
                key={index}
                className={`flex items-center gap-3 p-3 rounded-lg transition-all ${
                  isActive
                    ? 'bg-amber-500/20 border border-amber-500/50'
                    : isComplete
                    ? 'bg-slate-800/50'
                    : 'bg-slate-800/30 opacity-30'
                }`}
              >
                <span className="text-xl">{step.icon}</span>
                <span className={`text-sm ${isActive ? 'text-white' : isComplete ? 'text-slate-300' : 'text-slate-400'}`}>
                  {isWaiting ? 'Finishing up...' : step.text}
                </span>
                {isActive && (
                  <div className="ml-auto">
                    <div className="animate-spin w-4 h-4 border-2 border-amber-500 border-t-transparent rounded-full" />
                  </div>
                )}
                {isComplete && (
                  <svg className="ml-auto w-5 h-5 text-green-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                    <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
                  </svg>
                )}
              </div>
            )
          })}
        </div>
      </div>
    </div>
  )
}

export default LoadingAnalysis