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

<section class="page-intro">
<div>
<span class="page-kicker">Cours & ateliers</span>
<h2>Modifier le cours</h2>
<p><?= htmlspecialchars((string)$workshop['code']) ?></p>
</div>
<a class="button button-secondary" href="/public/ateliers">Retour</a>
</section>

<form method="post" action="/public/ateliers/modifier" class="studio-card">
<?= Csrf::field() ?>
<input type="hidden" name="id" value="<?= (int)$workshop['id'] ?>">

<div class="studio-fields">
<label>
<span>Discipline *</span>
<select required name="discipline_id" id="courseDiscipline">
<option value="">Choisir une discipline</option>
<?php foreach($disciplines as $discipline): ?>
<option value="<?= (int)$discipline['id'] ?>"
data-code="<?= htmlspecialchars((string)$discipline['pole_code'].'-'.(string)$discipline['code']) ?>"
<?= (int)$workshop['discipline_id']===(int)$discipline['id']?'selected':'' ?>>
<?= htmlspecialchars((string)$discipline['pole_libelle'].' — '.(string)$discipline['libelle']) ?>
</option>
<?php endforeach; ?>
</select>
</label>

<label>
<span>Libellé *</span>
<input required name="libelle"
value="<?= htmlspecialchars((string)$workshop['libelle']) ?>">
</label>

<label>
<span>Type de cours</span>
<select name="type_atelier">
<?php foreach(['individuel','collectif','ponctuel','stage','master_class'] as $type): ?>
<option value="<?= $type ?>"
<?= $workshop['type_atelier']===$type?'selected':'' ?>>
<?= ucfirst(str_replace('_',' ',$type)) ?>
</option>
<?php endforeach; ?>
</select>
</label>

<label>
<span>Durée standard</span>
<input type="number" min="5" step="5"
name="duree_standard_minutes"
value="<?= (int)$workshop['duree_standard_minutes'] ?>">
</label>

<label>
<span>Capacité</span>
<input type="number" min="1"
name="capacite_max"
value="<?= (int)$workshop['capacite_max'] ?>">
</label>
</div>

<div class="audience-panel">
<h3>Publics autorisés</h3>
<div>
<?php foreach($publics as $public): $publicIcon=['ENF'=>'🧒','ADO'=>'🧑','ADU'=>'👤'][$public['code']]??'👥'; ?>
<label>
<input type="checkbox"
name="public_ids[]"
value="<?= (int)$public['id'] ?>"
data-public-code="<?= htmlspecialchars((string)$public['code']) ?>"
<?= in_array((int)$public['id'],$selectedPublics,true)?'checked':'' ?>>
<span><?= $publicIcon ?></span>
<strong><?= htmlspecialchars((string)$public['libelle']) ?></strong>
</label>
<?php endforeach; ?>
</div>
<p>Un public conserve son code. Plusieurs publics génèrent automatiquement le code MIX.</p>
</div>

<div class="course-code-preview"><span>Code recalculé à l’enregistrement</span><strong id="courseCodePreview"><?= htmlspecialchars((string)$workshop['code']) ?></strong></div>

<label class="full-field">
<span>Description</span>
<textarea name="description" rows="5"><?= htmlspecialchars((string)$workshop['description']) ?></textarea>
</label>

<div class="sticky-actions">
<a class="button button-secondary" href="/public/ateliers">Annuler</a>
<button class="button button-primary">Enregistrer</button>
</div>
</form>
<script src="/public/assets/js/cda-course-linking-96151.js"></script>
