import {
  Paper,
  Text,
  Group,
  Box,
  Title
} from "@mantine/core";
import { Trans } from "@lingui/react/macro";
import { useTeam } from "../queries";
import TeamAvatar from "@/components/team-avatar";

interface RegionalTeamCardProps {
  teamId: string;
}

const RegionalTeamCard = ({ teamId }: RegionalTeamCardProps) => {
  const { data: team, error } = useTeam(teamId);

  if (error || !team) {
    return (
      <Paper p="sm" withBorder radius="md">
        <Text c="red" ta="center" size="sm">
          <Trans>Failed to load team</Trans>
        </Text>
      </Paper>
    );
  }

  return (
    <Paper
      withBorder
      radius="lg"
      shadow="xs"
      p="xs"
    >
      <Group gap="md" align="center">
        <TeamAvatar
          team={team}
          size={40}
          radius="md"
          isRegional={true}
          style={{
            backgroundColor: team.primary_color || undefined,
            color: team.accent_color || undefined,
          }}
        />
        <Box style={{ flex: 1, minWidth: 0 }}>
          <Title order={5} lineClamp={1}>
            {team.name}
          </Title>
          <Text size="sm" c="dimmed" lineClamp={1}>
            {team.players?.map(p => `${p.first_name} ${p.last_name}`).join(', ')}
          </Text>
        </Box>
      </Group>
    </Paper>
  );
};

export default RegionalTeamCard;
