import { Box, Stack, Text, Divider } from "@mantine/core";
import { Suspense } from "react";
import Header from "./header";
import SwipeableTabs from "@/components/swipeable-tabs";
import { usePlayer, usePlayerMatches, usePlayerStats } from "../../queries";
import TeamList from "@/features/teams/components/team-list";
import StatsOverview from "@/components/stats-overview";
import MatchList from "@/features/matches/components/match-list";
import BadgeShowcase from "@/features/badges/components/badge-showcase";
import BadgeShowcaseSkeleton from "@/features/badges/components/badge-showcase-skeleton";

interface ProfileProps {
  id: string;
}

const Profile = ({ id }: ProfileProps) => {
  const { data: player } = usePlayer(id);
  const { data: matches } = usePlayerMatches(id);
  const { data: stats, isLoading: statsLoading } = usePlayerStats(id);

  const tabs = [
    {
      label: "Overview",
      content: <>
        <Stack px="md">
          <Text size="md" fw={700}>Badges</Text>
          <Suspense fallback={<BadgeShowcaseSkeleton />}>
            <BadgeShowcase playerId={id} />
          </Suspense>
        </Stack>
        <Divider my="md" />
        <Stack>
          <Text px="md" size="md" fw={700}>Statistics</Text>
          <StatsOverview statsData={stats} isLoading={statsLoading} />
        </Stack>
      </>,
    },
    {
      label: "Matches",
      content: <MatchList matches={matches || []} />,
    },
    {
      label: "Teams",
      content: <TeamList teams={player.teams || []} />,
    },
  ];

  return (
    <>
      <Header player={player} />
      <Box mt="lg">
        <SwipeableTabs tabs={tabs} />
      </Box>
    </>
  );
};

export default Profile;
