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

<section class="page-intro">
<div>
<span class="page-kicker">CDA V5 Studio</span>
<h2>Modifier l’atelier</h2>
<p>Les modifications seront historisées.</p>
</div>
<a class="button button-secondary" href="/public/ateliers/voir?id=<?= (int)$workshop['id'] ?>">Annuler</a>
</section>

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

<section class="studio-card">
<header><span>Identité</span><h3>Informations générales</h3></header>

<div class="studio-form-grid">
<label>
<span>Code</span>
<input value="<?= htmlspecialchars((string)$workshop['code']) ?>" readonly>
</label>

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

<label>
<span>Type</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>

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

<section class="studio-card">
<header><span>Publics</span><h3>Enfant, Adulte ou Mixte</h3></header>

<div class="studio-public-grid">
<?php foreach($publics as $public): ?>
<label>
<input type="checkbox" name="public_ids[]" value="<?= (int)$public['id'] ?>"
<?= in_array((int)$public['id'],$selectedPublics,true)?'checked':'' ?>>
<span><?= $public['code']==='ENF'?'🧒':'👤' ?></span>
<strong><?= htmlspecialchars((string)$public['libelle']) ?></strong>
</label>
<?php endforeach; ?>
</div>
</section>

<section class="studio-card">
<header><span>Traçabilité</span><h3>Date d’effet et motif</h3></header>

<div class="studio-form-grid">
<label>
<span>Date d’effet</span>
<input type="date" name="date_effet" value="<?= date('Y-m-d') ?>">
</label>

<label class="wide">
<span>Motif de la modification</span>
<input name="motif" placeholder="Ex. changement de capacité ou évolution du cours">
</label>
</div>
</section>

<div class="sticky-actions">
<a class="button button-secondary" href="/public/ateliers/voir?id=<?= (int)$workshop['id'] ?>">Annuler</a>
<button class="button button-primary">Enregistrer les modifications</button>
</div>
</form>
