<h1><?= htmlspecialchars($user['jmeno'] . ' ' . $user['prijmeni']) ?></h1>

<div class="card mb-4">
    <div class="card-body">
        <dl class="row">
            <dt class="col-sm-3">Uživatelské jméno:</dt>
            <dd class="col-sm-9"><?= htmlspecialchars($user['uzivatelske_jmeno']) ?></dd>

            <dt class="col-sm-3">Jméno:</dt>
            <dd class="col-sm-9"><?= htmlspecialchars($user['jmeno']) ?></dd>

            <dt class="col-sm-3">Příjmení:</dt>
            <dd class="col-sm-9"><?= htmlspecialchars($user['prijmeni']) ?></dd>

            <dt class="col-sm-3">Role:</dt>
            <dd class="col-sm-9">
                <?php 
                    $roleLabel = [
                        'admin' => 'Správce',
                        'trener' => 'Trenér',
                        'sportovec' => 'Sportovec'
                    ];
                    echo $roleLabel[$user['role']] ?? $user['role'];
                ?>
            </dd>

            <dt class="col-sm-3">Registrován:</dt>
            <dd class="col-sm-9"><?= date('d.m.Y H:i', strtotime($user['datum_registrace'])) ?></dd>
        </dl>
    </div>
</div>

<div class="card mb-4">
    <div class="card-header">
        <h5 class="card-title mb-0">Členství v týmech</h5>
    </div>
    <div class="card-body">
        <?php if (empty($teams)): ?>
            <p class="text-muted p-3 mb-0">Uživatel není členem žádného týmu.</p>
        <?php else: ?>
            <table class="table table-hover mb-0">
                <thead>
                    <tr>
                        <th>Název týmu</th>
                        <th>Role v týmu</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $roleLabelTeam = [
                        'trener'   => 'Trenér',
                        'asistent' => 'Asistent',
                        'hrac'     => 'Hráč',
                    ];
                    foreach ($teams as $team): ?>
                        <tr>
                            <td>
                                <a href="<?= BASE_URL ?>/team/show?id=<?= $team['id'] ?>" style="color:inherit;">
                                    <?= htmlspecialchars($team['nazev']) ?>
                                </a>
                            </td>
                            <td><?= $roleLabelTeam[$team['role_v_tymu']] ?? htmlspecialchars($team['role_v_tymu']) ?></td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        <?php endif; ?>
    </div>
</div>


<div class="card mb-4">
    <div class="card-header">
        <h5 class="card-title mb-0">Docházka</h5>
    </div>
    <div class="card-body">
        <?php if (empty($dochazka)): ?>
            <p class="text-muted p-3 mb-0">Žádné záznamy o docházce.</p>
        <?php else: ?>
            <table class="table table-hover mb-0">
                <thead>
                    <tr>
                        <th>Tým</th>
                        <th class="text-center">Přítomen</th>
                        <th class="text-center">Nepřítomen</th>
                        <th class="text-center">Omluven</th>
                        <th class="text-center">Pozdní příchod</th>
                        <th class="text-center">Docházka</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($dochazka as $row): ?>
                        <?php
                            $celkem = (int)$row['celkem'];
                            $pritomni = (int)$row['pritomny'] + (int)$row['pozde'];
                            $procent = $celkem > 0 ? round($pritomni / $celkem * 100) : 0;
                        ?>
                        <tr>
                            <td><?= htmlspecialchars($row['tym_nazev']) ?></td>
                            <td class="text-center"><?= (int)$row['pritomny'] ?></td>
                            <td class="text-center"><?= (int)$row['nepritomny'] ?></td>
                            <td class="text-center"><?= (int)$row['omluven'] ?></td>
                            <td class="text-center"><?= (int)$row['pozde'] ?></td>
                            <td class="text-center"><strong><?= $procent ?> %</strong></td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        <?php endif; ?>
    </div>
</div>

<div class="card mb-4">
    <div class="card-header">
        <h5 class="card-title mb-0">Statistiky</h5>
    </div>
    <div class="card-body">
        <?php if (empty($statistiky)): ?>
            <p class="text-muted p-3 mb-0">Žádné statistiky.</p>
        <?php else: ?>
            <?php foreach ($statistiky as $team): ?>
                <div class="px-3 pt-3 pb-1">
                    <strong><?= htmlspecialchars($team['nazev']) ?></strong>
                </div>
                <table class="table table-sm mb-3">
                    <thead>
                        <tr>
                            <th>Statistika</th>
                            <th class="text-end">Hodnota</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($team['stats'] as $stat): ?>
                            <tr>
                                <td><?= htmlspecialchars($stat['nazev']) ?></td>
                                <td class="text-end"><?= $stat['hodnota'] ?></td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            <?php endforeach; ?>
        <?php endif; ?>
    </div>
</div>

<p>
    <a class="btn btn-success" title="Upravit" href="<?= BASE_URL ?>/user/edit?id=<?= $user['id'] ?>"><i class="ti ti-edit fs-4"></i></a>
    <?php if ($canDelete): ?>
        <a class="btn btn-danger" title="Smazat" href="<?= BASE_URL ?>/user/delete?id=<?= $user['id'] ?>" onclick="return confirm('Opravdu smazat uživatele?')"><i class="ti ti-trash fs-4"></i></a>
    <?php endif; ?>
    <a class="btn btn-outline-secondary" title="Zpět" href="<?= BASE_URL ?>/user/index"><i class="ti ti-arrow-back-up fs-4"></i></a>
</p>
