# All files / src/components/filters GameFilters.tsx

0% Statements 0/300
0% Branches 0/1
0% Functions 0/1
0% Lines 0/300

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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

     import React, { useState } from 'react';
    import { useDarkMode } from '../../contexts/DarkModeContext';

    interface GameFiltersProps {
      selectedSports: string[];
      onSportToggle: (sport: string) => void;
      selectedStatus: string;
      onStatusChange: (status: string) => void;
      selectedBookmaker: string;
      onBookmakerChange: (bookmaker: string) => void;
      oddsFormat: 'american' | 'decimal' | 'fractional';
      onOddsFormatChange: (format: 'american' | 'decimal' | 'fractional') => void;
      selectedDate: string;
      onDateChange: (date: string) => void;
      availableSports: { key: string; name: string; count: number }[];
      availableBookmakers: string[];
    }

    // Map sport keys to image files and categories
    const SPORT_CONFIG: Record<string, {
      image: string;
      displayName: string;
      category: 'professional' | 'college';
      baseKey: string;
    }> = {
      'basketball_nba': {
        image: '/sports/basketball.svg',
        displayName: 'NBA',
        category: 'professional',
        baseKey: 'basketball'
      },
      'basketball_ncaab': {
        image: '/sports/basketball.svg',
        displayName: 'NCAAB',
        category: 'college',
        baseKey: 'basketball'
      },
      'americanfootball_nfl': {
        image: '/sports/football.svg',
        displayName: 'NFL',
        category: 'professional',
        baseKey: 'football'
      },
      'americanfootball_ncaaf': {
        image: '/sports/football.svg',
        displayName: 'NCAAF',
        category: 'college',
        baseKey: 'football'
      },
      'icehockey_nhl': {
        image: '/sports/hockey.svg',
        displayName: 'NHL',
        category: 'professional',
        baseKey: 'hockey'
      },
      'soccer_epl': {
        image: '/sports/soccer.svg',
        displayName: 'EPL',
        category: 'professional',
        baseKey: 'soccer'
      },
      'soccer_usa_mls': {
        image: '/sports/soccer.svg',
        displayName: 'MLS',
        category: 'professional',
        baseKey: 'soccer'
      },
      'baseball_mlb': {
        image: '/sports/baseball.svg',
        displayName: 'MLB',
        category: 'professional',
        baseKey: 'baseball'
      },
    };

    export default function GameFilters({
      selectedSports,
      onSportToggle,
      selectedStatus,
      onStatusChange,
      selectedBookmaker,
      onBookmakerChange,
      oddsFormat,
      onOddsFormatChange,
      selectedDate,
      onDateChange,
      availableSports,
      availableBookmakers,
    }: GameFiltersProps) {
      const [activeSportDropdown, setActiveSportDropdown] = useState<string | null>(null);

      // Group sports by base sport type
      const groupedSports = availableSports.reduce((acc, sport) => {
        const config = SPORT_CONFIG[sport.key];
        if (!config) return acc;

        if (!acc[config.baseKey]) {
          acc[config.baseKey] = {
            professional: [],
            college: [],
            image: config.image
          };
        }

        acc[config.baseKey][config.category].push(sport);
        return acc;
      }, {} as Record<string, {
        professional: typeof availableSports;
        college: typeof availableSports;
        image: string;
      }>);

      const toggleSportDropdown = (baseKey: string) => {
        const categories = groupedSports[baseKey];
        const hasBothCategories = categories.professional.length > 0 && categories.college.length > 0;

        if (hasBothCategories) {
          setActiveSportDropdown(activeSportDropdown === baseKey ? null : baseKey);
        } else {
          // If only one category, select it directly
          const singleSport = [...categories.professional, ...categories.college][0];
          if (singleSport) {
            onSportToggle(singleSport.key);
          }
        }
      };

      const isSportActive = (baseKey: string) => {
        const categories = groupedSports[baseKey];
        const allSports = [...categories.professional, ...categories.college];
        return allSports.some(sport => selectedSports.includes(sport.key));
      };

      const { isDarkMode } = useDarkMode();

      return (
        <div
          className="relative"
          style={{
            fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
            backgroundColor: isDarkMode ? '#020617' : '#f8fafc',
            color: isDarkMode ? '#e5e7eb' : '#1e293b',
            border: `4px solid ${isDarkMode ? '#e5e7eb' : '#cbd5e1'}`,
            padding: '16px',
            boxShadow: isDarkMode ? '0 0 0 2px rgba(229,231,235,0.12) inset, 0 8px 16px rgba(0,0,0,0.4)' : '0 0 0 2px rgba(203,213,225,0.3) inset, 0 8px 16px rgba(0,0,0,0.1)',
            imageRendering: 'pixelated',
          }}
        >
          {/* Pixel grid overlay */}
          <div
            style={{
              position: 'absolute',
              inset: 0,
              backgroundImage: isDarkMode
                ? 'linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px)'
                : 'linear-gradient(rgba(0,0,0,0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(0,0,0,0.03) 1px, transparent 1px)',
              backgroundSize: '6px 6px',
              pointerEvents: 'none',
            }}
          />

          {/* Vertical Filter Layout */}
          <div className="relative z-10 space-y-6">
            {/* Date Filter */}
            <div>
              <h3 className="text-[10px] font-bold tracking-wider uppercase opacity-60 mb-3">Date</h3>
              <input
                type="date"
                value={selectedDate}
                onChange={(e) => onDateChange(e.target.value)}
                className="w-full bg-gray-800 dark:bg-gray-800 bg-white text-gray-900 dark:text-white px-3 py-2 rounded border-2 border-gray-300 dark:border-gray-700 focus:border-red-600 focus:outline-none text-sm"
                style={{
                  fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace',
                }}
              />
            </div>

            {/* Status Filters */}
            <div>
              <h3 className="text-[10px] font-bold tracking-wider uppercase opacity-60 mb-3">Status</h3>
              <div className="flex flex-col gap-1.5">
                {[
                  { value: 'all', label: 'All' },
                  { value: 'upcoming', label: 'Upcoming' },
                  { value: 'live', label: 'Live', badge: '🔴' },
                  { value: 'completed', label: 'Final' },
                ].map((status) => (
                  <button
                    key={status.value}
                    onClick={() => onStatusChange(status.value)}
                    className={`
                      w-full px-3 py-1.5 font-bold text-[10px] tracking-wider transition-all rounded
                      ${
                        selectedStatus === status.value
                          ? 'bg-red-600 text-white'
                          : 'bg-gray-800 text-gray-400 hover:bg-gray-700'
                      }
                    `}
                  >
                    {status.badge && <span className="mr-1">{status.badge}</span>}
                    {status.label}
                  </button>
                ))}
              </div>
            </div>

            {/* Sport Filters */}
            <div>
              <h3 className="text-[10px] font-bold tracking-wider uppercase opacity-60 mb-3">Sports</h3>
              <div className="flex gap-2 items-center flex-wrap">
                {Object.entries(groupedSports).map(([baseKey, categories]) => {
                  const hasGames = [...categories.professional, ...categories.college].length > 0;
                  if (!hasGames) return null;

                  const isActive = isSportActive(baseKey);
                  const hasBothCategories = categories.professional.length > 0 && categories.college.length > 0;
                  const isDropdownOpen = activeSportDropdown === baseKey;

                  return (
                    <div key={baseKey} className="relative">
                      {/* Sport Icon Button */}
                      <button
                        onClick={() => toggleSportDropdown(baseKey)}
                        className={`
                          w-10 h-10 rounded-lg transition-all transform hover:scale-110 border-2
                          ${isActive
                            ? 'bg-red-600 border-red-500'
                            : 'bg-gray-800 border-gray-700 hover:border-gray-600'
                          }
                        `}
                        title={baseKey}
                      >
                        <img
                          src={categories.image}
                          alt={baseKey}
                          className="w-full h-full p-1.5"
                        />
                      </button>

                      {/* Dropdown Pill Box (only if both professional and college) */}
                      {hasBothCategories && isDropdownOpen && (
                        <div
                          className="absolute top-full left-0 mt-2 bg-gray-900 border-2 border-gray-700 rounded-lg p-2 min-w-[160px] z-50"
                          style={{
                            boxShadow: '0 4px 12px rgba(0,0,0,0.6)',
                          }}
                        >
                          {/* Professional */}
                          {categories.professional.length > 0 && (
                            <div className="mb-2">
                              <div className="text-[8px] font-bold tracking-wider uppercase opacity-60 mb-1.5 px-1">
                                Professional
                              </div>
                              <div className="flex flex-col gap-1">
                                {categories.professional.map((sport) => {
                                  const isSelected = selectedSports.includes(sport.key);
                                  const config = SPORT_CONFIG[sport.key];

                                  return (
                                    <button
                                      key={sport.key}
                                      onClick={() => {
                                        onSportToggle(sport.key);
                                        setActiveSportDropdown(null);
                                      }}
                                      className={`
                                        px-3 py-1.5 text-[10px] font-bold tracking-wider transition-all rounded-full
                                        flex items-center justify-between gap-2
                                        ${
                                          isSelected
                                            ? 'bg-red-600 text-white'
                                            : 'bg-gray-800 text-gray-400 hover:bg-gray-700'
                                        }
                                      `}
                                    >
                                      <span>{config?.displayName}</span>
                                      <span className="text-[8px] opacity-70">
                                        {sport.count}
                                      </span>
                                    </button>
                                  );
                                })}
                              </div>
                            </div>
                          )}

                          {/* College */}
                          {categories.college.length > 0 && (
                            <div>
                              <div className="text-[8px] font-bold tracking-wider uppercase opacity-60 mb-1.5 px-1">
                                College
                              </div>
                              <div className="flex flex-col gap-1">
                                {categories.college.map((sport) => {
                                  const isSelected = selectedSports.includes(sport.key);
                                  const config = SPORT_CONFIG[sport.key];

                                  return (
                                    <button
                                      key={sport.key}
                                      onClick={() => {
                                        onSportToggle(sport.key);
                                        setActiveSportDropdown(null);
                                      }}
                                      className={`
                                        px-3 py-1.5 text-[10px] font-bold tracking-wider transition-all rounded-full
                                        flex items-center justify-between gap-2
                                        ${
                                          isSelected
                                            ? 'bg-red-600 text-white'
                                            : 'bg-gray-800 text-gray-400 hover:bg-gray-700'
                                        }
                                      `}
                                    >
                                      <span>{config?.displayName}</span>
                                      <span className="text-[8px] opacity-70">
                                        {sport.count}
                                      </span>
                                    </button>
                                  );
                                })}
                              </div>
                            </div>
                          )}
                        </div>
                      )}
                    </div>
                  );
                })}
              </div>
            </div>

            {/* Bookmaker Filter */}
            <div>
              <h3 className="text-[10px] font-bold tracking-wider uppercase opacity-60 mb-3">Bookmaker</h3>
              <select
                value={selectedBookmaker}
                onChange={(e) => onBookmakerChange(e.target.value)}
                className="w-full bg-gray-800 text-white text-[10px] font-bold tracking-wider px-3 py-2 rounded border-2 border-gray-700 hover:border-gray-600 focus:border-red-600 focus:outline-none transition-colors"
              >
                <option value="all">All</option>
                {availableBookmakers.map(bookmaker => (
                  <option key={bookmaker} value={bookmaker}>
                    {bookmaker.charAt(0).toUpperCase() + bookmaker.slice(1)}
                  </option>
                ))}
              </select>
            </div>

            {/* Odds Format Filter */}
            <div>
              <h3 className="text-[10px] font-bold tracking-wider uppercase opacity-60 mb-3">Odds Format</h3>
              <div className="flex flex-col gap-1.5">
                {[
                  { value: 'american', label: 'American' },
                  { value: 'decimal', label: 'Decimal' },
                  { value: 'fractional', label: 'Fractional' },
                ].map((format) => (
                  <button
                    key={format.value}
                    onClick={() => onOddsFormatChange(format.value as any)}
                    className={`
                      w-full px-3 py-1.5 font-bold text-[10px] tracking-wider transition-all rounded
                      ${
                        oddsFormat === format.value
                          ? 'bg-red-600 text-white'
                          : 'bg-gray-800 text-gray-400 hover:bg-gray-700'
                      }
                    `}
                  >
                    {format.label}
                  </button>
                ))}
              </div>
            </div>

            {/* Clear All Button */}
            {(selectedSports.length > 0 || selectedStatus !== 'all' || selectedBookmaker !== 'all') && (
              <button
                onClick={() => {
                  selectedSports.forEach(sport => onSportToggle(sport));
                  onStatusChange('all');
                  onBookmakerChange('all');
                  setActiveSportDropdown(null);
                }}
                className="w-full text-red-400 hover:text-red-300 text-[10px] font-bold tracking-wider transition-colors px-3 py-2 rounded hover:bg-gray-800 border border-red-600"
              >
                CLEAR ALL FILTERS
              </button>
            )}
          </div>
        </div>
      );
    }