<div class="d-flex justify-content-between align-items-center mb-3">
    <h3>Týmy</h3>
    <?php if ($user['role'] === 'admin' || $user['role'] === 'trener'): ?>
        <a href="<?= BASE_URL ?>/team/pridat" class="btn btn-primary"><i class="ti ti-users-plus fs-4"></i></a>
    <?php endif; ?>
</div>

<div class="card mb-4">
    <div class="card-body">
        <?php if (empty($teams)): ?>
            <div class="alert alert-info" role="alert">
                <i class="ti ti-info-circle"></i>
                Zatím žádné týmy.
            </div>
        <?php else: ?>
        <div class="table-responsive">
            <table class="table table-hover align-middle" id="TableTeams">
                <thead>
                    <tr>
                        <th>Název</th>
                        <th>Popis</th>
                        <th class="text-center">Počet členů</th>
                        <th>Vytvořeno</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach($teams as $team): ?>
                        <tr class="cursor-pointer" onclick="window.location='<?= BASE_URL ?>/team/show?id=<?= $team->id ?>'" style="cursor: pointer;">
                            <td class="text-decoration-underline" style="text-decoration: underline;">
                                <?= htmlspecialchars($team->nazev) ?>
                            </td>
                            <td><?= htmlspecialchars(substr($team->popis ?? '', 0, 50)) ?><?= strlen($team->popis ?? '') > 50 ? '...' : '' ?></td>
                            <td class="text-center"><?= $memberCounts[$team->id] ?? 0 ?></td>
                            <td><?= date('d.m.Y', strtotime($team->vytvoreno)) ?></td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
        <?php endif; ?>
    </div>
</div>
