{% extends 'layout.html' %}

{% block content %}
<div class="admin-container">
    <div class="admin-header">
        <h1>Team Management</h1>
        <a href="{{ url_for('create_team') }}" class="btn btn-md btn-success">Create New Team</a>
    </div>

    {% if teams %}
        <table class="data-table">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Description</th>
                    <th>Members</th>
                    <th>Created</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                {% for team in teams %}
                    <tr>
                        <td>{{ team.name }}</td>
                        <td>{{ team.description }}</td>
                        <td>{{ team.users|length }}</td>
                        <td>{{ team.created_at.strftime('%Y-%m-%d') }}</td>
                        <td class="actions">
                            <a href="{{ url_for('manage_team', team_id=team.id) }}" class="button btn btn-sm btn-primary">Manage</a>
                            <form method="POST" action="{{ url_for('delete_team', team_id=team.id) }}" class="d-inline" onsubmit="return confirm('Are you sure you want to delete this team?');">
                                <button type="submit" class="btn btn-sm btn-danger">Delete</button>
                            </form>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>

    {% else %}
        <p>No teams found. Create a team to get started.</p>
    {% endif %}
</div>

{% endblock %}