File size: 10,504 Bytes
a9dc537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
'use client';

import { motion } from 'framer-motion';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Progress } from '@/components/ui/progress';
import { Badge } from '@/components/ui/badge';
import { CheckCircle, Circle, Loader2, FileText, BarChart3, Users, Mail } from 'lucide-react';
import { Workflow } from '@/lib/types';
import { cn } from '@/lib/utils';

interface WorkflowProgressProps {
  workflow: Workflow;
}

const WORKFLOW_STEPS = [
  {
    key: 'document_analysis',
    label: 'Patent Analysis',
    description: 'Extracting key innovations and TRL assessment',
    icon: FileText,
    progressRange: [0, 30],
  },
  {
    key: 'market_analysis',
    label: 'Market Research',
    description: 'Identifying commercialization opportunities',
    icon: BarChart3,
    progressRange: [30, 60],
  },
  {
    key: 'matchmaking',
    label: 'Partner Matching',
    description: 'Finding relevant stakeholders with semantic search',
    icon: Users,
    progressRange: [60, 85],
  },
  {
    key: 'outreach',
    label: 'Brief Generation',
    description: 'Creating valorization brief document',
    icon: Mail,
    progressRange: [85, 100],
  },
];

export function WorkflowProgress({ workflow }: WorkflowProgressProps) {
  // Determine current step based on workflow.current_step or progress
  const currentStepIndex = workflow.current_step
    ? WORKFLOW_STEPS.findIndex((step) => step.key === workflow.current_step)
    : Math.floor(workflow.progress / 25);

  const getStepStatus = (stepIndex: number) => {
    if (workflow.status === 'failed') {
      return stepIndex <= currentStepIndex ? 'failed' : 'pending';
    }
    if (workflow.status === 'completed') {
      return 'completed';
    }
    if (stepIndex < currentStepIndex) {
      return 'completed';
    }
    if (stepIndex === currentStepIndex) {
      return 'in-progress';
    }
    return 'pending';
  };

  return (
    <div className="w-full max-w-3xl mx-auto space-y-6">
      {/* Overall Progress */}
      <Card>
        <CardHeader>
          <div className="flex items-center justify-between">
            <CardTitle className="text-2xl">
              {workflow.status === 'completed' && '✅ Analysis Complete'}
              {workflow.status === 'failed' && '❌ Analysis Failed'}
              {workflow.status === 'running' && '⚡ Analyzing Patent...'}
              {workflow.status === 'queued' && '⏳ Queued for Processing'}
            </CardTitle>
            <Badge
              variant={
                workflow.status === 'completed'
                  ? 'default'
                  : workflow.status === 'failed'
                  ? 'destructive'
                  : 'secondary'
              }
              className="text-sm"
            >
              {workflow.status.toUpperCase()}
            </Badge>
          </div>
        </CardHeader>
        <CardContent>
          <div className="space-y-2">
            <div className="flex justify-between text-sm">
              <span className="text-gray-600">Overall Progress</span>
              <span className="font-medium">{workflow.progress}%</span>
            </div>
            <Progress value={workflow.progress} className="h-3" />
          </div>
        </CardContent>
      </Card>

      {/* Workflow Steps */}
      <div className="space-y-4">
        {WORKFLOW_STEPS.map((step, index) => {
          const status = getStepStatus(index);
          const Icon = step.icon;

          return (
            <motion.div
              key={step.key}
              initial={{ opacity: 0, x: -20 }}
              animate={{ opacity: 1, x: 0 }}
              transition={{ delay: index * 0.1 }}
            >
              <Card
                className={cn(
                  'transition-all',
                  status === 'in-progress' && 'border-blue-500 bg-blue-50',
                  status === 'completed' && 'border-green-200 bg-green-50',
                  status === 'failed' && 'border-red-200 bg-red-50'
                )}
              >
                <CardContent className="p-6">
                  <div className="flex items-start space-x-4">
                    {/* Status Icon */}
                    <div
                      className={cn(
                        'flex h-12 w-12 shrink-0 items-center justify-center rounded-full',
                        status === 'completed' && 'bg-green-100',
                        status === 'in-progress' && 'bg-blue-100',
                        status === 'pending' && 'bg-gray-100',
                        status === 'failed' && 'bg-red-100'
                      )}
                    >
                      {status === 'completed' && (
                        <CheckCircle className="h-6 w-6 text-green-600" />
                      )}
                      {status === 'in-progress' && (
                        <Loader2 className="h-6 w-6 text-blue-600 animate-spin" />
                      )}
                      {status === 'pending' && (
                        <Circle className="h-6 w-6 text-gray-400" />
                      )}
                      {status === 'failed' && (
                        <Circle className="h-6 w-6 text-red-600" />
                      )}
                    </div>

                    {/* Step Content */}
                    <div className="flex-1 min-w-0">
                      <div className="flex items-center space-x-3 mb-1">
                        <Icon
                          className={cn(
                            'h-5 w-5',
                            status === 'completed' && 'text-green-600',
                            status === 'in-progress' && 'text-blue-600',
                            status === 'pending' && 'text-gray-400',
                            status === 'failed' && 'text-red-600'
                          )}
                        />
                        <h3
                          className={cn(
                            'text-lg font-semibold',
                            status === 'completed' && 'text-green-900',
                            status === 'in-progress' && 'text-blue-900',
                            status === 'pending' && 'text-gray-500',
                            status === 'failed' && 'text-red-900'
                          )}
                        >
                          {step.label}
                        </h3>
                        <Badge
                          variant={
                            status === 'completed'
                              ? 'default'
                              : status === 'in-progress'
                              ? 'secondary'
                              : 'outline'
                          }
                          className="text-xs"
                        >
                          {status === 'completed' && 'Done'}
                          {status === 'in-progress' && 'Processing...'}
                          {status === 'pending' && 'Pending'}
                          {status === 'failed' && 'Failed'}
                        </Badge>
                      </div>
                      <p
                        className={cn(
                          'text-sm',
                          status === 'completed' && 'text-green-700',
                          status === 'in-progress' && 'text-blue-700',
                          status === 'pending' && 'text-gray-500',
                          status === 'failed' && 'text-red-700'
                        )}
                      >
                        {step.description}
                      </p>

                      {/* Step Progress Bar (only for in-progress step) */}
                      {status === 'in-progress' && (
                        <motion.div
                          initial={{ opacity: 0, y: -5 }}
                          animate={{ opacity: 1, y: 0 }}
                          className="mt-3"
                        >
                          <Progress
                            value={
                              ((workflow.progress - step.progressRange[0]) /
                                (step.progressRange[1] - step.progressRange[0])) *
                              100
                            }
                            className="h-2"
                          />
                        </motion.div>
                      )}
                    </div>
                  </div>
                </CardContent>
              </Card>
            </motion.div>
          );
        })}
      </div>

      {/* Error Display */}
      {workflow.error && (
        <motion.div
          initial={{ opacity: 0, y: 10 }}
          animate={{ opacity: 1, y: 0 }}
        >
          <Card className="border-red-200 bg-red-50">
            <CardContent className="p-6">
              <div className="flex items-start space-x-3">
                <div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-red-100">
                  <span className="text-xl">⚠️</span>
                </div>
                <div>
                  <h3 className="font-semibold text-red-900">Error Occurred</h3>
                  <p className="text-sm text-red-700 mt-1">{workflow.error}</p>
                </div>
              </div>
            </CardContent>
          </Card>
        </motion.div>
      )}

      {/* Completion Message */}
      {workflow.status === 'completed' && (
        <motion.div
          initial={{ opacity: 0, scale: 0.95 }}
          animate={{ opacity: 1, scale: 1 }}
          transition={{ duration: 0.5 }}
        >
          <Card className="border-green-200 bg-gradient-to-br from-green-50 to-emerald-50">
            <CardContent className="p-6">
              <div className="text-center space-y-2">
                <div className="flex justify-center">
                  <div className="flex h-16 w-16 items-center justify-center rounded-full bg-green-100">
                    <CheckCircle className="h-10 w-10 text-green-600" />
                  </div>
                </div>
                <h3 className="text-xl font-bold text-green-900">
                  Analysis Complete!
                </h3>
                <p className="text-green-700">
                  Your patent analysis is ready. Redirecting to results...
                </p>
              </div>
            </CardContent>
          </Card>
        </motion.div>
      )}
    </div>
  );
}