File size: 13,341 Bytes
654175d
 
4baacf3
654175d
 
4baacf3
654175d
c65aa31
654175d
4baacf3
 
654175d
c65aa31
654175d
 
c65aa31
654175d
4baacf3
654175d
 
 
 
 
 
 
 
 
4baacf3
654175d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
07273d8
654175d
 
07273d8
654175d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
07273d8
654175d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
07273d8
654175d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
07273d8
4baacf3
654175d
4baacf3
07273d8
654175d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4baacf3
654175d
 
 
c65aa31
654175d
 
 
 
 
 
 
 
 
 
c65aa31
654175d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c65aa31
 
654175d
07273d8
c65aa31
 
654175d
 
 
 
 
 
 
 
c65aa31
654175d
 
 
 
c65aa31
07273d8
654175d
 
 
c65aa31
654175d
4baacf3
 
654175d
 
 
 
 
9e82ecd
654175d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c65aa31
654175d
 
 
 
 
 
c65aa31
654175d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c65aa31
654175d
 
 
 
 
c65aa31
654175d
07273d8
654175d
 
c65aa31
 
654175d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c65aa31
654175d
 
 
 
 
 
 
 
 
 
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
from __future__ import annotations

import html
import json
from typing import Any

# ==========================================
# HELPER: ENTERPRISE REPORT RENDERER
# ==========================================

def render_plan_html(result: Any) -> str:
    """
    Renders the analysis payload into a High-Contrast Enterprise Grid.
    """
    # --- INTERNAL CSS FOR THE REPORT ---
    # (CSS remains unchanged to preserve the requested theme)
    css = """
    <style>
        /* FORCE ROBUST CONTAINER HEIGHT */
        .sec-report-wrapper {
            width: 100%;
            min-height: 70vh; /* Force container to take up significant screen space */
            display: flex;
            flex-direction: column;
        }

        .sec-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); /* Wider cards for better readability */
            gap: 20px;
            padding: 10px 0;
            flex-grow: 1; /* Allow grid to expand */
        }

        /* CARD STYLING */
        .sec-card {
            background-color: var(--bg-card);
            border: 1px solid var(--border-dim);
            border-left: 4px solid var(--arc-orange); /* Default tactical color */
            display: flex;
            flex-direction: column;
            position: relative;
            transition: border-color 0.2s;
        }
        .sec-card:hover {
            border-color: var(--arc-yellow);
            box-shadow: 0 4px 24px rgba(0,0,0,0.4);
        }

        /* HEADER */
        .sec-card-header {
            background: rgba(255,255,255,0.03);
            padding: 16px 20px;
            border-bottom: 1px solid var(--border-dim);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .sec-role-badge {
            font-size: 12px;
            font-weight: 700;
            color: var(--text-main);
            letter-spacing: 1px;
            text-transform: uppercase;
            opacity: 0.9;
        }
        
        /* BODY */
        .sec-card-body {
            padding: 20px;
            flex-grow: 1;
        }
        
        .sec-name {
            font-family: var(--font-header);
            font-size: 20px; /* Larger Name */
            font-weight: 700;
            color: var(--text-main);
            margin-bottom: 4px;
            letter-spacing: 0.5px;
        }
        .sec-id-tag {
            font-family: var(--font-mono);
            font-size: 12px;
            color: var(--arc-orange);
            margin-bottom: 20px;
            opacity: 1.0;
        }

        /* SKILL GAPS (Binary State) */
        .sec-skill-container {
            background: rgba(255, 42, 42, 0.08); /* Red tint */
            border: 1px dashed var(--arc-red);
            padding: 12px 16px;
            margin-bottom: 20px;
            border-radius: 4px;
        }
        .sec-skill-label {
            font-size: 12px;
            color: var(--arc-red);
            font-weight: 700;
            text-transform: uppercase;
            margin-bottom: 10px;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .sec-skill-tags {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
        }
        .sec-skill-tag {
            font-family: var(--font-mono);
            font-size: 12px;
            background: var(--bg-void);
            border: 1px solid var(--arc-red);
            color: var(--text-main);
            padding: 6px 10px;
            display: flex;
            align-items: center;
            gap: 6px;
        }
        .sec-skill-icon {
            width: 8px; height: 8px; background: var(--arc-red); border-radius: 50%;
        }

        /* TRAINING PLAN */
        .sec-plan-section {
            border-top: 1px solid var(--border-dim);
            padding-top: 16px;
        }
        .sec-section-title {
            font-size: 12px;
            color: var(--arc-yellow);
            text-transform: uppercase;
            letter-spacing: 1px;
            margin-bottom: 12px;
            font-weight: 700;
        }

        .sec-item {
            display: flex;
            background: var(--bg-panel);
            border-left: 3px solid var(--text-dim); 
            margin-bottom: 10px;
            padding: 12px;
            align-items: flex-start;
        }
        /* Cost Indicators */
        .inv-low { border-left-color: var(--arc-green); } 
        .inv-med { border-left-color: var(--arc-yellow); } 
        .inv-high { border-left-color: var(--arc-red); } 

        .sec-item-details { flex-grow: 1; }
        .sec-item-title { font-size: 14px; color: #fff; font-weight: 600; margin-bottom: 4px; line-height: 1.4;}
        .sec-item-meta { font-size: 12px; color: var(--text-main); font-family: var(--font-mono); opacity: 0.9; }
        
        /* STATS BAR */
        .sec-stats-bar {
            display: flex;
            gap: 20px;
            background: rgba(255,255,255,0.05);
            border: 1px solid var(--border-dim);
            padding: 12px 20px;
            margin-bottom: 20px;
            align-items: center;
        }
        .sec-stat-group {
            display: flex;
            flex-direction: column;
        }
        .sec-stat-label {
            font-size: 11px;
            color: var(--text-main);
            font-weight: 600;
            letter-spacing: 0.5px;
            text-transform: uppercase;
            opacity: 0.9;
        }
        .sec-stat-value {
            font-size: 18px;
            color: var(--text-main);
            font-weight: 700;
            font-family: var(--font-mono);
        }
        .sec-divider {
            width: 1px;
            height: 24px;
            background: var(--border-dim);
        }

        /* LOADING / ERROR STATES */
        .sec-status-offline { 
            color: var(--text-dim); 
            font-family: var(--font-mono); 
            font-size: 14px; 
            padding: 20px; 
            min-height: 70vh; /* Use VH to ensure it fills screen vertical space */
            display: flex;
            align-items: center;
            justify-content: center;
            background: rgba(255,255,255,0.01);
            border: 1px dashed var(--border-dim);
            flex-grow: 1;
        }
        .sec-terminal-text { 
            color: var(--arc-red); 
            font-family: var(--font-mono); 
            font-size: 14px; 
            padding: 20px;
            min-height: 70vh; /* Consistent height for error states */
        }
    </style>
    """

    if result is None:
        return f"{css}<div class='sec-report-wrapper'><div class='sec-status-offline'>// WAITING FOR ANALYSIS DATA</div></div>"

    # Ensure data is dict; handle string inputs gracefully
    data = result
    if not isinstance(data, dict):
        try:
            data = json.loads(str(result))
        except (json.JSONDecodeError, TypeError):
            # Fallback for non-JSON strings
            return f"{css}<div class='sec-report-wrapper'><div class='sec-terminal-text'>{html.escape(str(result))}</div></div>"

    project_name = html.escape(str(data.get("project_name", "UNDEFINED PROJECT")).upper())
    team = data.get("team", [])

    # --- CALCULATE AGGREGATE STATS ---
    total_cost = 0.0
    max_duration = 0.0
    
    for member in team:
        member_cost = 0.0
        member_duration = 0.0
        for plan in member.get("training_plan", []):
            try:
                member_cost += float(plan.get("cost", 0))
                member_duration += float(plan.get("duration_hours", 0))
            except (ValueError, TypeError):
                continue
        
        total_cost += member_cost
        # Parallel training assumption: Project duration is limited by the person with the longest plan
        if member_duration > max_duration:
            max_duration = member_duration

    # --- BUILD HTML ---
    html_parts = [css, "<div class='sec-report-wrapper'>"]

    # --- MAIN HEADER ---
    html_parts.append(f"""
    <div style="margin-bottom: 16px; padding: 0 4px; display:flex; flex-wrap: wrap; justify-content:space-between; align-items:flex-end; border-bottom: 1px solid var(--border-dim); padding-bottom: 12px; gap: 10px;">
        <div>
            <h2 style="margin:0; color:white; font-size:24px; letter-spacing: 0.5px;">CAPABILITY ANALYSIS REPORT</h2> 
            <div style="color:var(--arc-yellow); font-family:var(--font-mono); font-size: 14px; margin-top:6px;">PROJECT: {project_name}</div>
        </div>
        <div style="font-family: var(--font-mono); font-size: 12px; color: var(--text-main); text-align: right;">
            <div>STATUS: <span style="color:var(--arc-green)">ACTIVE</span></div>
            <div>HEADCOUNT: {len(team)}</div>
        </div>
    </div>
    """)

    # --- OVERALL STATS BAR ---
    html_parts.append(f"""
    <div class="sec-stats-bar">
        <div class="sec-stat-group">
            <div class="sec-stat-label">Total Budget</div>
            <div class="sec-stat-value" style="color: var(--arc-cyan);">${total_cost:,.2f}</div>
        </div>
        <div class="sec-divider"></div>
        <div class="sec-stat-group">
            <div class="sec-stat-label">Est. Timeline</div>
            <div class="sec-stat-value" style="color: var(--arc-orange);">{max_duration:.0f} HRS <span style="font-size:11px; color:var(--text-main); opacity:0.8;">(CONCURRENT)</span></div>
        </div>
        <div class="sec-divider"></div>
        <div class="sec-stat-group">
            <div class="sec-stat-label">Team Size</div>
            <div class="sec-stat-value">{len(team)}</div>
        </div>
    </div>
    """)

    html_parts.append("<div class='sec-grid'>")

    for member in team:
        name = html.escape(str(member.get("employee_name", "UNKNOWN")).upper())
        role = html.escape(str(member.get("role", "UNASSIGNED")).upper())
        
        # --- SKILL GAPS ---
        skills_html = ""
        gaps_list = member.get("skills_gaps", [])
        
        if gaps_list:
            skill_tags = ""
            for gap_data in gaps_list:
                skill_name = html.escape(gap_data.get("skill", "GENERIC"))
                skill_tags += f"""
                <div class="sec-skill-tag">
                    <div class="sec-skill-icon"></div>
                    {skill_name}
                </div>
                """
            
            skills_html = f"""
            <div class="sec-skill-container">
                <div class="sec-skill-label">⚠ SKILL GAP IDENTIFIED</div>
                <div class="sec-skill-tags">{skill_tags}</div>
            </div>
            """
        else:
            skills_html = """
            <div style="padding: 12px; border: 1px solid var(--arc-green); color: var(--arc-green); font-size: 12px; display:flex; align-items:center; gap:8px; margin-bottom:20px; border-radius:4px;">
                <span>✔</span> SKILLS VERIFIED. NO GAPS.
            </div>
            """

        # --- TRAINING PLAN ---
        training_html = ""
        for plan in member.get("training_plan", []):
            title = html.escape(plan.get("title", "Training Module"))
            cost = float(plan.get("cost", 0))
            hours = float(plan.get("duration_hours", 0))
            
            # Investment Level Logic
            inv_class = "inv-low"
            if cost > 50: inv_class = "inv-med"
            if cost > 200: inv_class = "inv-high"

            training_html += f"""
            <div class="sec-item {inv_class}">
                <div class="sec-item-details">
                    <div class="sec-item-title">{title}</div>
                    <div class="sec-item-meta">COST: ${cost} | DURATION: {hours} HRS</div>
                </div>
            </div>
            """
        
        if not training_html and gaps_list:
            training_html = "<div style='font-size:12px; color:var(--arc-red); padding: 4px 0;'>PENDING: CURRICULUM GENERATION REQUIRED</div>"
        elif not training_html:
            training_html = "<div style='font-size:12px; color:var(--text-main); opacity:0.9; padding: 4px 0;'>NO ACTION REQUIRED</div>"

        # Assemble Card
        # Create a faux Employee ID
        emp_hash = f"EMP-{hash(name) % 99999:05d}"
        
        card_html = f"""
        <div class="sec-card">
            <div class="sec-card-header">
                <div style="display:flex; align-items:center; gap:8px;">
                    <div style="width:8px; height:8px; background:var(--arc-orange);"></div>
                    <div class="sec-role-badge">{role}</div>
                </div>
            </div>
            <div class="sec-card-body">
                <div class="sec-name">{name}</div>
                <div class="sec-id-tag">{emp_hash}</div>
                
                {skills_html}

                <div class="sec-plan-section">
                    <div class="sec-section-title">RECOMMENDED TRAINING</div>
                    {training_html}
                </div>
            </div>
        </div>
        """
        html_parts.append(card_html)

    html_parts.append("</div>")
    html_parts.append("</div>") # Close sec-report-wrapper
    return "".join(html_parts)