"use client"; import { Box, Flex, Heading, Text, Card, VStack, HStack, Badge, Spinner, Button, SimpleGrid, } from "@chakra-ui/react"; import { useTranslations } from "next-intl"; import { useColorModeValue } from "@/components/ui/color-mode"; import { SlideUp } from "@/components/motion"; import { useAnalyzeMatches, useAnalysisHistory, } from "@/lib/api/analysis/use-hooks"; import { useQueryMatches } from "@/lib/api/matches/use-hooks"; import type { LeagueWithMatchesDto } from "@/lib/api/matches/types"; import { LuSparkles, LuClock, LuCheck } from "react-icons/lu"; import { useState } from "react"; import { toaster } from "@/components/ui/feedback/toaster"; export default function AnalysisContent() { const t = useTranslations("analysis"); const tCommon = useTranslations("common"); const cardBg = useColorModeValue("white", "gray.800"); const borderColor = useColorModeValue("gray.100", "gray.700"); const [selectedMatchIds, setSelectedMatchIds] = useState([]); const upcomingMatches = useQueryMatches(); const analyzeMutation = useAnalyzeMatches(); const historyQuery = useAnalysisHistory(); const toast = (opts: { title: string; status: string }) => toaster.create({ title: opts.title, type: opts.status as "success" | "warning" | "error" | "info" | "loading", }); const toggleMatch = (id: string) => { setSelectedMatchIds((prev) => prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id], ); }; const handleAnalyze = async () => { if (selectedMatchIds.length < 2) { toast({ title: t("select-at-least-2"), status: "warning", }); return; } await analyzeMutation.mutateAsync({ matchIds: selectedMatchIds }); toast({ title: t("analysis-complete"), status: "success", }); historyQuery.refetch(); }; const allMatches: { id: string; home: string; away: string; date: string }[] = upcomingMatches.data?.data ?.flatMap((league: LeagueWithMatchesDto) => league.matches?.map((m) => ({ id: m.id, home: m.homeTeam?.name || "", away: m.awayTeam?.name || "", date: m.mstUtc ? new Date(m.mstUtc).toLocaleDateString() : "", })), ) .filter(Boolean) || []; return ( {t("title")} {/* Match Selection */} {t("select-matches")} 0 ? "primary" : "gray" } > {selectedMatchIds.length} {t("selected")} {upcomingMatches.isPending ? ( ) : ( {allMatches.map((m) => { const isSelected = selectedMatchIds.includes(m.id); return ( toggleMatch(m.id)} > {isSelected ? : null} {m.home} vs {m.away} {m.date} ); })} )} {/* Analysis History */} {t("history")} {historyQuery.isLoading ? ( ) : historyQuery.data?.data?.analyses && historyQuery.data.data.analyses.length > 0 ? ( {historyQuery.data.data.analyses.map( (a: { id: string; matchIds: string[]; createdAt: string; }) => ( {a.matchIds.length} {t("matches-analyzed")} {new Date(a.createdAt).toLocaleString()} ), )} ) : ( {t("no-history")} )} ); }