File size: 13,927 Bytes
82a1419
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
import { useState } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import type { VeoSegment } from '@/types';
import { ChevronDownIcon, CopyIcon, CheckIcon } from './Icons';

interface SegmentPromptsViewerProps {
  segments: VeoSegment[];
  accentColor: 'coral' | 'electric';
}

export const SegmentPromptsViewer: React.FC<SegmentPromptsViewerProps> = ({ 
  segments, 
  accentColor 
}) => {
  const [isOpen, setIsOpen] = useState(false);
  const [expandedSegments, setExpandedSegments] = useState<Set<number>>(new Set());
  const [copiedIndex, setCopiedIndex] = useState<number | null>(null);

  const toggleSegment = (index: number) => {
    const newExpanded = new Set(expandedSegments);
    if (newExpanded.has(index)) {
      newExpanded.delete(index);
    } else {
      newExpanded.add(index);
    }
    setExpandedSegments(newExpanded);
  };

  const expandAll = () => {
    setExpandedSegments(new Set(segments.map((_, i) => i)));
  };

  const collapseAll = () => {
    setExpandedSegments(new Set());
  };

  const copySegment = (segment: VeoSegment, index: number) => {
    const formatted = JSON.stringify(segment, null, 2);
    navigator.clipboard.writeText(formatted);
    setCopiedIndex(index);
    setTimeout(() => setCopiedIndex(null), 2000);
  };

  const copyAllSegments = () => {
    const formatted = JSON.stringify({ segments }, null, 2);
    navigator.clipboard.writeText(formatted);
    setCopiedIndex(-1);
    setTimeout(() => setCopiedIndex(null), 2000);
  };

  if (segments.length === 0) return null;

  return (
    <div className="mb-8">
      <button
        onClick={() => setIsOpen(!isOpen)}
        className={`
          w-full card border-2 transition-colors
          ${accentColor === 'coral' 
            ? 'border-coral-500/30 hover:border-coral-500/50' 
            : 'border-electric-500/30 hover:border-electric-500/50'
          }
        `}
      >
        <div className="flex items-center justify-between">
          <div className="flex items-center gap-3">
            <div className={`p-2 rounded-lg ${accentColor === 'coral' ? 'bg-coral-500/20' : 'bg-electric-500/20'}`}>
              <svg className={`w-5 h-5 ${accentColor === 'coral' ? 'text-coral-400' : 'text-electric-400'}`} fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
              </svg>
            </div>
            <div className="text-left">
              <h3 className="font-bold text-void-100">View Segment Prompts</h3>
              <p className="text-sm text-void-400">
                {segments.length} detailed AI-generated prompts
              </p>
            </div>
          </div>
          <motion.div
            animate={{ rotate: isOpen ? 180 : 0 }}
            transition={{ duration: 0.2 }}
          >
            <ChevronDownIcon size={24} className="text-void-400" />
          </motion.div>
        </div>
      </button>

      <AnimatePresence>
        {isOpen && (
          <motion.div
            initial={{ opacity: 0, height: 0 }}
            animate={{ opacity: 1, height: 'auto' }}
            exit={{ opacity: 0, height: 0 }}
            transition={{ duration: 0.3 }}
            className="overflow-hidden"
          >
            <div className="mt-4 space-y-4">
              {/* Controls */}
              <div className="flex items-center justify-between gap-3 flex-wrap">
                <div className="flex gap-2">
                  <button
                    onClick={expandAll}
                    className="btn-secondary-sm"
                  >
                    Expand All
                  </button>
                  <button
                    onClick={collapseAll}
                    className="btn-secondary-sm"
                  >
                    Collapse All
                  </button>
                </div>
                <button
                  onClick={copyAllSegments}
                  className={`
                    flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm font-medium transition-colors
                    ${accentColor === 'coral'
                      ? 'bg-coral-500/10 text-coral-400 hover:bg-coral-500/20'
                      : 'bg-electric-500/10 text-electric-400 hover:bg-electric-500/20'
                    }
                  `}
                >
                  {copiedIndex === -1 ? (
                    <>
                      <CheckIcon size={16} />
                      Copied All!
                    </>
                  ) : (
                    <>
                      <CopyIcon size={16} />
                      Copy All JSON
                    </>
                  )}
                </button>
              </div>

              {/* Segment Cards */}
              <div className="space-y-3">
                {segments.map((segment, index) => {
                  const isExpanded = expandedSegments.has(index);
                  
                  return (
                    <div
                      key={index}
                      className="card border border-void-700 hover:border-void-600 transition-colors"
                    >
                      {/* Segment Header */}
                      <div className="flex items-start justify-between gap-4">
                        <button
                          onClick={() => toggleSegment(index)}
                          className="flex-1 text-left"
                        >
                          <div className="flex items-center gap-3 mb-2">
                            <span className={`
                              px-2.5 py-0.5 rounded-full text-xs font-bold
                              ${accentColor === 'coral' 
                                ? 'bg-coral-500/20 text-coral-400' 
                                : 'bg-electric-500/20 text-electric-400'
                              }
                            `}>
                              Segment {index + 1}
                            </span>
                            <motion.div
                              animate={{ rotate: isExpanded ? 180 : 0 }}
                              transition={{ duration: 0.2 }}
                            >
                              <ChevronDownIcon size={16} className="text-void-400" />
                            </motion.div>
                          </div>
                          <p className="text-sm text-void-300 line-clamp-2">
                            {segment.action_timeline?.dialogue || 'No dialogue'}
                          </p>
                        </button>
                        <button
                          onClick={() => copySegment(segment, index)}
                          className="p-2 rounded-lg hover:bg-void-800 transition-colors text-void-400 hover:text-void-200"
                          title="Copy segment JSON"
                        >
                          {copiedIndex === index ? (
                            <CheckIcon size={16} className="text-green-400" />
                          ) : (
                            <CopyIcon size={16} />
                          )}
                        </button>
                      </div>

                      {/* Expanded Content */}
                      <AnimatePresence>
                        {isExpanded && (
                          <motion.div
                            initial={{ opacity: 0, height: 0 }}
                            animate={{ opacity: 1, height: 'auto' }}
                            exit={{ opacity: 0, height: 0 }}
                            className="overflow-hidden"
                          >
                            <div className="mt-4 pt-4 border-t border-void-700 space-y-4 text-sm">
                              {/* Dialogue */}
                              <div>
                                <h4 className="font-semibold text-void-200 mb-2">Dialogue</h4>
                                <p className="text-void-400 bg-void-900/50 p-3 rounded-lg">
                                  "{segment.action_timeline?.dialogue}"
                                </p>
                              </div>

                              {/* Character Description */}
                              <div>
                                <h4 className="font-semibold text-void-200 mb-2">Character</h4>
                                <div className="space-y-2">
                                  <div>
                                    <span className="text-xs text-void-500 uppercase tracking-wide">Current State:</span>
                                    <p className="text-void-400 bg-void-900/50 p-2 rounded mt-1 text-xs leading-relaxed">
                                      {segment.character_description?.current_state}
                                    </p>
                                  </div>
                                  <div>
                                    <span className="text-xs text-void-500 uppercase tracking-wide">Voice Matching:</span>
                                    <p className="text-void-400 bg-void-900/50 p-2 rounded mt-1 text-xs leading-relaxed">
                                      {segment.character_description?.voice_matching}
                                    </p>
                                  </div>
                                </div>
                              </div>

                              {/* Scene Continuity */}
                              <div>
                                <h4 className="font-semibold text-void-200 mb-2">Scene</h4>
                                <div className="space-y-2">
                                  <div>
                                    <span className="text-xs text-void-500 uppercase tracking-wide">Environment:</span>
                                    <p className="text-void-400 bg-void-900/50 p-2 rounded mt-1 text-xs leading-relaxed">
                                      {segment.scene_continuity?.environment}
                                    </p>
                                  </div>
                                  <div>
                                    <span className="text-xs text-void-500 uppercase tracking-wide">Camera:</span>
                                    <p className="text-void-400 bg-void-900/50 p-2 rounded mt-1 text-xs leading-relaxed">
                                      {segment.scene_continuity?.camera_position} • {segment.scene_continuity?.camera_movement}
                                    </p>
                                  </div>
                                  <div>
                                    <span className="text-xs text-void-500 uppercase tracking-wide">Lighting:</span>
                                    <p className="text-void-400 bg-void-900/50 p-2 rounded mt-1 text-xs leading-relaxed">
                                      {segment.scene_continuity?.lighting_state}
                                    </p>
                                  </div>
                                </div>
                              </div>

                              {/* Synchronized Actions */}
                              <div>
                                <h4 className="font-semibold text-void-200 mb-2">Timeline</h4>
                                <div className="space-y-1.5">
                                  {Object.entries(segment.action_timeline?.synchronized_actions || {}).map(([time, action]) => (
                                    <div key={time} className="flex gap-3">
                                      <span className={`
                                        text-xs font-mono px-2 py-1 rounded
                                        ${accentColor === 'coral' 
                                          ? 'bg-coral-500/10 text-coral-400' 
                                          : 'bg-electric-500/10 text-electric-400'
                                        }
                                      `}>
                                        {time}
                                      </span>
                                      <p className="text-void-400 text-xs flex-1">
                                        {action}
                                      </p>
                                    </div>
                                  ))}
                                </div>
                              </div>

                              {/* Segment Info */}
                              <div className="pt-3 border-t border-void-800">
                                <div className="grid grid-cols-2 gap-3 text-xs">
                                  <div>
                                    <span className="text-void-500">Duration:</span>
                                    <span className="text-void-300 ml-2 font-medium">
                                      {segment.segment_info?.duration}
                                    </span>
                                  </div>
                                  <div>
                                    <span className="text-void-500">Location:</span>
                                    <span className="text-void-300 ml-2 font-medium">
                                      {segment.segment_info?.location}
                                    </span>
                                  </div>
                                </div>
                              </div>
                            </div>
                          </motion.div>
                        )}
                      </AnimatePresence>
                    </div>
                  );
                })}
              </div>
            </div>
          </motion.div>
        )}
      </AnimatePresence>
    </div>
  );
};