File size: 8,914 Bytes
edb7d3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { useState } from 'react'
import { X, Download, CheckCircle2 } from 'lucide-react'
import clsx from 'clsx'
import { downloadClip } from '../utils/api'

/**
 * Export modal for downloading clips
 * Props: { isOpen, onClose, clip, jobId }
 */
function ExportModal({ isOpen, onClose, clip, jobId }) {
  const [format, setFormat] = useState('mp4')
  const [quality, setQuality] = useState('1080p')
  const [captions, setCaptions] = useState('burned')
  const [watermark, setWatermark] = useState(true)
  const [isExporting, setIsExporting] = useState(false)
  const [exportComplete, setExportComplete] = useState(false)

  if (!isOpen) return null

  const formats = [
    { id: 'mp4', label: 'MP4', codec: 'H.264' },
    { id: 'mov', label: 'MOV', codec: 'ProRes' },
    { id: 'webm', label: 'WebM', codec: 'VP9' },
  ]

  const qualities = [
    { id: '4k', label: '4K (2160p)', size: '~450MB' },
    { id: '1080p', label: '1080p (Full HD)', size: '~150MB' },
    { id: '720p', label: '720p (HD)', size: '~65MB' },
    { id: '480p', label: '480p (Mobile)', size: '~25MB' },
  ]

  const handleExport = async () => {
    setIsExporting(true)
    try {
      const blob = await downloadClip(jobId, clip.id, {
        format,
        quality,
        includeCaptions: captions !== 'none',
        includeWatermark: watermark,
      })

      // Create download link
      const url = window.URL.createObjectURL(blob)
      const link = document.createElement('a')
      link.href = url
      link.download = `${clip.title || 'clip'}.${format}`
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
      window.URL.revokeObjectURL(url)

      setExportComplete(true)
      setTimeout(() => {
        onClose()
        setExportComplete(false)
      }, 2000)
    } catch (error) {
      console.error('Export failed:', error)
      alert('Export failed. Please try again.')
    } finally {
      setIsExporting(false)
    }
  }

  return (
    <>
      {/* Overlay */}
      <div
        className="fixed inset-0 bg-black/60 backdrop-blur-sm z-40 animate-fade-in"
        onClick={onClose}
      />

      {/* Modal */}
      <div className="fixed inset-0 z-50 flex items-center justify-center p-4 animate-scale-in">
        <div className="glass-lg max-w-2xl w-full rounded-3xl overflow-hidden">
          {/* Header */}
          <div className="flex items-center justify-between p-8 border-b border-white/10">
            <h2 className="text-2xl font-bold text-white">Export Clip</h2>
            <button
              onClick={onClose}
              className="p-2 hover:bg-white/10 rounded-lg transition-colors"
            >
              <X className="w-5 h-5 text-white/70" />
            </button>
          </div>

          <div className="p-8 space-y-8">
            {/* Format Selection */}
            <div>
              <label className="block text-sm font-semibold text-white mb-4">File Format</label>
              <div className="grid grid-cols-3 gap-3">
                {formats.map((fmt) => (
                  <button
                    key={fmt.id}
                    onClick={() => setFormat(fmt.id)}
                    className={clsx(
                      'p-4 rounded-xl transition-all text-center',
                      format === fmt.id
                        ? 'glass-lg bg-primary-500/20 border-primary-500/50'
                        : 'glass hover:bg-white/10'
                    )}
                  >
                    <p className="font-bold text-lg text-white">{fmt.label}</p>
                    <p className="text-xs text-white/60 mt-1">{fmt.codec}</p>
                  </button>
                ))}
              </div>
            </div>

            {/* Quality Selection */}
            <div>
              <label className="block text-sm font-semibold text-white mb-4">Quality</label>
              <div className="space-y-2">
                {qualities.map((q) => (
                  <button
                    key={q.id}
                    onClick={() => setQuality(q.id)}
                    className={clsx(
                      'w-full p-4 rounded-lg transition-all flex items-center justify-between',
                      quality === q.id
                        ? 'glass-lg bg-primary-500/20 border-primary-500/50'
                        : 'glass hover:bg-white/10'
                    )}
                  >
                    <div className="text-left">
                      <p className="font-semibold text-white">{q.label}</p>
                      <p className="text-xs text-white/60">{q.size}</p>
                    </div>
                    {quality === q.id && (
                      <CheckCircle2 className="w-5 h-5 text-primary-500" />
                    )}
                  </button>
                ))}
              </div>
            </div>

            {/* Captions */}
            <div>
              <label className="block text-sm font-semibold text-white mb-4">Captions</label>
              <div className="grid grid-cols-3 gap-3">
                {[
                  { id: 'burned', label: 'Burned-In' },
                  { id: 'srt', label: 'Separate SRT' },
                  { id: 'none', label: 'None' },
                ].map((opt) => (
                  <button
                    key={opt.id}
                    onClick={() => setCaptions(opt.id)}
                    className={clsx(
                      'p-4 rounded-xl font-semibold transition-all',
                      captions === opt.id
                        ? 'glass-lg bg-primary-500/20 border-primary-500/50 text-white'
                        : 'glass hover:bg-white/10 text-white/70'
                    )}
                  >
                    {opt.label}
                  </button>
                ))}
              </div>
            </div>

            {/* Watermark */}
            <label className="flex items-center gap-4 p-4 glass rounded-xl cursor-pointer hover:bg-white/10 transition-colors">
              <input
                type="checkbox"
                checked={watermark}
                onChange={(e) => setWatermark(e.target.checked)}
                className="w-5 h-5 rounded accent-primary-500 cursor-pointer"
              />
              <div>
                <p className="font-semibold text-white">Include Watermark</p>
                <p className="text-sm text-white/60">Adds your brand watermark to the clip</p>
              </div>
            </label>

            {/* File Size Estimate */}
            <div className="glass-lg p-6 rounded-2xl bg-primary-500/10 border border-primary-500/30">
              <div className="flex items-center justify-between">
                <div>
                  <p className="text-sm font-semibold text-white">Estimated File Size</p>
                  <p className="text-xs text-white/60 mt-1">Based on selected quality and format</p>
                </div>
                <p className="text-2xl font-bold text-primary-500">
                  {qualities.find((q) => q.id === quality)?.size}
                </p>
              </div>
            </div>

            {/* Export Complete State */}
            {exportComplete && (
              <div className="glass-lg p-6 rounded-2xl bg-green-500/10 border border-green-500/30 flex items-center gap-4">
                <CheckCircle2 className="w-6 h-6 text-green-400 flex-shrink-0" />
                <div>
                  <p className="font-semibold text-green-400">Export Complete!</p>
                  <p className="text-sm text-green-400/70">Your clip is downloading...</p>
                </div>
              </div>
            )}

            {/* Actions */}
            <div className="flex gap-3 pt-4">
              <button
                onClick={onClose}
                disabled={isExporting}
                className="btn-secondary-lg flex-1 disabled:opacity-50"
              >
                Cancel
              </button>
              <button
                onClick={handleExport}
                disabled={isExporting || exportComplete}
                className="btn-primary-lg flex-1 flex items-center justify-center gap-2 disabled:opacity-50"
              >
                {isExporting ? (
                  <>
                    <div className="w-4 h-4 border-2 border-white/20 border-t-white rounded-full animate-spin" />
                    Exporting...
                  </>
                ) : exportComplete ? (
                  <>
                    <CheckCircle2 className="w-4 h-4" />
                    Done!
                  </>
                ) : (
                  <>
                    <Download className="w-4 h-4" />
                    Export Clip
                  </>
                )}
              </button>
            </div>
          </div>
        </div>
      </div>
    </>
  )
}

export default ExportModal