File size: 4,686 Bytes
67c8aca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { RefreshCw, CheckCircle, XCircle, BrainCircuit, ShieldCheck, TrendingDown, Target, Lightbulb } from 'lucide-react';
import ReactMarkdown from 'react-markdown';
import { DTIGauge, FeatureImportanceBar, ComparisonRadar } from './Charts';

export default function Dashboard({ result, onReset }) {
  const isApproved = result.prediction === 'Y';
  
  // Parse structured AI points
  const explanationPoints = result.explanation_text 
    ? result.explanation_text.split('@@POINT@@').filter(p => p.trim() !== '')
    : [];

  return (
    <div className="animate-in">
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '2rem' }}>
        <div className={`status-badge ${isApproved ? 'status-approved' : 'status-rejected'}`}>
          {isApproved ? <CheckCircle size={24} /> : <XCircle size={24} />}
          {isApproved ? 'Application Approved' : 'Action Required: Rejection'}
        </div>
        <button onClick={onReset} className="btn" style={{ background: 'white', color: 'var(--text-main)', border: '1px solid var(--border-color)', boxShadow: 'none' }}>
          <RefreshCw size={16} /> New Assessment
        </button>
      </div>

      {/* Top Metric Grid */}
      <div className="metric-grid">
        <div className="metric-tile">
          <span className="metric-label">Approval Confidence</span>
          <span className="metric-value" style={{ color: isApproved ? 'var(--success)' : 'var(--danger)' }}>
            {(result.confidence * 100).toFixed(0)}%
          </span>
        </div>
        <div className="metric-tile">
          <span className="metric-label">DTI Ratio</span>
          <span className="metric-value">{result.dti_ratio.toFixed(1)}%</span>
        </div>
        <div className="metric-tile">
          <span className="metric-label">Credit Level</span>
          <span className="metric-value">{result.credit_history === 1 ? 'High' : 'At-Risk'}</span>
        </div>
      </div>

      <div className="glass-card" style={{ marginBottom: '2rem' }}>
        <h2 style={{ marginBottom: '0.5rem', display: 'flex', alignItems: 'center', gap: '0.75rem', color: 'var(--primary)', fontWeight: '700' }}>
          <BrainCircuit size={28} />
          AI Advisor Narrative
        </h2>
        <p style={{ color: 'var(--text-muted)', marginBottom: '1.5rem', fontSize: '1rem' }}>
          Structured multi-point analysis from the Mistral Reasoning Engine.
        </p>
        
        <div className="narrative-grid">
          {explanationPoints.length > 0 ? (
            explanationPoints.map((point, index) => (
              <div key={index} className="narrative-sub-card">
                <div style={{ display: 'flex', gap: '1rem' }}>
                   <div style={{ color: 'var(--primary)', marginTop: '0.2rem' }}><Lightbulb size={20} /></div>
                   <div className="narrative-content">
                     <ReactMarkdown>{point.trim()}</ReactMarkdown>
                   </div>
                </div>
              </div>
            ))
          ) : (
            <div className="narrative-sub-card" style={{ gridColumn: '1 / -1' }}>
              <p>{result.explanation_text || "Gathering advisor narrative..."}</p>
            </div>
          )}
        </div>
        
        {!isApproved && result.optimized_suggestion && (
          <div className="ai-advice-box">
            <h3><Target size={20} /> Actionable Path to Approval</h3>
            <p style={{ fontSize: '1.1rem', color: '#4b5563' }}>{result.optimized_suggestion}</p>
          </div>
        )}
      </div>

      <div className="dashboard-layout">
        <div className="glass-card">
          <h3 style={{ marginBottom: '2rem', display: 'flex', alignItems: 'center', gap: '0.5rem', borderBottom: '1px solid var(--border-color)', paddingBottom: '1rem' }}>
            <ShieldCheck size={20} color="var(--success)" />
            Peer Comparison Radar
          </h3>
          <div style={{ height: '300px' }}>
            <ComparisonRadar userResults={result} />
          </div>
        </div>

        <div className="glass-card">
          <h3 style={{ marginBottom: '2rem', display: 'flex', alignItems: 'center', gap: '0.5rem', borderBottom: '1px solid var(--border-color)', paddingBottom: '1rem' }}>
            <TrendingDown size={20} color="var(--primary)" />
            Impact Vector Analysis
          </h3>
          <FeatureImportanceBar featuresJson={result.feature_importance_json} />
        </div>
      </div>
      
      <div style={{ textAlign: 'center', marginTop: '3rem', opacity: 0.6 }}>
         <DTIGauge dti={result.dti_ratio} />
      </div>
    </div>
  );
}