<div class="card mb-4">
    <div class="card-header">
        <h4 class="mb-0">Docházka – <?= htmlspecialchars($meeting['datum']) ?> (<?= htmlspecialchars($meeting['typ'] ?? 'Akce') ?>)</h4>
    </div>
    <div class="card-body">
        <?php if ($canEdit): ?>
        <form method="post" action="<?= BASE_URL ?>/dochazka/save?id=<?= $meeting['id'] ?>">
        <?php else: ?>
        <div>
        <?php endif; ?>
            <div class="table-responsive">
                <table class="table table-sm table-hover align-middle">
                    <thead class="table-light">
                        <tr>
                            <th>Účastník</th>
                            <th class="text-center col-md-2">Přítomen</th>
                            <th class="text-center col-md-2">Nepřítomen</th>
                            <th class="text-center col-md-2">Omluven</th>
                            <th class="text-center col-md-2">Pozdní příchod</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if (!empty($members)): foreach ($members as $member): ?>
                            <tr>
                                <td>
                                    <strong><?= htmlspecialchars($member['jmeno']) ?> <?= htmlspecialchars($member['prijmeni']) ?></strong>
                                </td>
                                <?php $stav = $dochazka[$member['id']] ?? 'nevyjadril_se'; ?>
                                <td class="text-center">
                                    <input type="radio" name="dochazka[<?= $member['id'] ?>]" 
                                           value="pritomen" 
                                           <?= ($stav === 'pritomen') ? 'checked' : '' ?>
                                           <?= !$canEdit ? 'disabled' : '' ?> />
                                </td>
                                <td class="text-center">
                                    <input type="radio" name="dochazka[<?= $member['id'] ?>]" 
                                           value="nepritomen" 
                                           <?= ($stav === 'nepritomen') ? 'checked' : '' ?>
                                           <?= !$canEdit ? 'disabled' : '' ?> />
                                </td>
                                <td class="text-center">
                                    <input type="radio" name="dochazka[<?= $member['id'] ?>]" 
                                           value="omluven" 
                                           <?= ($stav === 'omluven') ? 'checked' : '' ?>
                                           <?= !$canEdit ? 'disabled' : '' ?> />
                                </td>
                                <td class="text-center">
                                    <input type="radio" name="dochazka[<?= $member['id'] ?>]" 
                                           value="pozdni_prichod" 
                                           <?= ($stav === 'pozdni_prichod') ? 'checked' : '' ?>
                                           <?= !$canEdit ? 'disabled' : '' ?> />
                                </td>
                            </tr>
                        <?php endforeach; else: ?>
                            <tr><td colspan="5" class="text-center text-muted">Žádní členové týmu.</td></tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
            
            <div class="mt-3 d-flex gap-2">
                <?php if ($canEdit): ?>
                <button type="submit" class="btn btn-success no-print" title="Uložit">
                    <i class="ti ti-device-floppy fs-4"></i>
                </button>
                <?php endif; ?>
                <button type="button" class="btn btn-outline-secondary no-print" onclick="window.print()" title="Tisk">
                    <i class="ti ti-printer fs-4"></i>
                </button>
                <a href="<?= BASE_URL ?>/team/show?id=<?= $team ?>#attendance-tab" class="btn btn-outline-secondary no-print" title="Zpět">
                    <i class="ti ti-arrow-back-up fs-4"></i>
                </a>
            </div>
        <?php if ($canEdit): ?>
        </form>
        <?php else: ?>
        </div>
        <?php endif; ?>
    </div>
</div>
