<?php
use App\Core\Csrf;
use App\Core\Permission;
?>
<link rel="stylesheet" href="/public/assets/css/cda-v5-1.css">

<section class="page-intro">
<div>
<span class="page-kicker">Catalogue</span>
<h2>Cours et ateliers</h2>
<p>Enfant, Adulte ou Mixte sont affichés sur chaque cours.</p>
</div>
<a class="button button-primary" href="/public/ateliers/nouveau">+ Nouveau cours</a>
</section>

<section class="v51-course-grid">
<?php foreach($workshops as $workshop): ?>
<?php
$codes=array_filter(explode(',',(string)$workshop['public_codes']));
$mixed=in_array('ENF',$codes,true) && in_array('ADU',$codes,true);
?>
<article class="v51-course-card">
<header>
<div>
<span><?= htmlspecialchars((string)$workshop['pole_libelle']) ?></span>
<h3><?= htmlspecialchars((string)$workshop['libelle']) ?></h3>
<p><?= htmlspecialchars((string)$workshop['discipline_libelle']) ?></p>
</div>
<b><?= htmlspecialchars((string)$workshop['code']) ?></b>
</header>

<div class="v51-public-badges">
<?php if($mixed): ?>
<span class="mix">🧒 + 👤 Mixte</span>
<?php else: ?>
<?php if(in_array('ENF',$codes,true)): ?><span class="enf">🧒 Enfant</span><?php endif; ?>
<?php if(in_array('ADU',$codes,true)): ?><span class="adu">👤 Adulte</span><?php endif; ?>
<?php endif; ?>
</div>

<footer>
<?php if(Permission::can('ateliers.edit')): ?>
<a href="/public/ateliers/modifier?id=<?= (int)$workshop['id'] ?>">Modifier</a>
<?php endif; ?>

<?php if(Permission::can('ateliers.archive')): ?>
<form method="post" action="/public/ateliers/archiver"
onsubmit="return confirm('Archiver ce cours ? Les données historiques seront conservées.');">
<?= Csrf::field() ?>
<input type="hidden" name="id" value="<?= (int)$workshop['id'] ?>">
<button type="submit">Archiver</button>
</form>
<?php endif; ?>

<a href="/public/tarifs">Tarif</a>
</footer>
</article>
<?php endforeach; ?>
</section>
