<link rel="stylesheet" href="/public/assets/css/cda-v5-studio.css">

<section class="page-intro">
<div>
<span class="page-kicker">Traçabilité</span>
<h2>Historique de l’atelier</h2>
<p><?= htmlspecialchars((string)$workshop['code']) ?> · <?= htmlspecialchars((string)$workshop['libelle']) ?></p>
</div>
<a class="button button-secondary" href="/public/ateliers/voir?id=<?= (int)$workshop['id'] ?>">Retour à la fiche</a>
</section>

<section class="history-timeline">
<?php if(!$history): ?>
<div class="studio-card">Aucun historique enregistré.</div>
<?php endif; ?>

<?php foreach($history as $entry): ?>
<article>
<div class="history-dot"></div>
<div class="history-card">
<header>
<div>
<strong><?= htmlspecialchars(ucfirst(str_replace('_',' ',(string)$entry['type_action']))) ?></strong>
<span><?= htmlspecialchars((string)($entry['champ'] ?: 'Atelier')) ?></span>
</div>
<time><?= htmlspecialchars(date('d/m/Y H:i',strtotime((string)$entry['created_at']))) ?></time>
</header>

<?php if($entry['ancienne_valeur']!==null || $entry['nouvelle_valeur']!==null): ?>
<div class="history-change">
<span><?= htmlspecialchars((string)($entry['ancienne_valeur'] ?: '—')) ?></span>
<b>→</b>
<strong><?= htmlspecialchars((string)($entry['nouvelle_valeur'] ?: '—')) ?></strong>
</div>
<?php endif; ?>

<?php if(!empty($entry['motif'])): ?>
<p><?= nl2br(htmlspecialchars((string)$entry['motif'])) ?></p>
<?php endif; ?>

<footer>
<?= htmlspecialchars(trim((string)($entry['user_prenom'] ?? '').' '.(string)($entry['user_nom'] ?? 'Utilisateur système'))) ?>
<?php if(!empty($entry['date_effet'])): ?>
· effet au <?= htmlspecialchars(date('d/m/Y',strtotime((string)$entry['date_effet']))) ?>
<?php endif; ?>
</footer>
</div>
</article>
<?php endforeach; ?>
</section>
