File size: 5,304 Bytes
5470817
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React from "react";
import { Card, CardContent, Typography, Box, Stack } from "@mui/material";
import FavoriteBorderIcon from "@mui/icons-material/FavoriteBorder";
import { alpha } from "@mui/material/styles";

const LeaderboardCard = ({ leaderboard }) => {
  const { card_data, likes, enriched, consolidated_notes, organization } =
    leaderboard;

  // Fonction pour capitaliser la première lettre
  const capitalizeFirst = (str) => {
    return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
  };

  // Fonction pour formater les likes
  const formatLikes = (count) => {
    if (count >= 1000) {
      return (count / 1000).toFixed(2).replace(/\.?0+$/, "") + "k";
    }
    return count;
  };

  // Séparer les emojis s'il y en a plusieurs
  const emojis = card_data.emoji.trim().split(/\s+/);

  return (
    <Box
      component="a"
      href={`https://huggingface.co/spaces/${leaderboard.id}`}
      target="_blank"
      rel="noopener noreferrer"
      sx={{
        textDecoration: "none",
        color: "inherit",
        display: "block",
        "&:hover": {
          opacity: 0.95,
        },
      }}
    >
      <Stack spacing={1}>
        <Card
          elevation={0}
          sx={{
            position: "relative",
            minHeight: 180,
            background: `linear-gradient(135deg, ${card_data.colorFrom} 0%, ${card_data.colorTo} 100%)`,
            color: "white",
            overflow: "visible",
            "&::after": {
              content: '""',
              position: "absolute",
              top: 0,
              left: 0,
              right: 0,
              bottom: 0,
              backgroundColor: "rgba(0, 0, 0, 0.1)",
              pointerEvents: "none",
              zIndex: 1,
            },
          }}
        >
          {/* Background Emoji */}
          <Box
            sx={{
              position: "absolute",
              top: "50%",
              left: "50%",
              transform: "translate(-50%, -50%)",
              fontSize: "3.75rem",
              opacity: 0.6,
              pointerEvents: "none",
              display: "flex",
              zIndex: 2,
            }}
          >
            {emojis.map((emoji, index) => (
              <span key={index}>{emoji}</span>
            ))}
          </Box>

          {/* Header with likes and status */}
          <Box
            sx={{
              position: "absolute",
              top: 0,
              left: 0,
              right: 0,
              p: 1.5,
              display: "flex",
              justifyContent: "space-between",
              alignItems: "center",
              zIndex: 2,
            }}
          >
            <Typography
              variant="body2"
              sx={{
                backgroundColor: "rgba(0, 0, 0, 0.1)",
                px: 1,
                py: 0.25,
                borderRadius: 1,
                fontSize: "0.75rem",
              }}
            >
              {capitalizeFirst(leaderboard.runtime_stage)}
            </Typography>
            <Box
              sx={{
                display: "flex",
                alignItems: "center",
                gap: 0.25,
                fontSize: "0.75rem",
              }}
            >
              <FavoriteBorderIcon sx={{ fontSize: 16 }} />
              <Typography variant="body2" sx={{ fontSize: "inherit" }}>
                {formatLikes(likes)}
              </Typography>
            </Box>
          </Box>

          {/* Footer with author */}
          <Box
            sx={{
              position: "absolute",
              bottom: 0,
              left: 0,
              right: 0,
              p: 1.5,
              zIndex: 2,
            }}
          >
            <Typography
              variant="body2"
              sx={{
                fontSize: "0.75rem",
                opacity: 0.9,
              }}
            >
              by {organization}
            </Typography>
          </Box>

          <CardContent
            sx={{
              height: "100%",
              display: "flex",
              alignItems: "center",
              justifyContent: "center",
              position: "absolute",
              top: "50%",
              left: "50%",
              transform: "translate(-50%, -50%)",
              width: "100%",
              zIndex: 2,
              p: 0,
              "&:last-child": {
                paddingBottom: 0,
              },
            }}
          >
            <Typography
              variant="h6"
              component="h2"
              align="center"
              sx={{
                fontSize: "1.25rem",
                fontWeight: 800,
                maxWidth: "90%",
                margin: "0 auto",
                zIndex: 5,
                textShadow: "rgba(0, 0, 0, 0.25) 0px 1px 2px",
              }}
            >
              {card_data.title}
            </Typography>
          </CardContent>
        </Card>

        {consolidated_notes && (
          <Typography
            variant="body2"
            sx={{
              color: "text.secondary",
              fontSize: "0.875rem",
            }}
          >
            {consolidated_notes}
          </Typography>
        )}
      </Stack>
    </Box>
  );
};

export default LeaderboardCard;