<?php
use App\Core\{Csrf,Permission};
$h=static fn($v)=>htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8');
?>
<link rel="stylesheet" href="/public/assets/css/cda-attendance-9654.css?v=9.6.54">
<main class="att-day">
 <section class="page-intro"><div><span class="page-kicker">Feuille de présence</span><h2><?=$h($session['atelier'].' — '.$session['groupe'])?></h2><p><?=date('d/m/Y',strtotime($session['date_seance']))?> · <?=substr($session['heure_debut'],0,5)?>–<?=substr($session['heure_fin'],0,5)?> · <?=$h($session['salle']?:'Salle non renseignée')?></p></div><a class="button button-secondary" href="/public/presences?date=<?=$h($session['date_seance'])?>">Retour à la journée</a></section>
 <section class="att-sheet">
 <?php foreach($participants as$p):
   $status=(string)($p['statut']??'');
   $class=$status==='present'?'is-present':($status==='absent_justifie'?'is-excused':($status==='absent'?'is-absent':''));
 ?>
  <article class="att-person <?=$class?>">
   <form method="post" action="/public/presences/pointer"><?=Csrf::field()?><input type="hidden" name="seance" value="<?=$h($session['public_token'])?>"><input type="hidden" name="participant_id" value="<?=(int)$p['id']?>">
    <strong><?=$h($p['prenom'].' '.$p['nom'])?></strong>
    <div class="att-status-buttons">
     <input id="p<?=$p['id']?>-present" type="radio" name="statut" value="present" <?=$status==='present'?'checked':''?>><label class="present" for="p<?=$p['id']?>-present">Présent</label>
     <input id="p<?=$p['id']?>-excused" type="radio" name="statut" value="absent_justifie" <?=$status==='absent_justifie'?'checked':''?>><label class="excused" for="p<?=$p['id']?>-excused">Absent excusé</label>
     <input id="p<?=$p['id']?>-absent" type="radio" name="statut" value="absent" <?=$status==='absent'?'checked':''?>><label class="absent" for="p<?=$p['id']?>-absent">Absent non excusé</label>
    </div>
    <input name="motif" placeholder="Motif de l’absence" value="<?=$h($p['motif_absence']??'')?>">
    <input name="observation" placeholder="Observation" value="<?=$h($p['observation']??'')?>">
    <button>Enregistrer</button>
   </form>
  </article>
 <?php endforeach?>
 <?php if(!$participants):?><div class="att-empty">Aucun élève n’est inscrit à ce cours.</div><?php endif?>
 </section>
 <p><a class="button button-secondary" href="/public/presences/emargements?seance=<?=$h($session['public_token'])?>">Émargements</a> <a class="button button-secondary" href="/public/presences/justificatifs?seance=<?=$h($session['public_token'])?>">Justificatifs</a></p>
 <?php if(Permission::can('presences.validate')):?><form method="post" action="/public/presences/valider" class="att-validate"><?=Csrf::field()?><input type="hidden" name="seance" value="<?=$h($session['public_token'])?>"><button class="button button-primary">Valider la journée de cours</button></form><?php endif?>
</main>
