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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
import React from "react";
import { Box, Typography, Link, Tooltip, IconButton } from "@mui/material";
import { getModelTypeIcon } from "../constants/modelTypes";
import TrendingUpIcon from "@mui/icons-material/TrendingUp";
import TrendingDownIcon from "@mui/icons-material/TrendingDown";
import RemoveIcon from "@mui/icons-material/Remove";
import PushPinIcon from "@mui/icons-material/PushPin";
import PushPinOutlinedIcon from "@mui/icons-material/PushPinOutlined";
import { TABLE_DEFAULTS, HIGHLIGHT_COLORS } from "../constants/defaults";
import { looksLikeRegex, extractTextSearch } from "./searchUtils";
import { commonStyles } from "../styles/common";
import { typeColumnSort } from "../components/Table/hooks/useSorting";
import {
  COLUMN_TOOLTIPS,
  getTooltipStyle,
  TABLE_TOOLTIPS,
} from "../constants/tooltips";
import OpenInNewIcon from "@mui/icons-material/OpenInNew";
import { alpha } from "@mui/material/styles";
import InfoIconWithTooltip from "../../../../../components/shared/InfoIconWithTooltip";

const DatabaseIcon = () => (
  <svg
    className="mr-1.5 text-gray-400 group-hover:text-red-500"
    xmlns="http://www.w3.org/2000/svg"
    aria-hidden="true"
    focusable="false"
    role="img"
    width="1.4em"
    height="1.4em"
    preserveAspectRatio="xMidYMid meet"
    viewBox="0 0 25 25"
  >
    <ellipse
      cx="12.5"
      cy="5"
      fill="currentColor"
      fillOpacity="0.25"
      rx="7.5"
      ry="2"
    ></ellipse>
    <path
      d="M12.5 15C16.6421 15 20 14.1046 20 13V20C20 21.1046 16.6421 22 12.5 22C8.35786 22 5 21.1046 5 20V13C5 14.1046 8.35786 15 12.5 15Z"
      fill="currentColor"
      opacity="0.5"
    ></path>
    <path
      d="M12.5 7C16.6421 7 20 6.10457 20 5V11.5C20 12.6046 16.6421 13.5 12.5 13.5C8.35786 13.5 5 12.6046 5 11.5V5C5 6.10457 8.35786 7 12.5 7Z"
      fill="currentColor"
      opacity="0.5"
    ></path>
    <path
      d="M5.23628 12C5.08204 12.1598 5 12.8273 5 13C5 14.1046 8.35786 15 12.5 15C16.6421 15 20 14.1046 20 13C20 12.8273 19.918 12.1598 19.7637 12C18.9311 12.8626 15.9947 13.5 12.5 13.5C9.0053 13.5 6.06886 12.8626 5.23628 12Z"
      fill="currentColor"
    ></path>
  </svg>
);

const HighlightedText = ({ text, searchValue }) => {
  if (!searchValue) return text;

  const searches = searchValue
    .split(";")
    .map((s) => s.trim())
    .filter(Boolean);
  let result = text;
  let fragments = [{ text: result, isMatch: false }];

  searches.forEach((search, searchIndex) => {
    if (!search) return;

    try {
      let regex;
      if (looksLikeRegex(search)) {
        regex = new RegExp(search, "gi");
      } else {
        regex = new RegExp(search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "gi");
      }

      const newFragments = [];
      fragments.forEach((fragment) => {
        if (fragment.isMatch) {
          newFragments.push(fragment);
          return;
        }

        const parts = fragment.text.split(regex);
        const matches = fragment.text.match(regex);

        if (!matches) {
          newFragments.push(fragment);
          return;
        }

        parts.forEach((part, i) => {
          if (part) newFragments.push({ text: part, isMatch: false });
          if (i < parts.length - 1) {
            newFragments.push({
              text: matches[i],
              isMatch: true,
              colorIndex: searchIndex % HIGHLIGHT_COLORS.length,
            });
          }
        });
      });

      fragments = newFragments;
    } catch (e) {
      console.warn("Invalid regex:", search);
    }
  });

  return (
    <>
      {fragments.map((fragment, i) =>
        fragment.isMatch ? (
          <Box
            key={i}
            component="span"
            sx={{
              backgroundColor: HIGHLIGHT_COLORS[fragment.colorIndex],
              color: (theme) =>
                theme.palette.getContrastText(
                  HIGHLIGHT_COLORS[fragment.colorIndex]
                ),
              fontWeight: 500,
              px: 0.5,
              py: "2px",
              borderRadius: "3px",
              mx: "1px",
              overflow: "visible",
              display: "inline-block",
            }}
          >
            {fragment.text}
          </Box>
        ) : (
          <React.Fragment key={i}>{fragment.text}</React.Fragment>
        )
      )}
    </>
  );
};

const MEDAL_STYLES = {
  1: {
    color: "#B58A1B",
    background: "linear-gradient(135deg, #FFF7E0 0%, #FFD700 100%)",
    borderColor: "rgba(212, 160, 23, 0.35)",
    shadowColor: "rgba(212, 160, 23, 0.8)",
  },
  2: {
    color: "#667380",
    background: "linear-gradient(135deg, #FFFFFF 0%, #D8E3ED 100%)",
    borderColor: "rgba(124, 139, 153, 0.35)",
    shadowColor: "rgba(124, 139, 153, 0.8)",
  },
  3: {
    color: "#B85C2F",
    background: "linear-gradient(135deg, #FDF0E9 0%, #FFBC8C 100%)",
    borderColor: "rgba(204, 108, 61, 0.35)",
    shadowColor: "rgba(204, 108, 61, 0.8)",
  },
};

const getMedalStyle = (rank) => {
  if (rank <= 3) {
    const medalStyle = MEDAL_STYLES[rank];
    return {
      color: medalStyle.color,
      fontWeight: 900,
      fontStretch: "150%",
      fontFamily: '"Inter", -apple-system, sans-serif',
      width: "24px",
      height: "24px",
      background: medalStyle.background,
      border: "1px solid",
      borderColor: medalStyle.borderColor,
      borderRadius: "50%",
      display: "flex",
      alignItems: "center",
      justifyContent: "center",
      fontSize: "0.95rem",
      lineHeight: 1,
      padding: 0,
      boxShadow: `1px 1px 0 ${medalStyle.shadowColor}`,
      position: "relative",
    };
  }
  return {
    color: "inherit",
    fontWeight: rank <= 10 ? 600 : 400,
  };
};

const getRankStyle = (rank) => getMedalStyle(rank);

const RankIndicator = ({ rank, previousRank, mode }) => {
  const rankChange = previousRank ? previousRank - rank : 0;

  const RankChangeIndicator = ({ change }) => {
    if (!change || mode === "dynamic") return null;

    const getChangeColor = (change) => {
      if (change > 0) return "success.main";
      if (change < 0) return "error.main";
      return "grey.500";
    };

    const getChangeIcon = (change) => {
      if (change > 0) return <TrendingUpIcon sx={{ fontSize: "1rem" }} />;
      if (change < 0) return <TrendingDownIcon sx={{ fontSize: "1rem" }} />;
      return <RemoveIcon sx={{ fontSize: "1rem" }} />;
    };

    return (
      <Tooltip
        title={`${Math.abs(change)} position${
          Math.abs(change) > 1 ? "s" : ""
        } ${change > 0 ? "up" : "down"}`}
        arrow
        placement="right"
      >
        <Box
          sx={{
            display: "flex",
            alignItems: "center",
            color: getChangeColor(change),
            ml: 0.5,
            fontSize: "0.75rem",
          }}
        >
          {getChangeIcon(change)}
        </Box>
      </Tooltip>
    );
  };

  return (
    <Box
      sx={{
        display: "flex",
        alignItems: "center",
        justifyContent: "center",
        width: "100%",
      }}
    >
      <Typography
        sx={{
          ...getRankStyle(rank),
          display: "flex",
          alignItems: "center",
          lineHeight: 1,
          position: "relative",
        }}
      >
        {rank <= 3 ? (
          <>
            <Box component="span" sx={{ position: "relative", zIndex: 1 }}>
              {rank}
            </Box>
            <RankChangeIndicator change={rankChange} />
          </>
        ) : (
          <>
            <Box component="span" sx={{ position: "relative", zIndex: 1 }}>
              {rank}
            </Box>
            <RankChangeIndicator change={rankChange} />
          </>
        )}
      </Typography>
    </Box>
  );
};

const getDetailsUrl = (modelName) => {
  const formattedName = modelName.replace("/", "__");
  return `https://huggingface.co/datasets/TheFinAI/lm-eval-results-private`;
};

const HeaderLabel = ({ label, tooltip, className, isSorted }) => (
  <Tooltip
    title={label}
    arrow
    placement="top"
    enterDelay={1000}
    componentsProps={getTooltipStyle}
  >
    <Typography
      className={className}
      sx={{
        fontWeight: 600,
        color: isSorted ? "primary.main" : "grey.700",
        flex: 1,
        transition: "max-width 0.2s ease",
        maxWidth: "100%",
        ...(label === "Rank" || label === "Type"
          ? {
              overflow: "visible",
              whiteSpace: "normal",
              textOverflow: "clip",
              textAlign: "center",
            }
          : {
              overflow: "hidden",
              textOverflow: "ellipsis",
              whiteSpace: "nowrap",
            }),
        "@media (hover: hover)": {
          ".MuiTableCell-root:hover &": {
            maxWidth: tooltip ? "calc(100% - 48px)" : "100%",
          },
        },
      }}
    >
      {label}
    </Typography>
  </Tooltip>
);

const InfoIcon = ({ tooltip }) => (
  <Box
    component="span"
    sx={{
      opacity: 0.5,
      display: "flex",
      alignItems: "center",
      ml: 0.5,
    }}
  >
    <InfoIconWithTooltip tooltip={tooltip} />
  </Box>
);

const createHeaderCell = (label, tooltip) => (header) =>
  (
    <Box
      className="header-content"
      sx={{
        display: "flex",
        alignItems: "center",
        width: "100%",
        position: "relative",
      }}
    >
      <HeaderLabel
        label={label}
        tooltip={tooltip}
        className="header-label"
        isSorted={header?.column?.getIsSorted()}
      />

      <Box
        sx={{
          display: "flex",
          alignItems: "center",
          gap: 0.5,
          ml: "auto",
          flexShrink: 0,
        }}
      >
        {tooltip && <InfoIcon tooltip={tooltip} />}
      </Box>
    </Box>
  );

const createModelHeader =
  (totalModels, officialProvidersCount = 0, isOfficialProviderActive = false) =>
  ({ table }) => {
    return (
      <Box
        sx={{
          display: "flex",
          alignItems: "center",
          justifyContent: "space-between",
          width: "100%",
        }}
      >
        <Box
          sx={{
            display: "flex",
            alignItems: "center",
            gap: 1,
          }}
        >
          <Typography
            sx={{
              fontWeight: 600,
              color: "grey.700",
              overflow: "hidden",
              textOverflow: "ellipsis",
              whiteSpace: "nowrap",
            }}
          >
            Model
          </Typography>
        </Box>
      </Box>
    );
  };

const BooleanValue = ({ value }) => {
  if (value === null || value === undefined)
    return <Typography variant="body2">-</Typography>;

  return (
    <Box
      sx={(theme) => ({
        display: "flex",
        alignItems: "center",
        justifyContent: "center",
        borderRadius: "4px",
        px: 1,
        py: 0.5,
        backgroundColor: value
          ? theme.palette.mode === "dark"
            ? alpha(theme.palette.success.main, 0.1)
            : alpha(theme.palette.success.main, 0.1)
          : theme.palette.mode === "dark"
          ? alpha(theme.palette.error.main, 0.1)
          : alpha(theme.palette.error.main, 0.1),
      })}
    >
      <Typography
        variant="body2"
        sx={(theme) => ({
          color: value
            ? theme.palette.mode === "dark"
              ? theme.palette.success.light
              : theme.palette.success.dark
            : theme.palette.mode === "dark"
            ? theme.palette.error.light
            : theme.palette.error.dark,
        })}
      >
        {value ? "Yes" : "No"}
      </Typography>
    </Box>
  );
};

export const createColumns = (
  getColorForValue,
  scoreDisplay = "normalized",
  columnVisibility = {},
  totalModels,
  averageMode = "all",
  searchValue = "",
  rankingMode = "static",
  onTogglePin,
  hasPinnedRows = false
) => {
  // Ajuster les tailles des colonnes en fonction de la présence de lignes épinglées
  const getColumnSize = (defaultSize) =>
    hasPinnedRows ? "auto" : `${defaultSize}px`;

  const baseColumns = [
    {
      accessorKey: "isPinned",
      header: () => null,
      cell: ({ row }) => (
        <Box
          sx={{
            display: "flex",
            alignItems: "center",
            justifyContent: "center",
            height: "100%",
          }}
        >
          <IconButton
            size="small"
            onClick={(e) => {
              e.stopPropagation();
              e.preventDefault();
              onTogglePin(row.original.id);
            }}
            sx={{
              padding: 0.5,
              color: row.original.isPinned ? "primary.main" : "grey.400",
              "&:hover": {
                color: "primary.main",
              },
            }}
          >
            {row.original.isPinned ? (
              <PushPinIcon fontSize="small" />
            ) : (
              <PushPinOutlinedIcon fontSize="small" />
            )}
          </IconButton>
        </Box>
      ),
      enableSorting: false,
      size: getColumnSize(40),
    },
    {
      accessorKey: "rank",
      header: createHeaderCell("Rank"),
      cell: ({ row }) => {
        const rank =
          rankingMode === "static"
            ? row.original.static_rank
            : row.original.dynamic_rank;

        return (
          <RankIndicator
            rank={rank}
            previousRank={row.original.previous_rank}
            mode="static"
          />
        );
      },
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["rank"],
    },
    {
      id: "model_type",
      accessorFn: (row) => row.model.type,
      header: createHeaderCell("Type"),
      sortingFn: typeColumnSort,
      cell: ({ row }) => (
        <Box
          sx={{
            display: "flex",
            alignItems: "center",
            justifyContent: "center",
            width: "100%",
          }}
        >
          <Tooltip title={row.original.model.type}>
            <Typography
              sx={{
                fontSize: "1.2rem",
                cursor: "help",
                lineHeight: 1,
                fontFamily:
                  '"Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", sans-serif',
              }}
            >
              {getModelTypeIcon(row.original.model.type)}
            </Typography>
          </Tooltip>
        </Box>
      ),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["model.type_icon"],
    },
    {
      accessorKey: "id",
      header: createModelHeader(totalModels),
      cell: ({ row }) => {
        const textSearch = extractTextSearch(searchValue);
        const modelName = row.original.model.name;

        return (
          <Box
            sx={{
              width: "100%",
              display: "flex",
              alignItems: "center",
              gap: 1,
            }}
          >
            <Box
              sx={{
                display: "flex",
                alignItems: "center",
                gap: 1,
                minWidth: 0,
                flex: 1,
              }}
            >
              <Link
                href={`https://huggingface.co/${modelName}`}
                target="_blank"
                rel="noopener noreferrer"
                aria-label={`View ${modelName} on Hugging Face Hub`}
                title={TABLE_TOOLTIPS.HUB_LINK(modelName)}
                sx={{
                  textDecoration: "none",
                  color: "info.main",
                  display: "flex",
                  alignItems: "center",
                  gap: 0.5,
                  "&:hover": {
                    textDecoration: "underline",
                    color: (theme) =>
                      theme.palette.mode === "dark"
                        ? theme.palette.info.light
                        : theme.palette.info.dark,
                    "& svg": {
                      opacity: 0.8,
                    },
                  },
                  overflow: "hidden",
                  textOverflow: "ellipsis",
                  whiteSpace: "nowrap",
                  flex: 1,
                  minWidth: 0,
                  fontWeight: row.original.static_rank <= 3 ? 600 : "inherit",
                }}
              >
                <HighlightedText text={modelName} searchValue={textSearch} />
                <OpenInNewIcon
                  sx={{
                    fontSize: "0.75rem",
                    opacity: 0.6,
                    transition: "opacity 0.2s ease-in-out",
                    ml: 0.5,
                    flexShrink: 0,
                  }}
                />
              </Link>
              <Link
                href={getDetailsUrl(modelName)}
                target="_blank"
                rel="noopener noreferrer"
                aria-label={`View detailed evaluation results for ${modelName}`}
                title={TABLE_TOOLTIPS.EVAL_RESULTS(modelName)}
                sx={{
                  textDecoration: "none",
                  "&:hover": {
                    textDecoration: "underline",
                    "& svg": {
                      color: "text.primary",
                    },
                  },
                  display: "flex",
                  alignItems: "center",
                  color: "text.secondary",
                  flexShrink: 0,
                  mr: 0,
                }}
              >
                <DatabaseIcon />
              </Link>
            </Box>
          </Box>
        );
      },
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["id"],
    },
    {
      accessorKey: "model.average_score",
      header: createHeaderCell("Average", COLUMN_TOOLTIPS.AVERAGE),
      cell: ({ row, getValue }) =>
        createScoreCell(getValue, row, "model.average_score"),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["model.average_score"],
      meta: {
        headerStyle: {
          borderLeft: (theme) =>
            `2px solid ${alpha(
              theme.palette.divider,
              theme.palette.mode === "dark" ? 0.1 : 0.2
            )}`,
          borderRight: (theme) =>
            `2px solid ${alpha(
              theme.palette.divider,
              theme.palette.mode === "dark" ? 0.1 : 0.2
            )}`,
        },
        cellStyle: (value) => ({
          position: "relative",
          overflow: "hidden",
          padding: "8px 16px",
          borderLeft: (theme) =>
            `2px solid ${alpha(
              theme.palette.divider,
              theme.palette.mode === "dark" ? 0.1 : 0.2
            )}`,
          borderRight: (theme) =>
            `2px solid ${alpha(
              theme.palette.divider,
              theme.palette.mode === "dark" ? 0.1 : 0.2
            )}`,
        }),
      },
    },
  ];
  const createScoreCell = (getValue, row, field) => {
    const value = getValue();
    const rawValue = field.includes("normalized")
      ? row.original.evaluations[field.split(".")[1]]?.value
      : value;

    const isAverageColumn = field === "model.average_score";
    const hasNoValue = value === null || value === undefined;

    return (
      <Box sx={commonStyles.cellContainer}>
        {!hasNoValue && (scoreDisplay === "normalized" || isAverageColumn) && (
          <Box
            sx={{
              position: "absolute",
              left: -16,
              top: -16,
              height: "calc(100% + 32px)",
              width: `calc(${value}% + 16px)`,
              backgroundColor: getColorForValue(value),
              opacity: (theme) => (theme.palette.mode === "light" ? 0.1 : 0.2),
              transition: "width 0.3s ease",
              zIndex: 0,
            }}
          />
        )}
        <Box
          sx={{
            position: "relative",
            display: "flex",
            alignItems: "center",
            gap: 1,
            zIndex: 1,
            pl: isAverageColumn && !hasNoValue ? 1 : 0,
          }}
        >
          {isAverageColumn && !hasNoValue && (
            <Box
              sx={{
                width: 10,
                height: 10,
                borderRadius: "50%",
                marginLeft: -1,
                backgroundColor: getColorForValue(value),
              }}
            />
          )}
          <Typography variant="body2">
            {hasNoValue ? (
              "-"
            ) : (
              <>
                {isAverageColumn ? (
                  <>
                    {value.toFixed(2)}
                    <span style={{ opacity: 0.5 }}> %</span>
                  </>
                ) : scoreDisplay === "normalized" ? (
                  <>
                    {value.toFixed(2)}
                    <span style={{ opacity: 0.5 }}> %</span>
                  </>
                ) : (
                  <>{rawValue.toFixed(2)}</>
                )}
              </>
            )}
          </Typography>
        </Box>
      </Box>
    );
  };

  const evaluationColumns = [
    {
      accessorKey: "evaluations.multifin.normalized_score",
      header: createHeaderCell("MultiFin", COLUMN_TOOLTIPS.MULTIFIN),
      cell: ({ row, getValue }) =>
        createScoreCell(getValue, row, "evaluations.multifin.normalized_score"),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES[
        "evaluations.multifin.normalized_score"
      ],
    },
    {
      accessorKey: "evaluations.qa.normalized_score",
      header: createHeaderCell("QA", COLUMN_TOOLTIPS.QA),
      cell: ({ row, getValue }) =>
        createScoreCell(getValue, row, "evaluations.qa.normalized_score"),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES[
        "evaluations.qa.normalized_score"
      ],
    },
    {
      accessorKey: "evaluations.fns.normalized_score",
      header: createHeaderCell("FNS", COLUMN_TOOLTIPS.FNS),
      cell: ({ row, getValue }) =>
        createScoreCell(getValue, row, "evaluations.fns.normalized_score"),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES[
        "evaluations.fns.normalized_score"
      ],
    },
    {
      accessorKey: "evaluations.finnum.normalized_score",
      header: createHeaderCell("FinNum", COLUMN_TOOLTIPS.FinNum),
      cell: ({ row, getValue }) =>
        createScoreCell(getValue, row, "evaluations.finnum.normalized_score"),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES[
        "evaluations.finnum.normalized_score"
      ],
    },
    {
      accessorKey: "evaluations.fintext.normalized_score",
      header: createHeaderCell("FinText", COLUMN_TOOLTIPS.FinText),
      cell: ({ row, getValue }) =>
        createScoreCell(getValue, row, "evaluations.fintext.normalized_score"),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES[
        "evaluations.fintext.normalized_score"
      ],
    },
  ];

  const optionalColumns = [
    {
      accessorKey: "model.architecture",
      header: createHeaderCell("Architecture", COLUMN_TOOLTIPS.ARCHITECTURE),
      accessorFn: (row) => row.model.architecture,
      cell: ({ row }) => (
        <Tooltip title={row.original.model.architecture || "-"}>
          <span>{row.original.model.architecture || "-"}</span>
        </Tooltip>
      ),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["model.architecture"],
    },
    {
      accessorKey: "model.precision",
      header: createHeaderCell("Precision", COLUMN_TOOLTIPS.PRECISION),
      accessorFn: (row) => row.model.precision,
      cell: ({ row }) => (
        <Tooltip title={row.original.model.precision || "-"}>
          <span>{row.original.model.precision || "-"}</span>
        </Tooltip>
      ),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["model.precision"],
    },
    {
      accessorKey: "metadata.params_billions",
      header: createHeaderCell("Parameters", COLUMN_TOOLTIPS.PARAMETERS),
      cell: ({ row }) => (
        <Box
          sx={{
            display: "flex",
            alignItems: "center",
            justifyContent: "flex-start",
          }}
        >
          <Typography variant="body2">
            {row.original.metadata.params_billions}
            <span style={{ opacity: 0.6 }}>B</span>
          </Typography>
        </Box>
      ),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["metadata.params_billions"],
    },
    {
      accessorKey: "metadata.hub_license",
      header: createHeaderCell("License", COLUMN_TOOLTIPS.LICENSE),
      cell: ({ row }) => (
        <Tooltip title={row.original.metadata.hub_license || "-"}>
          <Typography
            variant="body2"
            sx={{
              overflow: "hidden",
              textOverflow: "ellipsis",
              whiteSpace: "nowrap",
            }}
          >
            {row.original.metadata.hub_license || "-"}
          </Typography>
        </Tooltip>
      ),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["metadata.hub_license"],
    },
    {
      accessorKey: "metadata.hub_hearts",
      header: createHeaderCell(
        "Hub ❤️",
        "Number of likes received on the Hugging Face Hub"
      ),
      cell: ({ row }) => (
        <Typography variant="body2">
          {row.original.metadata.hub_hearts}
        </Typography>
      ),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["metadata.hub_hearts"],
    },
    {
      accessorKey: "metadata.upload_date",
      header: createHeaderCell(
        "Upload Date",
        "Date when the model was uploaded to the Hugging Face Hub"
      ),
      cell: ({ row }) => (
        <Tooltip title={row.original.metadata.upload_date || "-"}>
          <Typography
            variant="body2"
            sx={{
              overflow: "hidden",
              textOverflow: "ellipsis",
              whiteSpace: "nowrap",
            }}
          >
            {row.original.metadata.upload_date || "-"}
          </Typography>
        </Tooltip>
      ),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["metadata.upload_date"],
    },
    {
      accessorKey: "metadata.submission_date",
      header: createHeaderCell(
        "Submission Date",
        "Date when the model was submitted to the leaderboard"
      ),
      cell: ({ row }) => (
        <Tooltip title={row.original.metadata.submission_date || "-"}>
          <Typography
            variant="body2"
            sx={{
              overflow: "hidden",
              textOverflow: "ellipsis",
              whiteSpace: "nowrap",
            }}
          >
            {row.original.metadata.submission_date || "-"}
          </Typography>
        </Tooltip>
      ),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["metadata.submission_date"],
    },
    {
      accessorKey: "metadata.generation",
      header: createHeaderCell(
        "Generation",
        "The generation or version number of the model"
      ),
      cell: ({ row }) => (
        <Typography variant="body2">
          {row.original.metadata.generation}
        </Typography>
      ),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["metadata.generation"],
    },
    {
      accessorKey: "metadata.base_model",
      header: createHeaderCell(
        "Base Model",
        "The original model this model was derived from"
      ),
      cell: ({ row }) => (
        <Tooltip title={row.original.metadata.base_model || "-"}>
          <Typography
            variant="body2"
            sx={{
              overflow: "hidden",
              textOverflow: "ellipsis",
              whiteSpace: "nowrap",
            }}
          >
            {row.original.metadata.base_model || "-"}
          </Typography>
        </Tooltip>
      ),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["metadata.base_model"],
    },
    {
      accessorKey: "metadata.co2_cost",
      header: createHeaderCell("CO₂ Cost", COLUMN_TOOLTIPS.CO2_COST),
      cell: ({ row }) => (
        <Box
          sx={{
            display: "flex",
            alignItems: "center",
            justifyContent: "flex-start",
          }}
        >
          <Typography variant="body2">
            {row.original.metadata.co2_cost?.toFixed(2) || "0"}
            <span style={{ opacity: 0.6 }}> kg</span>
          </Typography>
        </Box>
      ),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["metadata.co2_cost"],
    },
    {
      accessorKey: "model.has_chat_template",
      header: createHeaderCell(
        "Chat Template",
        "Whether this model has a chat template defined"
      ),
      cell: ({ row }) => (
        <BooleanValue value={row.original.model.has_chat_template} />
      ),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["model.has_chat_template"],
    },
    {
      accessorKey: "features.is_not_available_on_hub",
      header: createHeaderCell(
        "Hub Availability",
        "Whether the model is available on the Hugging Face Hub"
      ),
      cell: ({ row }) => (
        <BooleanValue value={row.original.features.is_not_available_on_hub} />
      ),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES[
        "features.is_not_available_on_hub"
      ],
    },
    {
      accessorKey: "features.is_highlighted_by_maintainer",
      header: createHeaderCell(
        "Official Providers",
        "Models that are officially provided and maintained by their original creators or organizations"
      ),
      cell: ({ row }) => (
        <BooleanValue
          value={row.original.features.is_highlighted_by_maintainer}
        />
      ),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES[
        "features.is_highlighted_by_maintainer"
      ],
      enableSorting: true,
    },
    {
      accessorKey: "features.is_moe",
      header: createHeaderCell(
        "Mixture of Experts",
        "Whether this model uses a Mixture of Experts architecture"
      ),
      cell: ({ row }) => <BooleanValue value={row.original.features.is_moe} />,
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["features.is_moe"],
    },
    {
      accessorKey: "features.is_flagged",
      header: createHeaderCell(
        "Flag Status",
        "Whether this model has been flagged for any issues"
      ),
      cell: ({ row }) => (
        <BooleanValue value={row.original.features.is_flagged} />
      ),
      size: TABLE_DEFAULTS.COLUMNS.COLUMN_SIZES["features.is_flagged"],
    },
  ];

  // Utiliser directement columnVisibility
  const finalColumns = [
    ...baseColumns,
    ...evaluationColumns.filter((col) => columnVisibility[col.accessorKey]),
    ...optionalColumns
      .filter((col) => columnVisibility[col.accessorKey])
      .sort((a, b) => {
        // Définir l'ordre personnalisé des colonnes
        const order = {
          "model.architecture": 1,
          "model.precision": 2,
          "metadata.params_billions": 3,
          "metadata.hub_license": 4,
          "metadata.co2_cost": 5,
          "metadata.hub_hearts": 6,
          "metadata.upload_date": 7,
          "metadata.submission_date": 8,
          "metadata.generation": 9,
          "metadata.base_model": 10,
          "model.has_chat_template": 11,
          "features.is_not_available_on_hub": 12,
          "features.is_highlighted_by_maintainer": 13,
          "features.is_moe": 14,
          "features.is_flagged": 15,
        };
        return order[a.accessorKey] - order[b.accessorKey];
      }),
  ];

  return finalColumns;
};