File size: 12,128 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
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
import React, { useState } from 'react';
import { marked } from 'marked';
import {
  FileText, Shield, Layers, HelpCircle, HardDrive,
  Terminal, Download, Eye, Play, ListFilter,
  AlertTriangle, Network, ChevronDown, ChevronRight, Database
} from 'lucide-react';
import GraphViewer from './GraphViewer';
import RepositoryAssistant from './RepositoryAssistant';
import KnowledgeExplorer from './KnowledgeExplorer';
import { apiUrl } from '../api';

const TABS = [
  { id: 'report',      icon: <FileText size={15} />,      label: 'Intelligence Report' },
  { id: 'summary',     icon: <Play size={15} />,           label: 'Knowledge Summary' },
  { id: 'profile',     icon: <Layers size={15} />,         label: 'Repository Profile' },
  { id: 'graph',       icon: <Network size={15} />,        label: 'Architecture Graph' },
  { id: 'assistant',   icon: <HelpCircle size={15} />,     label: 'AI Assistant' },
  { id: 'knowledge',   icon: <Database size={15} />,       label: 'Knowledge Explorer' },
];

export default function Dashboard({ analysisResult }) {
  const [activeTab, setActiveTab] = useState('report');
  const [showFullJson, setShowFullJson] = useState(false);

  const { repo_id, project_name, data } = analysisResult;
  const { report, profile, summary, graph } = data;

  const renderedReportHtml = React.useMemo(() => {
    try { return { __html: marked.parse(report || '') }; }
    catch (e) { return { __html: `<p>Failed to render: ${e.message}</p>` }; }
  }, [report]);

  const getDownloadUrl = (type) => apiUrl(`/api/download/${repo_id}/${type}`);

  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: '1.25rem' }}>

      {/* ── Header Bar ── */}
      <div className="dashboard-header">
        <div>
          <h2 className="section-title" style={{ fontSize: '1.25rem', marginBottom: '0.5rem' }}>
            Intelligence Dashboard
          </h2>
          <div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap', alignItems: 'center' }}>
            <span className="repo-meta">
              <Layers size={13} style={{ color: 'var(--accent-teal)' }} />
              {project_name}
            </span>
            <span className="repo-meta">
              <Terminal size={13} style={{ color: 'var(--accent-indigo)' }} />
              {profile.architecture_pattern}
            </span>
          </div>
        </div>

        <div className="download-bar">
          {[
            ['report', 'Report.md'],
            ['profile', 'Profile.json'],
            ['summary', 'Summary.json'],
            ['graph', 'Graph.json'],
          ].map(([type, label]) => (
            <a key={type} href={getDownloadUrl(type)} download className="btn-secondary">
              <Download size={13} /> {label}
            </a>
          ))}
        </div>
      </div>

      {/* ── Tab Navigation ── */}
      <div className="dashboard-tabs">
        {TABS.map(t => (
          <button
            key={t.id}
            id={`tab-${t.id}`}
            className={`tab-btn ${activeTab === t.id ? 'active' : ''}`}
            onClick={() => setActiveTab(t.id)}
          >
            {t.icon} {t.label}
          </button>
        ))}
      </div>

      {/* ── Tab Content ── */}
      <div className="tab-pane">

        {/* ── REPORT ── */}
        {activeTab === 'report' && (
          <div className="card report-content" dangerouslySetInnerHTML={renderedReportHtml} />
        )}

        {/* ── SUMMARY ── */}
        {activeTab === 'summary' && (
          <div className="summary-grid">
            {/* Elevator pitch */}
            <div className="summary-card full-width">
              <div className="summary-title">
                <Eye size={18} style={{ color: 'var(--accent-teal)' }} /> Project Purpose
              </div>
              <p style={{
                fontSize: '1.05rem',
                color: 'var(--text-secondary)',
                fontStyle: 'italic',
                lineHeight: 1.7,
                borderLeft: '3px solid var(--accent-teal)',
                paddingLeft: '1rem',
              }}>
                "{summary.elevator_pitch}"
              </p>
            </div>

            {/* Core Features */}
            <div className="summary-card">
              <div className="summary-title">
                <Play size={16} style={{ color: 'var(--accent-green)' }} /> Core Features
              </div>
              <ul className="list-styled">
                {summary.core_features?.map((f, i) => (
                  <li key={i} className="list-item-styled">
                    <span className="list-item-icon">βœ“</span>
                    <span>{f}</span>
                  </li>
                ))}
              </ul>
            </div>

            {/* Workflows */}
            <div className="summary-card">
              <div className="summary-title">
                <ListFilter size={16} style={{ color: 'var(--accent-indigo)' }} /> User Workflows
              </div>
              <ul className="list-styled">
                {summary.main_workflows?.map((w, i) => (
                  <li key={i} className="list-item-styled">
                    <span className="list-item-icon">⚑</span>
                    <span>{w}</span>
                  </li>
                ))}
              </ul>
            </div>

            {/* Key Components */}
            <div className="summary-card">
              <div className="summary-title">
                <Layers size={16} style={{ color: 'var(--accent-purple)' }} /> Key Components
              </div>
              <ul className="list-styled">
                {summary.key_components?.map((c, i) => (
                  <li key={i} className="list-item-styled">
                    <span className="list-item-icon">βš™</span>
                    <span>{c}</span>
                  </li>
                ))}
              </ul>
            </div>

            {/* Risks */}
            <div className="summary-card">
              <div className="summary-title">
                <AlertTriangle size={16} style={{ color: 'var(--accent-amber)' }} /> Architectural Risks
              </div>
              <ul className="list-styled">
                {summary.key_risks?.map((r, i) => (
                  <li key={i} className="list-item-styled">
                    <span className="list-item-icon risk">⚠</span>
                    <span>{r}</span>
                  </li>
                ))}
              </ul>
            </div>

            {/* Start Points */}
            <div className="summary-card full-width">
              <div className="summary-title">
                <HelpCircle size={16} style={{ color: 'var(--accent-teal)' }} /> Where to Start Reading Code
              </div>
              <div style={{ display: 'flex', flexWrap: 'wrap', gap: '0.5rem', marginTop: '0.25rem' }}>
                {summary.developer_start_points?.map((pt, i) => (
                  <div key={i} className="module-chip" style={{ color: 'var(--accent-teal-dk)' }}>
                    {pt}
                  </div>
                ))}
              </div>
            </div>
          </div>
        )}

        {/* ── PROFILE ── */}
        {activeTab === 'profile' && (
          <div style={{ display: 'flex', flexDirection: 'column', gap: '1.5rem' }}>
            <div className="tech-cards-grid">

              <div className="tech-card">
                <div className="tech-card-header"><Terminal size={16} /> Languages</div>
                <div className="badge-container">
                  {profile.languages?.map((l, i) => (
                    <span key={i} className="tech-badge language">{l}</span>
                  ))}
                </div>
              </div>

              <div className="tech-card">
                <div className="tech-card-header"><Layers size={16} /> Frameworks</div>
                <div className="badge-container">
                  {profile.frameworks?.map((f, i) => (
                    <span key={i} className="tech-badge">{f}</span>
                  ))}
                </div>
              </div>

              <div className="tech-card">
                <div className="tech-card-header"><HardDrive size={16} /> Databases</div>
                <div className="badge-container">
                  {profile.databases?.map((d, i) => (
                    <span key={i} className="tech-badge db">{d}</span>
                  ))}
                </div>
              </div>

              <div className="tech-card">
                <div className="tech-card-header"><Shield size={16} /> Security & Auth</div>
                <div className="badge-container">
                  {profile.authentication_methods?.map((a, i) => (
                    <span key={i} className="tech-badge" style={{
                      color: 'var(--accent-rose)',
                      background: '#FFF1F2',
                      borderColor: '#FECDD3',
                    }}>{a}</span>
                  ))}
                </div>
              </div>

            </div>

            <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '1.25rem' }}>
              <div className="card" style={{ padding: '1.5rem' }}>
                <h4 style={{
                  fontFamily: 'var(--font-display)', marginBottom: '1rem',
                  fontSize: '0.9rem', color: 'var(--text-primary)', fontWeight: 700
                }}>API Endpoints</h4>
                <div style={{ maxHeight: 280, overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: '0.35rem' }}>
                  {profile.api_endpoints?.map((ep, i) => (
                    <div key={i} className="api-endpoint-item">{ep}</div>
                  ))}
                </div>
              </div>

              <div className="card" style={{ padding: '1.5rem' }}>
                <h4 style={{
                  fontFamily: 'var(--font-display)', marginBottom: '1rem',
                  fontSize: '0.9rem', color: 'var(--text-primary)', fontWeight: 700
                }}>Core Modules</h4>
                <div style={{ display: 'flex', flexWrap: 'wrap', gap: '0.4rem', maxHeight: 280, overflowY: 'auto' }}>
                  {profile.major_modules?.map((m, i) => (
                    <span key={i} className="module-chip">{m}</span>
                  ))}
                </div>
              </div>
            </div>

            <div className="card" style={{ padding: '1.5rem' }}>
              <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: showFullJson ? '1rem' : 0 }}>
                <h4 style={{ fontFamily: 'var(--font-display)', fontSize: '0.9rem', color: 'var(--text-primary)', fontWeight: 700 }}>
                  Raw repository_profile.json
                </h4>
                <button className="btn-secondary" onClick={() => setShowFullJson(!showFullJson)}>
                  {showFullJson ? <ChevronDown size={14} /> : <ChevronRight size={14} />}
                  {showFullJson ? 'Hide' : 'Show'} JSON
                </button>
              </div>
              {showFullJson && (
                <pre className="json-block">{JSON.stringify(profile, null, 2)}</pre>
              )}
            </div>
          </div>
        )}

        {/* ── GRAPH ── */}
        {activeTab === 'graph' && (
          <div className="card" style={{ padding: '1.5rem' }}>
            <h3 style={{ fontFamily: 'var(--font-display)', fontSize: '1.1rem', marginBottom: '1rem', color: 'var(--text-primary)' }}>
              Code Topology Graph
            </h3>
            <GraphViewer graphData={graph} />
          </div>
        )}

        {/* ── AI ASSISTANT ── */}
        {activeTab === 'assistant' && (
          <RepositoryAssistant repo_id={repo_id} apiKey={analysisResult.apiKey} />
        )}

        {/* ── KNOWLEDGE EXPLORER ── */}
        {activeTab === 'knowledge' && (
          <KnowledgeExplorer repo_id={repo_id} apiKey={analysisResult.apiKey} />
        )}

      </div>
    </div>
  );
}