import React, { useEffect, useState } from "react";
import { Team } from "../../components/interfaces/Team";
import { get } from "http";
import { getTeams } from "../../components/requests/TeamData";



const Teams: React.FC = () => {
    const [teams, setTeams] = useState<Team[]>([]);

    useEffect(() => {
        // Replace with API call in production
       load();
    }, []);

    async function load() 
    {
        try {
        const teams : Team[] = await getTeams(localStorage.getItem("token") || "");
        setTeams(teams);
        } catch (error) {
            console.error("Fehler beim Laden der Teams:", error);
        }
        finally {
        }
    }

    return (
        <div style={{ padding: "2rem" }}>
            <h1>Teams Administration</h1>
            <table style={{ width: "100%", borderCollapse: "collapse", marginTop: "1rem" }}>
                <thead>
                    <tr>
                        <th style={{ borderBottom: "1px solid #ccc", textAlign: "left" }}>Team Name</th>
                       
                    </tr>
                </thead>
                <tbody>
                    {teams.map(team => (
                        <tr key={team.teamUUID}>
                            <td style={{ padding: "0.5rem 0" }}>{team.name}</td>
                           
                        </tr>
                    ))}
                </tbody>
            </table>
        </div>
    );
};

export default Teams;