'use client';

import Card from '@/ui/Card';
import { useTeamStandings } from "@/lib/hooks/team";

interface TeamStandingsProps {
  teamId: string;
  leagues: string[];
}

export default function TeamStandings({ teamId, leagues }: TeamStandingsProps) {
  const { data: standings = [], isLoading: loading } = useTeamStandings(teamId, leagues);

  if (loading) {
    return (
      <Card>
        <div className="text-center py-8 text-gray-400">Loading standings...</div>
      </Card>
    );
  }

  return (
    <Card>
      <h3 className="text-xl font-semibold text-white mb-6">League Standings</h3>
      
      <div className="space-y-4">
        {standings.map((standing: any) => (
          <div
            key={standing.leagueId}
            className="p-4 rounded-lg bg-deep-graphite border border-charcoal-outline"
          >
            <div className="flex items-center justify-between mb-3">
              <h4 className="text-white font-medium">{standing.leagueName}</h4>
              <span className="px-3 py-1 bg-primary-blue/20 text-primary-blue rounded-full text-sm font-semibold">
                P{standing.position}
              </span>
            </div>
            
            <div className="grid grid-cols-3 gap-4 text-center">
              <div>
                <div className="text-2xl font-bold text-white">{standing.points}</div>
                <div className="text-xs text-gray-400">Points</div>
              </div>
              <div>
                <div className="text-2xl font-bold text-white">{standing.wins}</div>
                <div className="text-xs text-gray-400">Wins</div>
              </div>
              <div>
                <div className="text-2xl font-bold text-white">{standing.racesCompleted}</div>
                <div className="text-xs text-gray-400">Races</div>
              </div>
            </div>
          </div>
        ))}
      </div>

      {standings.length === 0 && (
        <div className="text-center py-8 text-gray-400">
          No standings available yet.
        </div>
      )}
    </Card>
  );
}