"use client"; import { Box, Flex, Heading, Text, Card, VStack, HStack, Badge, Spinner, Input, Grid, GridItem, Icon, } from "@chakra-ui/react"; import { useTranslations } from "next-intl"; import { useColorModeValue } from "@/components/ui/color-mode"; import { SlideUp } from "@/components/motion"; import { useCountries, useLeagues, useSearchTeams, } from "@/lib/api/leagues/use-hooks"; import type { CountryDto, LeagueDto, TeamDto } from "@/lib/api/leagues/types"; import { LuSearch, LuGlobe, LuTrophy, LuUsers, LuArrowRight, LuMapPin } from "react-icons/lu"; import { useMemo, useState } from "react"; import { useDebounce } from "@/hooks/use-debounce"; import { Link } from "@/i18n/navigation"; import { InputGroup } from "@/components/ui/forms/input-group"; import { Link as ChakraLink } from "@chakra-ui/react"; export default function LeaguesContent() { const t = useTranslations("leagues"); const tMatches = useTranslations("matches"); const bgGradient = useColorModeValue( "linear(to-r, primary.500, primary.700)", "linear(to-r, primary.600, primary.900)" ); const cardBg = useColorModeValue("white", "gray.900"); const borderColor = useColorModeValue("gray.200", "gray.800"); const hoverBg = useColorModeValue("gray.50", "whiteAlpha.50"); const [activeTab, setActiveTab] = useState<"leagues" | "teams">("leagues"); const [sportFilter, setSportFilter] = useState(""); const [selectedCountryId, setSelectedCountryId] = useState(null); const [teamSearchQuery, setTeamSearchQuery] = useState(""); const debouncedTeamQuery = useDebounce(teamSearchQuery, 300); const [countrySearchQuery, setCountrySearchQuery] = useState(""); const debouncedCountryQuery = useDebounce(countrySearchQuery, 300); const countries = useCountries(); const leagues = useLeagues( sportFilter ? { sport: sportFilter as "football" | "basketball" } : undefined, ); const searchTeams = useSearchTeams( debouncedTeamQuery.length >= 2 ? { q: debouncedTeamQuery } : { q: "" }, ); const filteredCountries = useMemo(() => { if (!countries.data?.data) return []; if (!debouncedCountryQuery) return countries.data.data; return countries.data.data.filter((c) => c.name.toLowerCase().includes(debouncedCountryQuery.toLowerCase()) ); }, [countries.data?.data, debouncedCountryQuery]); const displayedLeagues = useMemo(() => { let sourceLeagues: LeagueDto[] = leagues.data?.data || []; if (selectedCountryId) { sourceLeagues = sourceLeagues.filter(l => l.countryId === selectedCountryId); } // Apply sport filter if selected if (sportFilter) { return sourceLeagues.filter(l => l.sport === sportFilter); } return sourceLeagues; }, [selectedCountryId, leagues.data?.data, sportFilter]); return ( {/* Hero Section */} {t("title")} {activeTab === "leagues" ? t("countries-leagues") : tMatches("search-teams")} {activeTab === "leagues" ? "Explore top football and basketball leagues around the world. Filter by country and analyze historical matches." : "Find your favorite teams across all leagues. Get deep insights and head-to-head statistics."} {/* Main Content Area - Pulled up to overlap hero */} {/* Tab Navigation */} setActiveTab("leagues")} transition="all 0.2s" _hover={{ bg: hoverBg }} > {t("countries-leagues")} setActiveTab("teams")} transition="all 0.2s" _hover={{ bg: hoverBg }} > {tMatches("search-teams")} {/* LEAGUES TAB */} {activeTab === "leagues" && ( {/* Left Sidebar: Countries */} } w="full"> setCountrySearchQuery(e.target.value)} /> {countries.isLoading ? ( ) : ( setSelectedCountryId(null)} transition="all 0.2s" > {t("all")} {leagues.data?.data?.length || 0} {filteredCountries.map((country: CountryDto) => { const isSelected = selectedCountryId === country.id; return ( setSelectedCountryId(country.id)} transition="all 0.2s" > {country.flag ? ( {country.name} ) : } {country.name} {leagues.data?.data?.filter(l => l.countryId === country.id).length || 0} ); })} )} {/* Right Area: Leagues Grid */} {/* Top Filters */} {selectedCountryId ? `${countries.data?.data?.find(c => c.id === selectedCountryId)?.name} ${t("leagues")}` : t("leagues")} ({displayedLeagues.length}) setSportFilter("")} transition="all 0.2s" _dark={{ bg: !sportFilter ? "gray.600" : "transparent", color: !sportFilter ? "white" : "gray.400" }} > {t("all")} setSportFilter(sportFilter === "football" ? "" : "football")} transition="all 0.2s" > {tMatches("football")} setSportFilter(sportFilter === "basketball" ? "" : "basketball")} transition="all 0.2s" > {tMatches("basketball")} {/* Leagues Grid */} {leagues.isLoading ? ( ) : displayedLeagues.length === 0 ? ( Bulunamadı Seçili kriterlere uygun lig bulunamadı. ) : ( {displayedLeagues.map((league: LeagueDto) => ( {league.sport} {league.name} {league.country?.name || "Global"} {league.season && ( SEZON: {league.season} )} ))} )} )} {/* TEAMS TAB */} {activeTab === "teams" && ( } w="full"> setTeamSearchQuery(e.target.value)} variant="outline" borderRadius="xl" fontSize="lg" py={6} boxShadow="sm" _focus={{ boxShadow: "0 0 0 2px var(--chakra-colors-primary-500)" }} /> {debouncedTeamQuery.length < 2 ? ( {t("search-at-least-2")} Find detailed statistics, upcoming matches, and head-to-head analysis by searching for any team worldwide. ) : searchTeams.isLoading ? ( ) : searchTeams.data?.data?.length === 0 ? ( Takım Bulunamadı "{debouncedTeamQuery}" aramasıyla eşleşen bir takım bulunamadı. ) : ( {searchTeams.data?.data?.map((team: TeamDto) => ( {team.logo ? ( {team.name} ) : ( )} {team.name} {team.country || "Global"} {team.sport} ))} )} )} ); }