<?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">Émargement</span><h2>Documents de la séance</h2></div>
 <a class="button button-secondary" href="/public/presences/feuille?seance=<?=$h($session['public_token'])?>">Retour</a>
</section>
<section class="card">
 <?php if(Permission::can('emargements.upload')):?>
 <form method="post" enctype="multipart/form-data" action="/public/presences/emargement">
  <?=Csrf::field()?><input type="hidden" name="seance" value="<?=$h($session['public_token'])?>">
  <label>Titre<input name="titre" value="Feuille d’émargement"></label>
  <label>PDF ou photo<input required type="file" name="document" accept="application/pdf,image/jpeg,image/png,image/webp"></label>
  <button class="button button-primary">Déposer</button>
 </form>
 <?php endif;?>
 <?php foreach($documents as$d):?>
 <p>
  <a href="/public/presences/emargement/telecharger?document=<?=$h($d['public_token'])?>"><?=$h($d['titre'])?></a>
  — <?=$d['valide']?'Validé':'À valider'?>
  <?php if(!$d['valide']&&Permission::can('emargements.validate')):?>
  <form method="post" action="/public/presences/emargement/valider" style="display:inline">
   <?=Csrf::field()?><input type="hidden" name="document" value="<?=$h($d['public_token'])?>">
   <button>Valider</button>
  </form>
  <?php endif;?>
  <?php if(Permission::can('emargements.delete')):?>
  <form method="post" action="/public/presences/emargement/archiver" style="display:inline">
   <?=Csrf::field()?><input type="hidden" name="document" value="<?=$h($d['public_token'])?>">
   <button>Archiver</button>
  </form>
  <?php endif;?>
 </p>
 <?php endforeach;?>
</section>
