File size: 10,235 Bytes
7e2f74d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { useState, useRef } from 'react';
import {
  GitBranch, UploadCloud, Link2, Lock, FileArchive,
  Cpu, Sparkles, ArrowRight
} from 'lucide-react';

const EXAMPLE_REPOS = [
  'https://github.com/pallets/flask',
  'https://github.com/tiangolo/fastapi',
  'https://github.com/django/django',
];

export default function InputForm({ onSubmit, loading }) {
  const [inputType, setInputType] = useState('url');
  const [repoUrl, setRepoUrl] = useState('');
  const [token, setToken] = useState('');
  const [apiKey, setApiKey] = useState('');
  const [zipFile, setZipFile] = useState(null);
  const [dragActive, setDragActive] = useState(false);
  const fileInputRef = useRef(null);

  const handleDrag = (e) => {
    e.preventDefault();
    e.stopPropagation();
    setDragActive(e.type === 'dragenter' || e.type === 'dragover');
  };

  const handleDrop = (e) => {
    e.preventDefault();
    e.stopPropagation();
    setDragActive(false);
    const file = e.dataTransfer.files?.[0];
    if (file?.name.endsWith('.zip')) setZipFile(file);
    else if (file) alert('Only .zip archives are supported.');
  };

  const handleFileChange = (e) => {
    const file = e.target.files?.[0];
    if (file?.name.endsWith('.zip')) setZipFile(file);
    else if (file) alert('Only .zip archives are supported.');
  };

  const handleSubmit = (e) => {
    e.preventDefault();
    if (inputType === 'url') {
      if (!repoUrl.trim()) return;
      onSubmit({ type: 'url', url: repoUrl.trim(), token, apiKey: apiKey.trim() });
    } else {
      if (!zipFile) return;
      onSubmit({ type: 'zip', file: zipFile, apiKey: apiKey.trim() });
    }
  };

  const canSubmit = inputType === 'url' ? !!repoUrl.trim() : !!zipFile;

  return (
    <div className="input-section">
      {/* Hero */}
      <div style={{ textAlign: 'center', marginBottom: '2.5rem' }}>
        <div style={{
          display: 'inline-flex',
          alignItems: 'center',
          gap: '0.5rem',
          background: '#E6F7F7',
          border: '1px solid var(--accent-teal-lt)',
          borderRadius: 'var(--radius-full)',
          padding: '0.3rem 0.9rem',
          fontSize: '0.78rem',
          fontWeight: 600,
          color: 'var(--accent-teal-dk)',
          marginBottom: '1.25rem',
        }}>
          <Sparkles size={12} />
          Powered by Gemini 2.5 Flash + RAG
        </div>
        <h1 className="section-title" style={{ fontSize: '2rem', lineHeight: 1.2, marginBottom: '0.75rem' }}>
          Understand any codebase<br />in seconds
        </h1>
        <p className="section-desc" style={{ maxWidth: '480px', margin: '0 auto' }}>
          Analyze repositories, map architecture, extract APIs, and build a semantic knowledge
          base ready for AI agents β€” no setup required.
        </p>
      </div>

      {/* Card */}
      <div className="card" style={{ padding: '2rem' }}>
        {/* Input Type Toggle */}
        <div className="dashboard-tabs" style={{ marginBottom: '1.75rem' }}>
          <button
            type="button"
            className={`tab-btn ${inputType === 'url' ? 'active' : ''}`}
            onClick={() => setInputType('url')}
          >
            <Link2 size={15} /> GitHub URL
          </button>
          <button
            type="button"
            className={`tab-btn ${inputType === 'zip' ? 'active' : ''}`}
            onClick={() => setInputType('zip')}
          >
            <FileArchive size={15} /> Upload ZIP
          </button>
        </div>

        <form onSubmit={handleSubmit}>
          {inputType === 'url' ? (
            <>
              <div className="form-group">
                <label className="form-label">GitHub Repository URL</label>
                <div className="input-wrapper">
                  <GitBranch className="input-icon" size={17} />
                  <input
                    type="url"
                    required
                    className="form-input"
                    placeholder="https://github.com/owner/repository"
                    value={repoUrl}
                    onChange={e => setRepoUrl(e.target.value)}
                    disabled={loading}
                    id="repo-url-input"
                  />
                </div>
              </div>

              <div className="form-group">
                <label className="form-label">
                  GitHub Personal Access Token
                  <span style={{ textTransform: 'none', color: 'var(--text-muted)', marginLeft: '0.5rem', fontWeight: 400 }}>
                    (required for private repos)
                  </span>
                </label>
                <div className="input-wrapper">
                  <Lock className="input-icon" size={17} />
                  <input
                    type="password"
                    className="form-input"
                    placeholder="ghp_xxxxxxxxxxxxxxxx"
                    value={token}
                    onChange={e => setToken(e.target.value)}
                    disabled={loading}
                    id="github-token-input"
                  />
                </div>
              </div>

              <div className="form-group">
                <label className="form-label">
                  Gemini API Key
                  <span style={{ textTransform: 'none', color: 'var(--text-muted)', marginLeft: '0.5rem', fontWeight: 400 }}>
                    (optional, useful if the server key is rate-limited)
                  </span>
                </label>
                <div className="input-wrapper">
                  <Cpu className="input-icon" size={17} />
                  <input
                    type="password"
                    className="form-input"
                    placeholder="Paste your Gemini API key"
                    value={apiKey}
                    onChange={e => setApiKey(e.target.value)}
                    disabled={loading}
                    id="gemini-api-key-input"
                  />
                </div>
              </div>

              {/* Example repos */}
              <div style={{ marginBottom: '1.5rem' }}>
                <div className="form-label" style={{ marginBottom: '0.5rem' }}>Try an example</div>
                <div style={{ display: 'flex', flexWrap: 'wrap', gap: '0.5rem' }}>
                  {EXAMPLE_REPOS.map(url => (
                    <button
                      key={url}
                      type="button"
                      className="btn-secondary"
                      style={{ fontSize: '0.75rem', padding: '0.3rem 0.7rem' }}
                      onClick={() => setRepoUrl(url)}
                    >
                      {url.split('/').slice(-2).join('/')}
                    </button>
                  ))}
                </div>
              </div>
            </>
          ) : (
            <div className="form-group">
              <label className="form-label">Upload ZIP Archive</label>
              <div
                className={`drag-drop-area ${dragActive ? 'drag-active' : ''}`}
                onDragEnter={handleDrag}
                onDragOver={handleDrag}
                onDragLeave={handleDrag}
                onDrop={handleDrop}
                onClick={() => fileInputRef.current?.click()}
                id="zip-drop-zone"
              >
                <input
                  ref={fileInputRef}
                  type="file"
                  style={{ display: 'none' }}
                  accept=".zip"
                  onChange={handleFileChange}
                  disabled={loading}
                />
                <UploadCloud size={36} className="upload-icon" />
                {zipFile ? (
                  <div>
                    <p style={{ fontWeight: 600, color: 'var(--accent-teal-dk)' }}>{zipFile.name}</p>
                    <p style={{ fontSize: '0.8rem', color: 'var(--text-muted)', marginTop: '0.25rem' }}>
                      {(zipFile.size / (1024 * 1024)).toFixed(2)} MB Β· Click to change
                    </p>
                  </div>
                ) : (
                  <div>
                    <p style={{ fontWeight: 600, color: 'var(--text-primary)' }}>
                      Drop your .zip file here
                    </p>
                    <p style={{ fontSize: '0.8rem', color: 'var(--text-muted)', marginTop: '0.25rem' }}>
                      or click to browse files
                    </p>
                  </div>
                )}
              </div>
            </div>
          )}

          <button
            id="submit-analysis-btn"
            className="btn-primary"
            type="submit"
            disabled={loading || !canSubmit}
          >
            {loading ? (
              <>
                <div className="spinner" style={{ width: 16, height: 16, borderWidth: 2, margin: 0 }} />
                Analyzing...
              </>
            ) : (
              <>Run Intelligence Analysis <ArrowRight size={16} /></>
            )}
          </button>
        </form>
      </div>

      {/* Features strip */}
      <div style={{
        display: 'grid',
        gridTemplateColumns: 'repeat(3, 1fr)',
        gap: '1rem',
        marginTop: '1.5rem',
      }}>
        {[
          { icon: 'πŸ—', title: 'Architecture Map', desc: 'Auto-detect patterns, entry points, and data flows' },
          { icon: 'πŸ”', title: 'Semantic Search', desc: 'RAG-powered search across indexed code knowledge' },
          { icon: 'πŸ€–', title: 'AI Agents', desc: 'Multi-agent Q&A with confidence scoring' },
        ].map(f => (
          <div key={f.title} style={{
            background: 'var(--bg-muted)',
            border: '1px solid var(--border-color)',
            borderRadius: 'var(--radius-lg)',
            padding: '1rem',
            textAlign: 'center',
          }}>
            <div style={{ fontSize: '1.5rem', marginBottom: '0.4rem' }}>{f.icon}</div>
            <div style={{ fontWeight: 600, fontSize: '0.82rem', color: 'var(--text-primary)', marginBottom: '0.25rem' }}>{f.title}</div>
            <div style={{ fontSize: '0.74rem', color: 'var(--text-muted)', lineHeight: 1.4 }}>{f.desc}</div>
          </div>
        ))}
      </div>
    </div>
  );
}