<?php
use App\Core\Csrf;
use App\Core\Permission;

$status=(string)$workshop['statut'];
?>
<link rel="stylesheet" href="/public/assets/css/cda-v5-studio.css">

<section class="studio-hero">
<div class="studio-hero-main">
<div class="studio-icon">🎨</div>
<div>
<span class="studio-kicker">
<?= htmlspecialchars((string)$workshop['pole_libelle']) ?>
·
<?= htmlspecialchars((string)$workshop['discipline_libelle']) ?>
</span>

<h2><?= htmlspecialchars((string)$workshop['libelle']) ?></h2>

<p>
Code <?= htmlspecialchars((string)$workshop['code']) ?>
· <?= htmlspecialchars((string)$workshop['annee_libelle']) ?>
· Version <?= (int)$workshop['version_numero'] ?>
</p>

<div class="studio-badges">
<span class="status-badge status-<?= htmlspecialchars($status) ?>">
<?= htmlspecialchars(ucfirst($status)) ?>
</span>

<span class="public-badge">
<?= htmlspecialchars((string)$workshop['public_libelles']) ?>
</span>
</div>
</div>
</div>

<div class="studio-actions">
<a class="button button-secondary" href="/public/ateliers">
Retour
</a>

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

<?php if(Permission::can('ateliers.view_history')): ?>
<a class="button button-secondary" href="/public/ateliers/historique?id=<?= (int)$workshop['id'] ?>">
Historique
</a>
<?php endif; ?>
</div>
</section>

<section class="studio-kpis">
<article><span>Groupes</span><strong><?= (int)$workshop['nb_groupes'] ?></strong></article>
<article><span>Participants</span><strong><?= (int)$workshop['nb_participants'] ?></strong></article>
<article><span>Capacité indicative</span><strong><?= $workshop['capacite_max'] ? (int)$workshop['capacite_max'] : '—' ?></strong></article>
<article><span>Durée standard</span><strong><?= $workshop['duree_standard_minutes'] ? (int)$workshop['duree_standard_minutes'].' min' : '—' ?></strong></article>
</section>

<section class="studio-tabs">
<a class="active" href="#">Vue générale</a>
<a href="/public/groupes">Groupes et créneaux</a>
<a href="#">Participants</a>
<a href="#">Planning</a>
<a href="#">Présences</a>
<a href="/public/tarifs">Tarification</a>
<a href="#">Documents</a>
<a href="/public/ateliers/historique?id=<?= (int)$workshop['id'] ?>">Historique</a>
</section>

<section class="studio-grid">
<article class="studio-card">
<header><span>Informations</span><h3>Organisation pédagogique</h3></header>

<dl class="studio-details">
<div><dt>Type de cours</dt><dd><?= htmlspecialchars((string)$workshop['type_atelier']) ?></dd></div>
<div><dt>Publics</dt><dd><?= htmlspecialchars((string)$workshop['public_libelles']) ?></dd></div>
<div><dt>Description</dt><dd><?= nl2br(htmlspecialchars((string)($workshop['description'] ?: 'Non renseignée'))) ?></dd></div>
</dl>
</article>

<article class="studio-card">
<header><span>Cycle de vie</span><h3>Statut et actions</h3></header>

<?php if(Permission::can('ateliers.change_status')): ?>
<form method="post" action="/public/ateliers/statut" class="studio-inline-form">
<?= Csrf::field() ?>
<input type="hidden" name="id" value="<?= (int)$workshop['id'] ?>">
<select name="statut">
<option value="brouillon">Brouillon</option>
<option value="ouvert">Ouvert aux inscriptions</option>
<option value="complet">Complet</option>
<option value="suspendu">Suspendu</option>
</select>
<input name="motif" placeholder="Motif facultatif">
<button class="button button-primary">Changer</button>
</form>
<?php endif; ?>

<?php if(Permission::can('ateliers.close') && !in_array($status,['ferme','archive'],true)): ?>
<details class="danger-panel">
<summary>Fermer l’atelier</summary>
<form method="post" action="/public/ateliers/fermer">
<?= Csrf::field() ?>
<input type="hidden" name="id" value="<?= (int)$workshop['id'] ?>">
<label>Date d’effet<input required type="date" name="date_effective" value="<?= date('Y-m-d') ?>"></label>
<label>Motif<textarea required name="motif" rows="3"></textarea></label>
<button class="button button-danger">Confirmer la fermeture</button>
</form>
</details>
<?php endif; ?>

<?php if(Permission::can('ateliers.archive') && $status!=='archive'): ?>
<details class="danger-panel">
<summary>Archiver l’atelier</summary>
<form method="post" action="/public/ateliers/archiver">
<?= Csrf::field() ?>
<input type="hidden" name="id" value="<?= (int)$workshop['id'] ?>">
<label>Motif<textarea required name="motif" rows="3"></textarea></label>
<button class="button button-danger">Archiver sans supprimer l’historique</button>
</form>
</details>
<?php endif; ?>

<?php if(Permission::can('ateliers.restore') && $status==='archive'): ?>
<form method="post" action="/public/ateliers/restaurer">
<?= Csrf::field() ?>
<input type="hidden" name="id" value="<?= (int)$workshop['id'] ?>">
<button class="button button-primary">Restaurer en brouillon</button>
</form>
<?php endif; ?>
</article>
</section>
