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 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 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 | 'use client' import { useState, useCallback, useMemo, useRef, useEffect } from 'react' import * as Tooltip from '@radix-ui/react-tooltip' import { useSpring } from '@react-spring/web' import { css } from '@styled/css' import { RangeThermometer, type ThermometerOption, type RangePreviewState, } from '@/components/Thermometer' import { useTheme } from '@/contexts/ThemeContext' import { MapSelectorMap } from './MapSelectorMap' import { RegionListPanel } from './RegionListPanel' import { WORLD_MAP, calculateContinentViewBox, filterRegionsByContinent, hasSubMap, getSubMapEntry, getSubMapData, getSubMapsForContinent, parseViewBox, calculateFitCropViewBox, calculateBoundingBox, getFilteredMapDataBySizesSync, REGION_SIZE_CONFIG, ALL_REGION_SIZES, IMPORTANCE_LEVEL_CONFIG, ALL_IMPORTANCE_LEVELS, POPULATION_LEVEL_CONFIG, ALL_POPULATION_LEVELS, FILTER_CRITERIA_CONFIG, filterRegionsByImportance, filterRegionsByPopulation, filterRegionsBySizes, calculateSafeZoneViewBox, type SafeZoneMargins, } from '../maps' import { getCustomCrop } from '../customCrops' import type { RegionSize, ImportanceLevel, PopulationLevel, FilterCriteria } from '../maps' import { CONTINENTS, getContinentForCountry, COUNTRY_TO_CONTINENT, type ContinentId, } from '../continents' import { sizesToRange, rangeToSizes, importanceToRange, rangeToImportance, populationToRange, rangeToPopulation, } from '../utils/regionSizeUtils' import { preventFlexExpansion } from '../utils/responsiveStyles' /** * Safe zone margins - must match MapRenderer for consistent positioning * These define areas reserved for floating UI elements during gameplay */ const SAFE_ZONE_MARGINS: SafeZoneMargins = { top: 290, // Space for nav (~150px) + floating prompt (~140px with name input + controls row) right: 0, // Controls now in floating prompt, no right margin needed bottom: 0, // Error banner can overlap map left: 0, } /** * Size options for the range thermometer, ordered from largest to smallest */ const SIZE_OPTIONS: ThermometerOption<RegionSize>[] = ALL_REGION_SIZES.map((size) => ({ value: size, label: REGION_SIZE_CONFIG[size].label, shortLabel: REGION_SIZE_CONFIG[size].label, emoji: REGION_SIZE_CONFIG[size].emoji, })) /** * Importance options for the range thermometer, ordered from most to least important */ const IMPORTANCE_OPTIONS: ThermometerOption<ImportanceLevel>[] = ALL_IMPORTANCE_LEVELS.map( (level) => ({ value: level, label: IMPORTANCE_LEVEL_CONFIG[level].label, shortLabel: IMPORTANCE_LEVEL_CONFIG[level].label, emoji: IMPORTANCE_LEVEL_CONFIG[level].emoji, }) ) /** * Population options for the range thermometer, ordered from largest to smallest */ const POPULATION_OPTIONS: ThermometerOption<PopulationLevel>[] = ALL_POPULATION_LEVELS.map( (level) => ({ value: level, label: POPULATION_LEVEL_CONFIG[level].label, shortLabel: POPULATION_LEVEL_CONFIG[level].label, emoji: POPULATION_LEVEL_CONFIG[level].emoji, }) ) /** * All filter criteria tabs */ const ALL_FILTER_CRITERIA: FilterCriteria[] = ['size', 'importance', 'population'] /** * Selection path for drill-down navigation: * - [] = World level * - [ContinentId] = Continent level (showing cropped world map) * - [ContinentId, SubMapId] = Sub-map level (e.g., USA states) */ export type SelectionPath = [] | [ContinentId] | [ContinentId, string] /** * Planet data type for joke placeholder */ interface PlanetData { id: string name: string color: string size: number hasStripes?: boolean hasRings?: boolean } /** * Joke placeholder: Other planets for when viewing Earth (world map) * Just for fun - these don't actually do anything */ const PLANETS: PlanetData[] = [ { id: 'mercury', name: 'Mercury', color: '#b0b0b0', size: 0.38 }, { id: 'venus', name: 'Venus', color: '#e6c87a', size: 0.95 }, { id: 'mars', name: 'Mars', color: '#c1440e', size: 0.53 }, { id: 'jupiter', name: 'Jupiter', color: '#d8ca9d', size: 2.0, hasStripes: true, }, { id: 'saturn', name: 'Saturn', color: '#ead6b8', size: 1.7, hasRings: true }, ] interface DrillDownMapSelectorProps { /** Callback when selection changes (map/continent for game start) */ onSelectionChange: (mapId: 'world' | 'usa', continentId: ContinentId | 'all') => void /** Callback when user clicks a country without sub-map (immediate game start) */ onStartGame: () => void /** Current selected map (for initial state sync) */ selectedMap: 'world' | 'usa' /** Current selected continent (for initial state sync) */ selectedContinent: ContinentId | 'all' /** Region sizes to include (for showing excluded regions dimmed) */ includeSizes: RegionSize[] /** Callback when region sizes change */ onRegionSizesChange: (sizes: RegionSize[]) => void /** Region counts per size category */ regionCountsBySize: Record<string, number> /** When true, fills parent container and uses overlay positioning for UI elements */ fillContainer?: boolean } interface BreadcrumbItem { label: string emoji: string path: SelectionPath isClickable: boolean } export function DrillDownMapSelector({ onSelectionChange, onStartGame, selectedMap, selectedContinent, includeSizes, onRegionSizesChange, regionCountsBySize, fillContainer = false, }: DrillDownMapSelectorProps) { const { resolvedTheme } = useTheme() const isDark = resolvedTheme === 'dark' // Initialize path from props const getInitialPath = (): SelectionPath => { if (selectedMap === 'usa') { // USA sub-map selected return ['north-america', 'us'] } if (selectedContinent !== 'all') { // Continent selected return [selectedContinent] } // World level return [] } const [path, setPath] = useState<SelectionPath>(getInitialPath) const [hoveredRegion, setHoveredRegion] = useState<string | null>(null) const [sizeRangePreview, setSizeRangePreview] = useState<RangePreviewState<RegionSize> | null>( null ) const [containerDimensions, setContainerDimensions] = useState({ width: 0, height: 0, }) const containerRef = useRef<HTMLDivElement>(null) // Track which region name is being hovered in the popover (for zoom preview) const [previewRegionName, setPreviewRegionName] = useState<string | null>(null) // Filter criteria tab state const [activeFilterCriteria, setActiveFilterCriteria] = useState<FilterCriteria>('size') // Local state for importance and population filters (not persisted, just for display filtering) const [includeImportance, setIncludeImportance] = useState<ImportanceLevel[]>([ 'superpower', 'major', 'regional', ]) const [includePopulation, setIncludePopulation] = useState<PopulationLevel[]>([ 'huge', 'large', 'medium', ]) // Preview states for importance and population thermometers const [importanceRangePreview, setImportanceRangePreview] = useState<RangePreviewState<ImportanceLevel> | null>(null) const [populationRangePreview, setPopulationRangePreview] = useState<RangePreviewState<PopulationLevel> | null>(null) // Sync local path state when props change from external sources (e.g., other players) useEffect(() => { const expectedPath = getInitialPath() const pathMatches = path.length === expectedPath.length && path.every((p, i) => p === expectedPath[i]) if (!pathMatches) { setPath(expectedPath) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [selectedMap, selectedContinent]) // Measure container dimensions for viewBox calculation useEffect(() => { const measureContainer = () => { if (containerRef.current) { const rect = containerRef.current.getBoundingClientRect() setContainerDimensions({ width: rect.width, height: rect.height }) } } measureContainer() window.addEventListener('resize', measureContainer) return () => window.removeEventListener('resize', measureContainer) }, []) // Derived state const currentLevel = path.length // Get current map data and viewBox based on path const { mapData, viewBox, visibleRegions, highlightedRegions } = useMemo(() => { if (currentLevel === 2) { // Sub-map level (e.g., USA states) const subMapId = path[1] const subMapData = getSubMapData(subMapId) if (subMapData) { // For USA in fillContainer mode, use safe zone calculation to match gameplay if (fillContainer && containerDimensions.width > 0 && containerDimensions.height > 0) { const originalBounds = parseViewBox(subMapData.viewBox) // USA doesn't have custom crops, so use full map bounds const customCrop = getCustomCrop('usa', 'all') const cropRegion = customCrop ? parseViewBox(customCrop) : originalBounds const safeZoneViewBox = calculateSafeZoneViewBox( containerDimensions.width, containerDimensions.height, SAFE_ZONE_MARGINS, cropRegion, originalBounds ) return { mapData: subMapData, viewBox: safeZoneViewBox, visibleRegions: undefined, highlightedRegions: [], } } return { mapData: subMapData, viewBox: subMapData.viewBox, visibleRegions: undefined, // Show all regions in sub-map highlightedRegions: [], // No further drill-down from USA states } } } // World or continent level - use world map // path[0] is guaranteed to be ContinentId when currentLevel >= 1 const continentId: ContinentId | 'all' = currentLevel >= 1 && path[0] ? path[0] : 'all' // For fillContainer mode (playing phase), use the same safe zone calculation as MapRenderer // This ensures the map positioning matches exactly between setup and gameplay if (fillContainer && containerDimensions.width > 0 && containerDimensions.height > 0) { const originalBounds = parseViewBox(WORLD_MAP.viewBox) // Use custom crop if defined, otherwise use full map bounds (same logic as MapRenderer) const customCrop = continentId !== 'all' ? getCustomCrop('world', continentId) : null const cropRegion = customCrop ? parseViewBox(customCrop) : originalBounds const safeZoneViewBox = calculateSafeZoneViewBox( containerDimensions.width, containerDimensions.height, SAFE_ZONE_MARGINS, cropRegion, originalBounds ) // Filter visible regions if on continent level const visible = continentId !== 'all' ? filterRegionsByContinent(WORLD_MAP.regions, continentId).map((r) => r.id) : undefined // Get regions with sub-maps for this continent (or all continents if world level) let highlighted: string[] = [] if (continentId !== 'all') { highlighted = getSubMapsForContinent(continentId) } else { const allContinentIds: ContinentId[] = [ 'africa', 'asia', 'europe', 'north-america', 'oceania', 'south-america', ] highlighted = allContinentIds.flatMap((cId) => getSubMapsForContinent(cId)) } return { mapData: WORLD_MAP, viewBox: safeZoneViewBox, visibleRegions: visible, highlightedRegions: highlighted, } } // Non-fillContainer mode: use expanded viewBox for better context during setup // Calculate viewBox for continent (or full world) const gameplayViewBox = calculateContinentViewBox( WORLD_MAP.regions, continentId, WORLD_MAP.viewBox, 'world' ) // Expand the viewBox by 30% on each side for selector (less zoomed in) // But only for continent views, not world view let adjustedViewBox = gameplayViewBox if (continentId !== 'all') { const parsed = parseViewBox(gameplayViewBox) const originalParsed = parseViewBox(WORLD_MAP.viewBox) const expandFactor = 0.3 // 30% expansion on each side const expandX = parsed.width * expandFactor const expandY = parsed.height * expandFactor // Calculate expanded crop region (clamped to original map bounds) const cropX = Math.max(originalParsed.x, parsed.x - expandX) const cropY = Math.max(originalParsed.y, parsed.y - expandY) const cropWidth = Math.min( originalParsed.x + originalParsed.width - cropX, parsed.width + expandX * 2 ) const cropHeight = Math.min( originalParsed.y + originalParsed.height - cropY, parsed.height + expandY * 2 ) // Use calculateFitCropViewBox to adjust for container aspect ratio // This ensures the crop fits within the container without clipping if (containerDimensions.width > 0 && containerDimensions.height > 0) { const containerAspect = containerDimensions.width / containerDimensions.height adjustedViewBox = calculateFitCropViewBox( originalParsed, { x: cropX, y: cropY, width: cropWidth, height: cropHeight }, containerAspect ) } else { // Fallback before container is measured adjustedViewBox = `${cropX.toFixed(2)} ${cropY.toFixed(2)} ${cropWidth.toFixed(2)} ${cropHeight.toFixed(2)}` } } // Filter visible regions if on continent level const visible = continentId !== 'all' ? filterRegionsByContinent(WORLD_MAP.regions, continentId).map((r) => r.id) : undefined // Get regions with sub-maps for this continent (or all continents if world level) let highlighted: string[] = [] if (continentId !== 'all') { highlighted = getSubMapsForContinent(continentId) } else { // At world level, collect all regions with sub-maps across all continents const allContinentIds: ContinentId[] = [ 'africa', 'asia', 'europe', 'north-america', 'oceania', 'south-america', ] highlighted = allContinentIds.flatMap((cId) => getSubMapsForContinent(cId)) } return { mapData: WORLD_MAP, viewBox: adjustedViewBox, visibleRegions: visible, highlightedRegions: highlighted, } }, [currentLevel, path, containerDimensions, fillContainer]) // Region groups for hover highlighting at world level // Maps each country to its continent so hovering one country highlights all countries in that continent const regionGroups = useMemo(() => { if (currentLevel !== 0) return undefined // Build a Map from country ID to continent ID const groups = new Map<string, string>() for (const [countryId, continentId] of Object.entries(COUNTRY_TO_CONTINENT)) { groups.set(countryId, continentId) } return groups }, [currentLevel]) // Get base regions for the current view (continent filtered but no criteria filtering) const baseRegions = useMemo(() => { const mapId = currentLevel === 2 && path[1] ? 'usa' : 'world' const continentId: ContinentId | 'all' = currentLevel >= 1 && path[0] ? path[0] : selectedContinent const allRegionsMapData = getFilteredMapDataBySizesSync( mapId as 'world' | 'usa', continentId, ['huge', 'large', 'medium', 'small', 'tiny'] // All sizes ) return allRegionsMapData.regions }, [currentLevel, path, selectedContinent]) // Get the active filter levels based on current tab const activeFilterLevels = useMemo(() => { switch (activeFilterCriteria) { case 'size': return includeSizes case 'importance': return includeImportance case 'population': return includePopulation default: return includeSizes } }, [activeFilterCriteria, includeSizes, includeImportance, includePopulation]) // Calculate excluded regions based on active filter criteria const excludedRegions = useMemo(() => { const allRegionIds = new Set(baseRegions.map((r) => r.id)) // Filter based on active criteria let filteredRegions = baseRegions switch (activeFilterCriteria) { case 'size': filteredRegions = filterRegionsBySizes(baseRegions, includeSizes, 'world') break case 'importance': filteredRegions = filterRegionsByImportance(baseRegions, includeImportance) break case 'population': filteredRegions = filterRegionsByPopulation(baseRegions, includePopulation) break } const filteredRegionIds = new Set(filteredRegions.map((r) => r.id)) // Excluded = all regions minus filtered regions const excluded: string[] = [] for (const regionId of allRegionIds) { if (!filteredRegionIds.has(regionId)) { excluded.push(regionId) } } return excluded }, [baseRegions, activeFilterCriteria, includeSizes, includeImportance, includePopulation]) // Compute region names by size category (for tooltip display) const regionNamesBySize = useMemo(() => { const result: Partial<Record<RegionSize, string[]>> = {} for (const size of ALL_REGION_SIZES) { const filtered = filterRegionsBySizes(baseRegions, [size], 'world') result[size] = filtered.map((r) => r.name).sort((a, b) => a.localeCompare(b)) } return result }, [baseRegions]) // Compute region names by importance category const regionNamesByImportance = useMemo(() => { const result: Partial<Record<ImportanceLevel, string[]>> = {} for (const level of ALL_IMPORTANCE_LEVELS) { const filtered = filterRegionsByImportance(baseRegions, [level]) result[level] = filtered.map((r) => r.name).sort((a, b) => a.localeCompare(b)) } return result }, [baseRegions]) // Compute region names by population category const regionNamesByPopulation = useMemo(() => { const result: Partial<Record<PopulationLevel, string[]>> = {} for (const level of ALL_POPULATION_LEVELS) { const filtered = filterRegionsByPopulation(baseRegions, [level]) result[level] = filtered.map((r) => r.name).sort((a, b) => a.localeCompare(b)) } return result }, [baseRegions]) // Compute region counts by category for the active filter criteria const regionCountsByCriteria = useMemo(() => { switch (activeFilterCriteria) { case 'size': return Object.fromEntries( Object.entries(regionNamesBySize).map(([k, v]) => [k, v?.length ?? 0]) ) case 'importance': return Object.fromEntries( Object.entries(regionNamesByImportance).map(([k, v]) => [k, v?.length ?? 0]) ) case 'population': return Object.fromEntries( Object.entries(regionNamesByPopulation).map(([k, v]) => [k, v?.length ?? 0]) ) default: return {} } }, [activeFilterCriteria, regionNamesBySize, regionNamesByImportance, regionNamesByPopulation]) // Compute all selected region names (for popover display) based on active filter const selectedRegionNames = useMemo(() => { let filteredRegions = baseRegions switch (activeFilterCriteria) { case 'size': filteredRegions = filterRegionsBySizes(baseRegions, includeSizes, 'world') break case 'importance': filteredRegions = filterRegionsByImportance(baseRegions, includeImportance) break case 'population': filteredRegions = filterRegionsByPopulation(baseRegions, includePopulation) break } return filteredRegions.map((r) => r.name) }, [baseRegions, activeFilterCriteria, includeSizes, includeImportance, includePopulation]) // Create lookup map from region name → region data (for zoom preview) const regionsByName = useMemo(() => { const lookup = new Map<string, { id: string; name: string; path: string }>() for (const region of mapData.regions) { lookup.set(region.name, region) } return lookup }, [mapData.regions]) // Calculate zoomed viewBox when previewing a region from the popover const previewViewBox = useMemo(() => { if (!previewRegionName) return null const region = regionsByName.get(previewRegionName) if (!region) return null // Calculate bounding box for the region const bbox = calculateBoundingBox([region.path]) // Add substantial padding around the region (100% on each side) // This gives good context while still focusing on the region const paddingFactor = 1.0 const paddingX = bbox.width * paddingFactor const paddingY = bbox.height * paddingFactor let cropWidth = bbox.width + paddingX * 2 let cropHeight = bbox.height + paddingY * 2 // Enforce minimum viewBox size to prevent over-zooming on tiny islands // This ensures we never zoom in more than ~10% of the original map const originalParsed = parseViewBox(mapData.viewBox) const minWidth = originalParsed.width * 0.1 const minHeight = originalParsed.height * 0.1 // If crop is smaller than minimum, expand it while keeping region centered if (cropWidth < minWidth) { cropWidth = minWidth } if (cropHeight < minHeight) { cropHeight = minHeight } // Center the crop region on the bbox center const bboxCenterX = bbox.minX + bbox.width / 2 const bboxCenterY = bbox.minY + bbox.height / 2 const cropRegion = { x: bboxCenterX - cropWidth / 2, y: bboxCenterY - cropHeight / 2, width: cropWidth, height: cropHeight, } // Use calculateFitCropViewBox to adjust for container aspect ratio if (containerDimensions.width > 0 && containerDimensions.height > 0) { const containerAspect = containerDimensions.width / containerDimensions.height return calculateFitCropViewBox(originalParsed, cropRegion, containerAspect) } // Fallback return `${cropRegion.x} ${cropRegion.y} ${cropRegion.width} ${cropRegion.height}` }, [previewRegionName, regionsByName, containerDimensions, mapData.viewBox]) // Animated viewBox for smooth transitions const targetViewBox = previewViewBox || viewBox const parsedTarget = parseViewBox(targetViewBox) const springProps = useSpring({ x: parsedTarget.x, y: parsedTarget.y, width: parsedTarget.width, height: parsedTarget.height, config: { tension: 200, friction: 25 }, }) const animatedViewBox = springProps.x.to( (x) => `${x.toFixed(2)} ${springProps.y.get().toFixed(2)} ${springProps.width.get().toFixed(2)} ${springProps.height.get().toFixed(2)}` ) // Get the region ID for the focused region name (for highlighting on the map) const focusedRegionId = useMemo(() => { if (!previewRegionName) return null const region = regionsByName.get(previewRegionName) return region?.id ?? null }, [previewRegionName, regionsByName]) // Calculate preview regions based on hovering over the thermometer // Shows what regions would be added or removed if the user clicks const { previewAddRegions, previewRemoveRegions } = useMemo(() => { // Determine which preview state to use based on active filter criteria const activePreview = activeFilterCriteria === 'size' ? sizeRangePreview : activeFilterCriteria === 'importance' ? importanceRangePreview : populationRangePreview if (!activePreview) { return { previewAddRegions: [], previewRemoveRegions: [] } } // Get current included region IDs based on active criteria let currentFiltered = baseRegions switch (activeFilterCriteria) { case 'size': currentFiltered = filterRegionsBySizes(baseRegions, includeSizes, 'world') break case 'importance': currentFiltered = filterRegionsByImportance(baseRegions, includeImportance) break case 'population': currentFiltered = filterRegionsByPopulation(baseRegions, includePopulation) break } const currentIncludedIds = new Set(currentFiltered.map((r) => r.id)) // Get preview included region IDs (if user clicked) let previewFiltered = baseRegions switch (activeFilterCriteria) { case 'size': if (sizeRangePreview) { const previewSizes = rangeToSizes( sizeRangePreview.previewMin, sizeRangePreview.previewMax ) previewFiltered = filterRegionsBySizes(baseRegions, previewSizes, 'world') } break case 'importance': if (importanceRangePreview) { const previewLevels = rangeToImportance( importanceRangePreview.previewMin, importanceRangePreview.previewMax ) previewFiltered = filterRegionsByImportance(baseRegions, previewLevels) } break case 'population': if (populationRangePreview) { const previewLevels = rangeToPopulation( populationRangePreview.previewMin, populationRangePreview.previewMax ) previewFiltered = filterRegionsByPopulation(baseRegions, previewLevels) } break } const previewIncludedIds = new Set(previewFiltered.map((r) => r.id)) // Regions that would be ADDED (in preview but not currently included) const addRegions: string[] = [] for (const id of previewIncludedIds) { if (!currentIncludedIds.has(id)) { addRegions.push(id) } } // Regions that would be REMOVED (currently included but not in preview) const removeRegions: string[] = [] for (const id of currentIncludedIds) { if (!previewIncludedIds.has(id)) { removeRegions.push(id) } } return { previewAddRegions: addRegions, previewRemoveRegions: removeRegions, } }, [ activeFilterCriteria, sizeRangePreview, importanceRangePreview, populationRangePreview, baseRegions, includeSizes, includeImportance, includePopulation, ]) // Compute the label to display for the hovered region // Shows the next drill-down level name, not the individual region name const hoveredLabel = useMemo(() => { if (!hoveredRegion) { // Not hovering - show current selection or level name if (currentLevel === 0) { // At world level - show selected continent if any, otherwise "World" if (selectedContinent !== 'all') { const continent = CONTINENTS.find((c) => c.id === selectedContinent) return continent?.name ?? 'World' } return 'World' } if (currentLevel === 1 && path[0]) { const continent = CONTINENTS.find((c) => c.id === path[0]) return continent?.name ?? 'Continent' } if (currentLevel === 2 && path[1]) { const entry = getSubMapEntry(path[1]) return entry?.name ?? 'Region' } return '' } // Hovering - show next level name if (currentLevel === 0) { // At world level, show continent name const continentId = getContinentForCountry(hoveredRegion) if (continentId) { const continent = CONTINENTS.find((c) => c.id === continentId) return continent?.name ?? continentId } return '' } if (currentLevel === 1 && path[0]) { // At continent level - only show name if region has a sub-map to drill into if (hasSubMap(hoveredRegion)) { const entry = getSubMapEntry(hoveredRegion) return entry?.name ?? hoveredRegion } // No sub-map - just show the continent name (clicking starts game with continent) const continent = CONTINENTS.find((c) => c.id === path[0]) return continent?.name ?? 'Continent' } if (currentLevel === 2) { // At sub-map level (e.g., USA states) - show region name const region = mapData.regions.find((r) => r.id === hoveredRegion) return region?.name ?? hoveredRegion } return '' }, [hoveredRegion, currentLevel, path, mapData.regions, selectedContinent]) // Compute hint text for what clicking will do const hoveredHint = useMemo(() => { if (!hoveredRegion) return null if (currentLevel === 0) { // World level - always zoom into continent return 'click to zoom in' } if (currentLevel === 1) { if (hasSubMap(hoveredRegion)) { return 'click to drill down' } return 'click to start game' } if (currentLevel === 2) { return 'click to start game' } return null }, [hoveredRegion, currentLevel]) // Build breadcrumbs const breadcrumbs: BreadcrumbItem[] = useMemo(() => { const crumbs: BreadcrumbItem[] = [ { label: 'World', emoji: '🌍', path: [], isClickable: currentLevel > 0 }, ] if (currentLevel >= 1 && path[0]) { const continentPath = path[0] const continent = CONTINENTS.find((c) => c.id === continentPath) if (continent) { crumbs.push({ label: continent.name, emoji: continent.emoji, path: [continentPath], isClickable: currentLevel > 1, }) } } if (currentLevel >= 2 && path[0] && path[1]) { const subMapEntry = getSubMapEntry(path[1]) if (subMapEntry) { crumbs.push({ label: subMapEntry.name, emoji: subMapEntry.emoji, path: [path[0], path[1]] as SelectionPath, isClickable: false, // Current level is never clickable }) } } return crumbs }, [currentLevel, path]) // Get peer navigation items (or planets as joke at world level) const peers = useMemo(() => { if (currentLevel === 0) { // World level - show planets as joke placeholder return PLANETS.map((planet) => ({ id: planet.id, label: planet.name, emoji: '', // Planets don't have emojis, we'll render SVG path: [] as SelectionPath, // Clicking does nothing isPlanet: true as const, planetData: planet, })) } if (currentLevel === 1 && path[0]) { const currentContinent = path[0] // Continent level - show other continents return CONTINENTS.filter((c) => c.id !== currentContinent && c.id !== 'antarctica').map( (c) => ({ id: c.id, label: c.name, emoji: c.emoji, path: [c.id] as SelectionPath, }) ) } if (currentLevel === 2 && path[0] && path[1]) { const currentContinent = path[0] const currentSubMap = path[1] // Sub-map level - show other sub-maps in same continent (if any) const siblingSubMaps = getSubMapsForContinent(currentContinent) return siblingSubMaps .filter((regionId) => regionId !== currentSubMap) .map((regionId) => { const entry = getSubMapEntry(regionId) return entry ? { id: regionId, label: entry.name, emoji: entry.emoji, path: [currentContinent, regionId] as SelectionPath, } : null }) .filter(Boolean) as Array<{ id: string label: string emoji: string path: SelectionPath }> } return [] }, [currentLevel, path]) // Get region count for start button const regionCount = useMemo(() => { if (currentLevel === 2 && path[1]) { const subMapData = getSubMapData(path[1]) return subMapData?.regions.length ?? 0 } // Use selectedContinent at world level, or path[0] at continent level const continentId: ContinentId | 'all' = currentLevel >= 1 && path[0] ? path[0] : selectedContinent const regions = filterRegionsByContinent(WORLD_MAP.regions, continentId) return regions.length }, [currentLevel, path, selectedContinent]) // Get context label for start button const contextLabel = useMemo(() => { if (currentLevel === 2 && path[1]) { const entry = getSubMapEntry(path[1]) return entry?.name ?? 'Region' } if (currentLevel === 1 && path[0]) { const continent = CONTINENTS.find((c) => c.id === path[0]) return continent?.name ?? 'Continent' } // At world level, use selectedContinent if set if (selectedContinent !== 'all') { const continent = CONTINENTS.find((c) => c.id === selectedContinent) return continent?.name ?? 'World' } return 'World' }, [currentLevel, path, selectedContinent]) // Handle region click const handleRegionClick = useCallback( (regionId: string) => { if (currentLevel === 0) { // World level - clicking any country drills into its continent const continent = getContinentForCountry(regionId) if (continent && continent !== 'antarctica') { // Always drill down to continent level setPath([continent]) onSelectionChange('world', continent) } } else if (currentLevel === 1 && path[0]) { const currentContinent = path[0] // Continent level - check for sub-map or start game if (hasSubMap(regionId)) { // Drill into sub-map setPath([currentContinent, regionId]) // Sync selection to the sub-map const entry = getSubMapEntry(regionId) if (entry?.mapId === 'usa') { onSelectionChange('usa', 'all') } } else { // No sub-map - start game immediately onStartGame() } } else if (currentLevel === 2) { // Sub-map level (e.g., USA states) - start game immediately onStartGame() } }, [currentLevel, path, onSelectionChange, onStartGame] ) // Handle breadcrumb click const handleBreadcrumbClick = useCallback( (targetPath: SelectionPath) => { setPath(targetPath) // Sync selection change if (targetPath.length === 0) { onSelectionChange('world', 'all') } else if (targetPath.length === 1 && targetPath[0]) { onSelectionChange('world', targetPath[0]) } // Level 2 keeps its own selection }, [onSelectionChange] ) // Handle peer click const handlePeerClick = useCallback( (targetPath: SelectionPath) => { setPath(targetPath) // Sync selection change if (targetPath.length === 1 && targetPath[0]) { onSelectionChange('world', targetPath[0]) } else if (targetPath.length === 2 && targetPath[1]) { const entry = getSubMapEntry(targetPath[1]) if (entry?.mapId === 'usa') { onSelectionChange('usa', 'all') } } }, [onSelectionChange] ) // Handle zoom out const handleZoomOut = useCallback(() => { if (currentLevel === 2 && path[0]) { const currentContinent = path[0] // Go back to continent setPath([currentContinent]) onSelectionChange('world', currentContinent) } else if (currentLevel === 1) { // Go back to world setPath([]) onSelectionChange('world', 'all') } }, [currentLevel, path, onSelectionChange]) return ( <div data-component="drill-down-map-selector" className={css({ width: '100%', ...(fillContainer && { height: '100%', position: 'relative' }), })} > {/* Breadcrumb Navigation - different styles for fillContainer vs normal */} {fillContainer ? ( /* Breadcrumb navigation overlay for full-screen mode */ <div data-element="navigation-overlay" className={css({ position: 'absolute', top: '164px', left: { base: '12px', sm: '24px' }, zIndex: 50, display: 'flex', flexDirection: { base: 'column', sm: 'row' }, alignItems: { base: 'flex-start', sm: 'center' }, gap: { base: '1', sm: '2' }, padding: '2', bg: isDark ? 'gray.800' : 'gray.100', rounded: 'xl', shadow: 'lg', fontSize: 'sm', })} > {breadcrumbs.map((crumb, index) => ( <span key={crumb.label} className={css({ display: 'flex', alignItems: 'center', gap: '1', })} > {index > 0 && ( <span className={css({ color: isDark ? 'gray.500' : 'gray.400', display: { base: 'none', sm: 'inline' }, })} > › </span> )} {crumb.isClickable ? ( <button data-action={`nav-${crumb.label.toLowerCase().replace(/\s/g, '-')}`} onClick={() => handleBreadcrumbClick(crumb.path)} className={css({ display: 'flex', alignItems: 'center', gap: '1', color: isDark ? 'blue.400' : 'blue.600', cursor: 'pointer', background: 'none', border: 'none', padding: '0', font: 'inherit', _hover: { textDecoration: 'underline' }, })} > <span>{crumb.emoji}</span> <span>{crumb.label}</span> </button> ) : ( <span className={css({ display: 'flex', alignItems: 'center', gap: '1', fontWeight: 'bold', color: isDark ? 'gray.100' : 'gray.800', })} > <span>{crumb.emoji}</span> <span>{crumb.label}</span> </span> )} </span> ))} </div> ) : ( /* Normal breadcrumb for non-fillContainer mode */ <div data-element="breadcrumbs" className={css({ display: 'flex', alignItems: 'center', gap: '2', fontSize: 'sm', flexWrap: 'wrap', marginBottom: '3', })} > {breadcrumbs.map((crumb, index) => ( <span key={crumb.label} className={css({ display: 'flex', alignItems: 'center', gap: '1', })} > {index > 0 && ( <span className={css({ color: isDark ? 'gray.500' : 'gray.400' })}>›</span> )} {crumb.isClickable ? ( <button data-action={`nav-${crumb.label.toLowerCase().replace(/\s/g, '-')}`} onClick={() => handleBreadcrumbClick(crumb.path)} className={css({ display: 'flex', alignItems: 'center', gap: '1', color: isDark ? 'blue.400' : 'blue.600', cursor: 'pointer', _hover: { textDecoration: 'underline' }, })} > <span>{crumb.emoji}</span> <span>{crumb.label}</span> </button> ) : ( <span className={css({ display: 'flex', alignItems: 'center', gap: '1', fontWeight: 'bold', color: isDark ? 'gray.100' : 'gray.800', })} > <span>{crumb.emoji}</span> <span>{crumb.label}</span> </span> )} </span> ))} </div> )} {/* Interactive Map - wrapped in ref'd container for dimension measurement */} <div ref={containerRef} data-element="map-container" className={css({ position: 'relative', ...(fillContainer && { width: '100%', height: '100%' }), })} > <MapSelectorMap fillContainer={fillContainer} mapData={mapData} viewBox={viewBox} onRegionClick={handleRegionClick} onRegionHover={setHoveredRegion} hoveredRegion={hoveredRegion} highlightedRegions={highlightedRegions} visibleRegions={visibleRegions} regionGroups={regionGroups} selectedGroup={ currentLevel === 0 && selectedContinent !== 'all' ? selectedContinent : null } hoverableRegions={currentLevel === 1 ? highlightedRegions : undefined} excludedRegions={excludedRegions} previewAddRegions={previewAddRegions} previewRemoveRegions={previewRemoveRegions} animatedViewBox={animatedViewBox} focusedRegion={focusedRegionId} /> {/* Zoom Out Button - only shown when NOT in fillContainer mode (fillContainer has navigation overlay) */} {!fillContainer && currentLevel > 0 && (() => { // Calculate what we're going back to const backToWorld = currentLevel === 1 const backToContinentId = currentLevel === 2 ? path[0] : null const backLabel = backToWorld ? 'World' : (CONTINENTS.find((c) => c.id === backToContinentId)?.name ?? 'Continent') // Get viewBox and regions for the mini-map preview const backViewBox = backToWorld ? WORLD_MAP.viewBox : backToContinentId ? calculateContinentViewBox( WORLD_MAP.regions, backToContinentId, WORLD_MAP.viewBox, 'world' ) : WORLD_MAP.viewBox const backRegions = backToWorld ? WORLD_MAP.regions : backToContinentId ? filterRegionsByContinent(WORLD_MAP.regions, backToContinentId) : [] return ( <button data-action="zoom-out" onClick={handleZoomOut} className={css({ position: 'absolute', top: '3', left: '3', display: 'flex', alignItems: 'center', gap: '2', padding: '2', fontSize: 'sm', color: isDark ? 'gray.100' : 'gray.700', bg: isDark ? 'gray.800' : 'gray.100', rounded: 'lg', cursor: 'pointer', border: '2px solid', borderColor: isDark ? 'gray.700' : 'gray.300', boxShadow: 'md', zIndex: 10, transition: 'all 0.15s', _hover: { borderColor: isDark ? 'blue.500' : 'blue.400', bg: isDark ? 'gray.700' : 'gray.200', }, })} > <span className={css({ fontSize: 'md' })}>←</span> {/* Mini-map preview */} <div className={css({ width: '64px', aspectRatio: '16 / 10', bg: isDark ? 'gray.900' : 'gray.50', rounded: 'sm', overflow: 'hidden', })} > <svg viewBox={backViewBox} className={css({ width: '100%', height: '100%', display: 'block', })} preserveAspectRatio="xMidYMid meet" > {/* Ocean background */} <rect x="-10000" y="-10000" width="30000" height="30000" fill={isDark ? '#111827' : '#e0f2fe'} /> {/* Render regions */} {backRegions.map((region) => ( <path key={region.id} d={region.path} fill={isDark ? '#4a5568' : '#d4c4a8'} stroke={isDark ? '#374151' : '#9ca3af'} strokeWidth={0.5} /> ))} </svg> </div> <span className={css({ fontWeight: '600' })}>{backLabel}</span> </button> ) })()} {/* Right-side controls container - region filter selector with tabs */} <div data-element="right-controls" className={css({ position: 'absolute', top: fillContainer ? '164px' : '3', right: { base: '8px', sm: '24px' }, zIndex: 10, transform: { base: 'scale(0.75)', sm: 'scale(1)' }, transformOrigin: 'top right', })} > {/* Region Filter Selector with tabs */} <div data-element="region-filters" className={css({ display: 'flex', flexDirection: 'column', alignItems: 'stretch', padding: '3', bg: isDark ? 'gray.800' : 'gray.100', rounded: 'xl', shadow: 'lg', width: '205px', maxHeight: { base: 'none', md: fillContainer ? '450px' : 'none' }, overflow: 'hidden', })} > {/* Filter Criteria Tabs */} <Tooltip.Provider delayDuration={200}> <div data-element="filter-tabs" className={css({ display: 'flex', gap: '1px', marginBottom: '2', padding: '2px', bg: isDark ? 'gray.700' : 'gray.200', rounded: 'md', width: '100%', })} > {ALL_FILTER_CRITERIA.map((criteria) => { const isActive = activeFilterCriteria === criteria const buttonContent = ( <button data-action={`select-filter-${criteria}`} onClick={() => setActiveFilterCriteria(criteria)} className={css({ flex: isActive ? 1 : 'none', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '1', padding: '1', paddingX: isActive ? '2' : '1.5', fontSize: 'xs', fontWeight: isActive ? 'bold' : 'normal', color: isActive ? isDark ? 'white' : 'gray.900' : isDark ? 'gray.400' : 'gray.600', bg: isActive ? (isDark ? 'gray.600' : 'white') : 'transparent', rounded: 'sm', cursor: 'pointer', border: 'none', transition: 'all 0.15s', whiteSpace: 'nowrap', _hover: { bg: isActive ? isDark ? 'gray.600' : 'white' : isDark ? 'gray.600' : 'gray.100', }, })} > <span>{FILTER_CRITERIA_CONFIG[criteria].emoji}</span> {isActive && <span>{FILTER_CRITERIA_CONFIG[criteria].label}</span>} </button> ) // Wrap inactive tabs with tooltips if (!isActive) { return ( <Tooltip.Root key={criteria}> <Tooltip.Trigger asChild>{buttonContent}</Tooltip.Trigger> <Tooltip.Portal> <Tooltip.Content side="top" sideOffset={5} className={css({ bg: isDark ? 'gray.800' : 'gray.900', color: 'white', paddingX: '3', paddingY: '1.5', rounded: 'md', fontSize: 'xs', fontWeight: 'medium', boxShadow: 'lg', zIndex: 10001, animation: 'fadeIn 0.15s ease-out', })} > {FILTER_CRITERIA_CONFIG[criteria].label} <Tooltip.Arrow className={css({ fill: isDark ? 'gray.800' : 'gray.900', })} /> </Tooltip.Content> </Tooltip.Portal> </Tooltip.Root> ) } return <span key={criteria}>{buttonContent}</span> })} </div> </Tooltip.Provider> {/* Size Filter (when size tab is active) */} {activeFilterCriteria === 'size' && ( <RangeThermometer options={SIZE_OPTIONS} minValue={sizesToRange(includeSizes)[0]} maxValue={sizesToRange(includeSizes)[1]} onChange={(min, max) => onRegionSizesChange(rangeToSizes(min, max))} orientation="vertical" isDark={isDark} counts={regionCountsByCriteria as Partial<Record<RegionSize, number>>} showTotalCount onHoverPreview={setSizeRangePreview} regionNamesByCategory={regionNamesBySize} selectedRegionNames={selectedRegionNames} onRegionNameHover={setPreviewRegionName} hideCountOnMd={fillContainer && selectedRegionNames.length > 0} /> )} {/* Importance Filter (when importance tab is active) */} {activeFilterCriteria === 'importance' && ( <RangeThermometer options={IMPORTANCE_OPTIONS} minValue={importanceToRange(includeImportance)[0]} maxValue={importanceToRange(includeImportance)[1]} onChange={(min, max) => setIncludeImportance(rangeToImportance(min, max))} orientation="vertical" isDark={isDark} counts={regionCountsByCriteria as Partial<Record<ImportanceLevel, number>>} showTotalCount onHoverPreview={setImportanceRangePreview} regionNamesByCategory={regionNamesByImportance} selectedRegionNames={selectedRegionNames} onRegionNameHover={setPreviewRegionName} hideCountOnMd={fillContainer && selectedRegionNames.length > 0} /> )} {/* Population Filter (when population tab is active) */} {activeFilterCriteria === 'population' && ( <RangeThermometer options={POPULATION_OPTIONS} minValue={populationToRange(includePopulation)[0]} maxValue={populationToRange(includePopulation)[1]} onChange={(min, max) => setIncludePopulation(rangeToPopulation(min, max))} orientation="vertical" isDark={isDark} counts={regionCountsByCriteria as Partial<Record<PopulationLevel, number>>} showTotalCount onHoverPreview={setPopulationRangePreview} regionNamesByCategory={regionNamesByPopulation} selectedRegionNames={selectedRegionNames} onRegionNameHover={setPreviewRegionName} hideCountOnMd={fillContainer && selectedRegionNames.length > 0} /> )} {/* Inline region list - visible on larger screens only, expands below thermometer */} {fillContainer && selectedRegionNames.length > 0 && ( <div data-element="region-list-inline" className={css({ display: { base: 'none', md: 'flex' }, flexDirection: 'column', borderTop: '1px solid', borderColor: isDark ? 'gray.700' : 'gray.300', marginTop: '2', paddingTop: '2', width: '100%', alignSelf: 'stretch', })} > <RegionListPanel regions={selectedRegionNames} onRegionHover={setPreviewRegionName} maxHeight="200px" isDark={isDark} /> </div> )} </div> </div> </div> {/* Peer Navigation - Mini-map thumbnails below main map (or planets at world level) */} {/* Hidden in fillContainer mode since there's no space below the map */} {!fillContainer && peers.length > 0 && ( <div data-element="peer-navigation" className={css({ display: 'grid', gridTemplateColumns: 'repeat(5, 1fr)', // Fixed 5 columns for max peers gap: '2', marginTop: '3', })} > {peers.map((peer) => { // Check if this is a planet (joke at world level) const isPlanet = 'isPlanet' in peer && peer.isPlanet const planetData = 'planetData' in peer ? (peer.planetData as PlanetData | null) : null // Calculate viewBox for this peer's continent (only for non-planets) const peerContinentId = peer.path[0] const peerViewBox = !isPlanet && peerContinentId ? calculateContinentViewBox( WORLD_MAP.regions, peerContinentId, WORLD_MAP.viewBox, 'world' ) : WORLD_MAP.viewBox const peerRegions = !isPlanet && peerContinentId ? filterRegionsByContinent(WORLD_MAP.regions, peerContinentId) : [] return ( <div key={peer.id} data-element={isPlanet ? `planet-${peer.id}` : `peer-${peer.id}`} onClick={isPlanet ? undefined : () => handlePeerClick(peer.path)} className={css({ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '1', padding: '1', bg: isDark ? 'gray.800' : 'gray.100', rounded: 'lg', cursor: isPlanet ? 'default' : 'pointer', border: '2px solid', borderColor: isDark ? 'gray.700' : 'gray.300', transition: 'all 0.15s', opacity: isPlanet ? 0.7 : 1, ...(!isPlanet && { _hover: { borderColor: isDark ? 'blue.500' : 'blue.400', bg: isDark ? 'gray.700' : 'gray.200', }, }), })} > {/* Mini-map preview or planet */} <div className={css({ width: '100%', aspectRatio: '16 / 10', bg: isDark ? 'gray.900' : 'gray.50', rounded: 'md', overflow: 'hidden', display: 'flex', alignItems: 'center', justifyContent: 'center', })} > {isPlanet && planetData ? ( // Render planet SVG <svg viewBox="0 0 100 100" className={css({ width: '80%', height: '80%', })} > {/* Stars background */} {[...Array(15)].map((_, i) => ( <circle key={i} cx={10 + ((i * 37) % 80)} cy={5 + ((i * 23) % 90)} r={0.5 + (i % 3) * 0.3} fill="white" opacity={0.4 + (i % 5) * 0.1} /> ))} {/* Saturn's rings (behind planet) */} {'hasRings' in planetData && planetData.hasRings && ( <ellipse cx="50" cy="50" rx={28 * planetData.size} ry={8 * planetData.size} fill="none" stroke="#c9b896" strokeWidth={3} opacity={0.6} /> )} {/* Planet body */} <circle cx="50" cy="50" r={15 * planetData.size} fill={planetData.color} /> {/* Jupiter's stripes */} {'hasStripes' in planetData && planetData.hasStripes && ( <> <ellipse cx="50" cy="42" rx={14 * planetData.size} ry={2} fill="#c4a574" opacity={0.5} /> <ellipse cx="50" cy="48" rx={14.5 * planetData.size} ry={2.5} fill="#b8956a" opacity={0.4} /> <ellipse cx="50" cy="55" rx={14 * planetData.size} ry={2} fill="#c4a574" opacity={0.5} /> {/* Great Red Spot */} <ellipse cx="58" cy="52" rx={4} ry={3} fill="#c1440e" opacity={0.6} /> </> )} {/* Saturn's rings (in front of planet) */} {'hasRings' in planetData && planetData.hasRings && ( <path d={`M ${50 - 28 * planetData.size} 50 Q 50 ${50 + 8 * planetData.size} ${50 + 28 * planetData.size} 50`} fill="none" stroke="#c9b896" strokeWidth={3} opacity={0.6} /> )} {/* Highlight/shine */} <circle cx={50 - 5 * planetData.size} cy={50 - 5 * planetData.size} r={3 * planetData.size} fill="white" opacity={0.2} /> </svg> ) : ( // Render mini-map for continents <svg viewBox={peerViewBox} className={css({ width: '100%', height: '100%', display: 'block', })} preserveAspectRatio="xMidYMid meet" > {/* Ocean background */} <rect x="-10000" y="-10000" width="30000" height="30000" fill={isDark ? '#111827' : '#e0f2fe'} /> {/* Render continent regions */} {peerRegions.map((region) => ( <path key={region.id} d={region.path} fill={isDark ? '#4a5568' : '#d4c4a8'} stroke={isDark ? '#374151' : '#9ca3af'} strokeWidth={0.5} /> ))} </svg> )} </div> {/* Label */} <span className={css({ fontSize: '2xs', fontWeight: '600', color: isDark ? 'gray.300' : 'gray.600', textAlign: 'center', lineHeight: 'tight', })} > {peer.label} </span> </div> ) })} </div> )} </div> ) } |