<?php use App\Core\{Csrf,Permission};$h=static fn($v)=>htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8');?>
<section class="page-intro">
 <div><span class="page-kicker">Absences</span><h2>Justificatifs — <?=$h($session['atelier'].' / '.$session['groupe'])?></h2><p><?=date('d/m/Y',strtotime($session['date_seance']))?></p></div>
 <a class="button button-secondary" href="/public/presences/feuille?seance=<?=$h($session['public_token'])?>">Retour</a>
</section>
<section class="card">
 <?php if(!$rows):?><p>Aucune absence à justifier.</p><?php endif;?>
 <?php foreach($rows as$r):?>
 <article style="padding:1rem;border-bottom:1px solid #e5e7eb">
  <h3><?=$h($r['nom'].' '.$r['prenom'])?></h3><p>Statut : <?=$h($r['statut'])?></p>
  <?php if($r['justificatif_id']):?>
   <a href="/public/presences/justificatif/telecharger?document=<?=$h($r['justificatif_token'])?>"><?=$h($r['titre'])?></a>
  <?php elseif(Permission::can('presences.edit')):?>
   <form method="post" enctype="multipart/form-data" action="/public/presences/justificatif">
    <?=Csrf::field()?><input type="hidden" name="seance" value="<?=$h($session['public_token'])?>">
    <input type="hidden" name="presence_id" value="<?=(int)$r['presence_id']?>">
    <input name="titre" value="Justificatif d’absence">
    <input required type="file" name="justificatif" accept="application/pdf,image/jpeg,image/png,image/webp">
    <button class="button button-primary">Déposer</button>
   </form>
  <?php endif;?>
 </article>
 <?php endforeach;?>
</section>
