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

<section class="page-intro">
<div>
<span class="page-kicker">Tarification</span>
<h2>Grille tarifaire TTC</h2>
<p>Les cours sans tarif apparaissent en premier.</p>
</div>
<a class="button button-secondary" href="/public/tarifs/reductions">Réductions</a>
</section>

<?php if(!$grid): ?>
<div class="alert alert-error">
Aucune grille tarifaire active ou en brouillon. Crée d’abord la grille de l’année.
</div>
<?php else: ?>

<section class="v51-pricing-layout">
<article class="v51-card">
<h3>Ajouter un tarif</h3>

<form method="post" action="/public/tarifs/ligne" class="v51-price-form">
<?= Csrf::field() ?>
<input type="hidden" name="grille_id" value="<?= (int)$grid['id'] ?>">

<label>
<span>Cours *</span>
<select required name="atelier_id">
<option value="">Choisir un cours</option>
<?php foreach($courses as $course): ?>
<option value="<?= (int)$course['id'] ?>">
<?= $course['has_tariff'] ? '✓ ' : 'À tarifer — ' ?>
<?= htmlspecialchars((string)$course['code']) ?>
— <?= htmlspecialchars((string)$course['libelle']) ?>
— <?= htmlspecialchars((string)($course['publics'] ?: 'Public non renseigné')) ?>
</option>
<?php endforeach; ?>
</select>
</label>

<label>
<span>Montant TTC *</span>
<input required type="number" min="0" step="0.01" name="montant">
</label>

<label>
<span>Périodicité</span>
<select name="periodicite">
<option value="annuel">Annuel</option>
<option value="trimestriel">Trimestriel</option>
<option value="mensuel">Mensuel</option>
<option value="seance">À la séance</option>
<option value="forfait">Forfait</option>
</select>
</label>

<button class="button button-primary">Ajouter le tarif</button>
</form>
</article>

<article class="v51-card">
<h3>Tarifs enregistrés</h3>

<div class="v51-tariff-list">
<?php foreach($lines as $line): ?>
<div>
<strong><?= htmlspecialchars((string)($line['atelier_code'] ?: '—')) ?></strong>
<span><?= htmlspecialchars((string)($line['atelier_libelle'] ?: $line['libelle'])) ?></span>
<b><?= number_format((float)$line['montant'],2,',',' ') ?> € TTC</b>
</div>
<?php endforeach; ?>
</div>
</article>
</section>
<?php endif; ?>
