File size: 27,657 Bytes
20e666e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
// components/LLMComparisonDashboard.jsx

"use client";

import React, { useState, useMemo } from "react";
import {
  getScoreBadgeColor,
  formatDisplayKey, // Use this for displaying snake_case keys nicely
  getMetricTooltip,
  getEquityIndicatorStyle, // Use this for Max Equity Gap status
} from "../lib/utils"; // Adjust path as needed
import TaskPerformance from "./TaskPerformance";
import DemographicAnalysis from "./DemographicAnalysis";
import MetricsBreakdown from "./MetricsBreakdown";
import About from "./About";
import { Tooltip } from "./Tooltip"; // Assuming this is your Tooltip component

// Helper component for info tooltips (assuming it exists and works)
const InfoTooltip = ({ text }) => {
  const [isVisible, setIsVisible] = useState(false);
  return (
    <div className="relative inline-block ml-1 align-middle">
      <button
        className="text-gray-400 hover:text-gray-600 focus:outline-none"
        onMouseEnter={() => setIsVisible(true)}
        onMouseLeave={() => setIsVisible(false)}
        onClick={(e) => {
          e.stopPropagation();
          setIsVisible(!isVisible);
        }}
        aria-label="Info"
      >
        <svg
          xmlns="http://www.w3.org/2000/svg"
          className="h-4 w-4"
          viewBox="0 0 20 20"
          fill="currentColor"
        >
          <path
            fillRule="evenodd"
            d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z"
            clipRule="evenodd"
          />
        </svg>
      </button>
      {isVisible && (
        <div className="absolute z-10 w-64 p-2 bg-white border rounded shadow-lg text-xs text-gray-700 -translate-x-1/2 left-1/2 mt-1 normal-case">
          {text}
        </div>
      )}
    </div>
  );
};

// Main dashboard component
const LLMComparisonDashboard = ({ data: processedData }) => {
  const [activeTab, setActiveTab] = useState("overview");
  const [topPerformersView, setTopPerformersView] = useState("high-level");

  // Destructure data - top-level keys are camelCase
  // Nested rawData and equityAnalysis retain original snake_case keys
  const {
    models: rankedModels = [], // This is overallRankingProcessed with camelCase keys
    metricsData = { highLevelCategories: {}, lowLevelMetrics: {} }, // Title Case keys inside
    radarData = [],
    overviewCardData = {}, // camelCase keys inside expected
    rawData = {
      // camelCase keys for objects, snake_case keys inside those objects
      taskLevelPerformance: {},
      mrpDemographics: {},
      demographicOptions: {},
      availableMetrics: [], // Title Case
      tasks: [],
      taskCategories: {},
      taskMetrics: [], // Title Case
      taskMetricsSnake: [], // snake_case
      taskCategoryMap: {},
    },
    bestPerCategory = {}, // Title Case keys
    bestPerMetric = {}, // Title Case keys
    equityAnalysis = {
      // Original snake_case keys
      all_equity_gaps: [],
      model_max_effect_gaps: {},
      universal_issues: [],
      assessment_method: {},
      demographic_variation_stats: {},
    },
    metadata = {}, // Original keys
  } = processedData || {};

  // NEW: Helper function to get color for Max Equity Gap bubble
  const getEquityGapBadgeColor = (model) => {
    const isConcern = model.maxEffectConcernFlag;
    const isSignificant = model.maxEffectSignificant;
    const effectSizeClass = model.maxEffectSizeClass;
    const isLargeEffect = effectSizeClass === "Large";

    if (isConcern && isSignificant && isLargeEffect) {
      return "bg-red-100 text-red-800"; // Equity Concern
    }
    if (isLargeEffect) {
      return "bg-yellow-100 text-yellow-800"; // Large Effect
    }
    if (isSignificant) {
      return "bg-blue-100 text-blue-800"; // Significant
    }
    return "bg-gray-100 text-gray-800"; // No concern
  };

  // UPDATED: Render cell for Max Equity Gap column with bubble design
  const renderMaxEquityGapCell = (model) => {
    // model object has camelCase keys
    const gapValue = model.maxEffectGap;
    const isConcern = model.maxEffectConcernFlag;
    const significanceStatus = model.maxEffectSignificant;
    const pValue = model.maxEffectPValue;
    const effectSizeClass = model.maxEffectSizeClass;
    const isLargeEffect = effectSizeClass === "Large";
    // Access nested details using original snake_case keys
    const gapDetails = model.maxEffectGapDetails || {};
    const ciLower = gapDetails.gap_confidence_interval_95_lower;
    const ciUpper = gapDetails.gap_confidence_interval_95_upper;

    const displayValue =
      typeof gapValue === "number" ? gapValue.toFixed(1) : "N/A";
    if (displayValue === "N/A")
      return <span className="text-xs text-gray-500">N/A</span>;

    const indicator = getEquityIndicatorStyle(
      isConcern,
      isLargeEffect,
      significanceStatus,
      pValue,
      effectSizeClass
    );
    let fullTooltipContent = indicator.tooltip;
    if (typeof ciLower === "number" && typeof ciUpper === "number") {
      fullTooltipContent += `\n95% CI: [${ciLower.toFixed(
        1
      )}, ${ciUpper.toFixed(1)}]`;
    } else {
      fullTooltipContent += `\n95% CI: N/A`;
    }

    return (
      <Tooltip
        content={
          <div className="whitespace-pre-line">{fullTooltipContent}</div>
        }
      >
        <span
          className={`px-2 py-0.5 rounded-full text-xs font-medium ${getEquityGapBadgeColor(
            model
          )}`}
        >
          {displayValue}
        </span>
      </Tooltip>
    );
  };

  // NEW: Helper for equity concerns percentage badge color
  const getEquityConcernBadgeColor = (percentage) => {
    if (percentage === null || percentage === undefined)
      return "bg-gray-100 text-gray-800";
    if (percentage === 0) return "bg-green-100 text-green-800";
    if (percentage <= 2.5) return "bg-blue-100 text-blue-800";
    if (percentage <= 5) return "bg-yellow-100 text-yellow-800";
    return "bg-red-100 text-red-800";
  };

  return (
    <div className="max-w-7xl mx-auto p-4 bg-white">
      {/* Header */}
      <div className="relative mb-6 overflow-hidden">
        <div className="absolute inset-0 bg-gradient-to-br from-blue-50 to-sky-50 opacity-70"></div>
        <div className="relative max-w-5xl mx-auto px-6 py-6">
          <div className="text-center">
            <h1 className="text-4xl font-bold mb-2 tracking-narrow text-blue-700">
              Prolific's AI User Experience Leaderboard
            </h1>

            <p className="text-gray-600 max-w-4xl mx-auto">
              A benchmark assessing how well language models handle real-world
              tasks based on user experiences.
            </p>
          </div>
        </div>
      </div>
      {/* Tab Buttons */}
      <div className="flex flex-wrap mb-6 border-b">
        {[
          "overview",
          "metrics-breakdown",
          "task-performance",
          "demographic-analysis",
          "about",
        ].map((tab) => (
          <button
            key={tab}
            className={`px-4 py-2 font-medium capitalize ${
              activeTab === tab
                ? "text-blue-600 border-b-2 border-blue-600"
                : "text-gray-500 hover:text-gray-700"
            }`}
            onClick={() => setActiveTab(tab)}
          >
            {" "}
            {tab.replace("-", " ")}{" "}
          </button>
        ))}
      </div>
      {/* Overview Tab */}
      {activeTab === "overview" && (
        <div>
          {/* Overall Rankings Card */}
          <div className="mb-6 border rounded-lg overflow-hidden shadow-sm">
            <div className="px-4 py-3 bg-gray-50 border-b">
              <h2 className="text-xl font-semibold text-gray-800">
                Overall Model Rankings
              </h2>
            </div>
            <div className="p-4">
              <div className="overflow-x-auto">
                <table className="w-full min-w-[850px] table-auto divide-y divide-gray-200">
                  <thead>
                    <tr className="bg-gray-50">
                      <th className="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider w-12">
                        Rank
                      </th>
                      <th className="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider w-48">
                        Model
                      </th>
                      <th className="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider w-28">
                        <span>Overall Score</span>
                      </th>
                      <th className="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider w-24">
                        <span>Overall SD</span>
                      </th>
                      <th className="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider w-32">
                        <span>Max Equity Gap</span>
                      </th>
                      <th className="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider w-38">
                        <span>Max Gap Area</span>
                      </th>
                      <th className="px-3 py-2 text-center text-xs font-medium text-gray-500 uppercase tracking-wider w-36">
                        <span>Equity Concerns</span>
                      </th>
                      <th className="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider w-32">
                        <span>User Retention</span>
                      </th>
                    </tr>
                  </thead>
                  <tbody className="divide-y divide-gray-200">
                    {/* Use camelCase model object from rankedModels */}
                    {rankedModels.map((model) => (
                      <tr key={model.model} className="hover:bg-gray-50">
                        <td className="px-3 py-3 text-sm font-medium text-gray-900">
                          {model.rank}
                        </td>
                        <td className="px-3 py-3">
                          <div className="flex items-center">
                            <div
                              className="w-3 h-3 rounded-full mr-2 flex-shrink-0"
                              style={{ backgroundColor: model.color }}
                            ></div>
                            <span className="text-sm font-medium text-gray-900">
                              {model.model}
                            </span>
                          </div>
                        </td>
                        <td className="px-3 py-3 text-sm font-semibold text-gray-800">
                          {model.overallScore !== null
                            ? model.overallScore.toFixed(1)
                            : "N/A"}
                        </td>
                        <td className="px-3 py-3 text-sm text-gray-600">
                          {model.stdDevAcrossCats !== "N/A" &&
                          model.stdDevAcrossCats !== null
                            ? `± ${Number(model.stdDevAcrossCats).toFixed(1)}`
                            : "N/A"}
                        </td>
                        <td className="px-3 py-3 text-sm">
                          {renderMaxEquityGapCell(model)}
                        </td>
                        <td className="px-3 py-3">
                          {model.maxEffectFactor &&
                          model.maxEffectFactor !== "N/A" ? (
                            <div className="flex flex-col">
                              <span className="text-xs font-medium text-gray-900">
                                {formatDisplayKey(model.maxEffectFactor)}
                              </span>
                              <span className="text-xs text-gray-500">
                                {formatDisplayKey(model.maxEffectCategory)}
                              </span>
                            </div>
                          ) : (
                            <span className="text-xs text-gray-500">N/A</span>
                          )}
                        </td>
                        <td className="px-3 py-3 text-sm text-center">
                          {model.equityConcernPercentage !== null ? (
                            <span>
                              {model.equityConcernPercentage.toFixed(1)}%
                            </span>
                          ) : (
                            <span className="text-xs text-gray-500">N/A</span>
                          )}
                        </td>
                        <td className="px-3 py-3 text-sm">
                          {model.repeatUsageScore !== null ? (
                            <span
                              className={`px-2 py-0.5 rounded-full text-xs font-medium ${getScoreBadgeColor(
                                model.repeatUsageScore
                              )}`}
                            >
                              {model.repeatUsageScore.toFixed(1)}%
                            </span>
                          ) : (
                            <span className="text-xs text-gray-500">N/A</span>
                          )}
                        </td>
                      </tr>
                    ))}
                  </tbody>
                </table>
              </div>
              {/* UPDATED: Vertical list for column descriptions with detailed info */}
              <div className="mt-4 pt-3 border-t border-gray-200 text-xs text-gray-600">
                {/* Column descriptions in vertical list */}
                <div className="mb-2">
                  <div>
                    <span className="font-semibold">Overall Score:</span> Avg.
                    score across high-level categories
                  </div>
                  <div>
                    <span className="font-semibold">Overall SD:</span> Standard
                    deviation across high-level categories (lower = more
                    consistent)
                  </div>
                  <div>
                    <span className="font-semibold">Max Equity Gap:</span>{" "}
                    Largest demographic score difference (hover for details on
                    significance and effect size)
                  </div>
                  <div>
                    <span className="font-semibold">Max Gap Area:</span>{" "}
                    Demographic group and Category where the Max Equity Gap
                    occurs
                  </div>
                  <div>
                    <span className="font-semibold">Equity Concerns:</span>{" "}
                    Percentage of demographic gaps flagged as concerns (large
                    effect & statistically significant)
                  </div>
                  <div>
                    <span className="font-semibold">User Retention:</span>{" "}
                    Percentage of participants who said they would use the model
                    again
                  </div>
                </div>

                {/* Color key on a single line */}
                <div className="mt-2 pt-2 border-t border-gray-100 flex flex-wrap items-center gap-x-4 gap-y-2">
                  <span className="font-semibold whitespace-nowrap">
                    Color Key:
                  </span>
                  <div className="flex items-center">
                    <span className="inline-block w-4 h-4 rounded-full bg-red-100 mr-1"></span>
                    <span>
                      Equity Concern (Large Effect & Statistically Significant)
                    </span>
                  </div>
                  <div className="flex items-center">
                    <span className="inline-block w-4 h-4 rounded-full bg-yellow-100 mr-1"></span>
                    <span>Large Effect (Not Statistically Significant)</span>
                  </div>
                </div>
              </div>
            </div>
          </div>

          {/* Top Performers Section */}
          <div className="mb-4 flex items-center">
            <h3 className="font-semibold text-xl mr-4">
              Top Performers by Category
            </h3>
            <div className="flex space-x-1 p-1 bg-gray-200 rounded-lg">
              <button
                className={`px-4 py-1.5 text-sm font-medium rounded-md transition-colors duration-150 ${
                  topPerformersView === "high-level"
                    ? "bg-white shadow text-blue-600"
                    : "text-gray-600 hover:text-gray-800"
                }`}
                onClick={() => setTopPerformersView("high-level")}
              >
                {" "}
                High-Level Categories{" "}
              </button>
              <button
                className={`px-4 py-1.5 text-sm font-medium rounded-md transition-colors duration-150 ${
                  topPerformersView === "low-level"
                    ? "bg-white shadow text-blue-600"
                    : "text-gray-600 hover:text-gray-800"
                }`}
                onClick={() => setTopPerformersView("low-level")}
              >
                {" "}
                Low-Level Metrics{" "}
              </button>
            </div>
          </div>
          {/* Top Performers Tables - Access using Title Case keys */}
          {topPerformersView === "high-level" && (
            <div className="border rounded-lg overflow-hidden shadow-sm mb-6">
              <div className="px-4 py-3 bg-gray-50 border-b">
                <h3 className="font-semibold text-gray-800">
                  Top Performers by High-Level Category
                </h3>
              </div>
              <div className="p-4">
                {Object.entries(bestPerCategory || {}).length > 0 ? (
                  <table className="min-w-full divide-y divide-gray-200">
                    <thead>
                      <tr>
                        <th
                          scope="col"
                          className="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                        >
                          Category
                        </th>
                        <th
                          scope="col"
                          className="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                        >
                          Best Model
                        </th>
                        <th
                          scope="col"
                          className="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                        >
                          Score
                        </th>
                      </tr>
                    </thead>
                    <tbody className="bg-white divide-y divide-gray-200">
                      {Object.entries(bestPerCategory)
                        .sort(([a], [b]) => a.localeCompare(b))
                        .map(([catDisplayKey, bestInfo], idx) => (
                          <tr
                            key={catDisplayKey}
                            className={
                              idx % 2 === 0 ? "bg-white" : "bg-gray-50"
                            }
                          >
                            <td className="px-3 py-2 font-medium text-sm text-gray-900">
                              <Tooltip
                                content={getMetricTooltip(catDisplayKey)}
                              >
                                <span>{catDisplayKey}</span>
                              </Tooltip>
                            </td>
                            <td className="px-3 py-2">
                              {bestInfo.model !== "N/A" ? (
                                <div className="flex items-center">
                                  <div
                                    className="w-3 h-3 rounded-full mr-2 shrink-0"
                                    style={{ backgroundColor: bestInfo.color }}
                                  ></div>
                                  <span className="text-sm">
                                    {bestInfo.model}
                                  </span>
                                </div>
                              ) : (
                                <span className="text-sm text-gray-500">
                                  N/A
                                </span>
                              )}
                            </td>
                            <td className="px-3 py-2">
                              {bestInfo.score !== null ? (
                                <span
                                  className={`px-2 py-0.5 rounded-full text-xs font-medium ${getScoreBadgeColor(
                                    bestInfo.score
                                  )}`}
                                >
                                  {bestInfo.score.toFixed(1)}
                                </span>
                              ) : (
                                <span className="text-sm text-gray-500">
                                  N/A
                                </span>
                              )}
                            </td>
                          </tr>
                        ))}
                    </tbody>
                  </table>
                ) : (
                  <p className="text-center text-gray-500 py-4">
                    Top performer data not available.
                  </p>
                )}
                <p className="text-xs text-gray-500 mt-2">
                  Scores based on user ratings, normalized to 0-100.
                </p>
              </div>
            </div>
          )}
          {topPerformersView === "low-level" && (
            <div className="border rounded-lg overflow-hidden shadow-sm mb-6">
              <div className="px-4 py-3 bg-gray-50 border-b">
                <h3 className="font-semibold text-gray-800">
                  Top Performers by Low-Level Metric
                </h3>
              </div>
              <div className="p-4">
                {Object.entries(bestPerMetric || {}).length > 0 ? (
                  <table className="min-w-full divide-y divide-gray-200">
                    <thead>
                      <tr>
                        <th
                          scope="col"
                          className="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                        >
                          Metric
                        </th>
                        <th
                          scope="col"
                          className="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                        >
                          Best Model
                        </th>
                        <th
                          scope="col"
                          className="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                        >
                          Score
                        </th>
                      </tr>
                    </thead>
                    <tbody className="bg-white divide-y divide-gray-200">
                      {Object.entries(bestPerMetric)
                        .sort(([a], [b]) => a.localeCompare(b))
                        .map(([metricDisplayKey, bestInfo], idx) => (
                          <tr
                            key={metricDisplayKey}
                            className={
                              idx % 2 === 0 ? "bg-white" : "bg-gray-50"
                            }
                          >
                            <td className="px-3 py-2 font-medium text-sm text-gray-900">
                              <Tooltip
                                content={getMetricTooltip(metricDisplayKey)}
                              >
                                <span>{metricDisplayKey}</span>
                              </Tooltip>
                            </td>
                            <td className="px-3 py-2">
                              {bestInfo.model !== "N/A" ? (
                                <div className="flex items-center">
                                  <div
                                    className="w-3 h-3 rounded-full mr-2 shrink-0"
                                    style={{ backgroundColor: bestInfo.color }}
                                  ></div>
                                  <span className="text-sm">
                                    {bestInfo.model}
                                  </span>
                                </div>
                              ) : (
                                <span className="text-sm text-gray-500">
                                  N/A
                                </span>
                              )}
                            </td>
                            <td className="px-3 py-2">
                              {bestInfo.score !== null ? (
                                <span
                                  className={`px-2 py-0.5 rounded-full text-xs font-medium ${getScoreBadgeColor(
                                    bestInfo.score
                                  )}`}
                                >
                                  {bestInfo.score.toFixed(1)}
                                </span>
                              ) : (
                                <span className="text-sm text-gray-500">
                                  N/A
                                </span>
                              )}
                            </td>
                          </tr>
                        ))}
                    </tbody>
                  </table>
                ) : (
                  <p className="text-center text-gray-500 py-4">
                    Low-level metric top performer data not available.
                  </p>
                )}
                <p className="text-xs text-gray-500 mt-2">
                  Scores based on user ratings, normalized to 0-100.
                </p>
              </div>
            </div>
          )}
        </div>
      )}{" "}
      {/* End Overview Tab */}
      {/* Other Tabs - Pass Correct Props */}
      {activeTab === "metrics-breakdown" && (
        <MetricsBreakdown
          metricsData={metricsData} // Title Case keys inside, plus internalMetricKey
          modelsMeta={rankedModels} // camelCase keys inside
          radarData={radarData}
        />
      )}
      {activeTab === "task-performance" && (
        <TaskPerformance
          rawData={rawData} // Contains camelCase top-level, snake_case nested
          modelsMeta={rankedModels}
          metricsData={metricsData} // Title Case keys inside, plus internalMetricKey
          overviewCardData={overviewCardData}
        />
      )}
      {activeTab === "demographic-analysis" && (
        <DemographicAnalysis
          rawData={rawData} // Contains camelCase top-level, snake_case/Title Case nested
          modelsMeta={rankedModels}
          metricsData={metricsData} // Title Case keys inside, plus internalMetricKey
          equityAnalysis={equityAnalysis} // Original snake_case structure
        />
      )}
      {activeTab === "about" && <About metadata={metadata} />}
    </div>
  );
};

export default LLMComparisonDashboard;