<?php
$professorId=(int)$professor['id'];
$previous=$mode==='month'?$from->modify('-1 month'):$from->modify($mode==='day'?'-1 day':'-7 days');
$next=$mode==='month'?$from->modify('+1 month'):$from->modify($mode==='day'?'+1 day':'+7 days');
$byDate=[];foreach($events as $event){$byDate[$event['date']][]=$event;}
?>
<link rel="stylesheet" href="/public/assets/css/cda-professor-agenda-957.css">
<section class="page-intro"><div><span class="page-kicker">Agenda professeur</span><h2><?=htmlspecialchars($professor['prenom'].' '.$professor['nom'])?></h2><p>Journées issues du planning annuel. Les fermetures scolaires sont signalées automatiquement.</p></div><a class="button button-secondary" href="/public/professeurs-pro/voir?id=<?=$professorId?>">Retour au profil pédagogique</a></section>
<section class="pa-toolbar"><div class="pa-nav"><a href="?professeur=<?=$professorId?>&vue=<?=$mode?>&date=<?=$previous->format('Y-m-d')?>">‹</a><a href="?professeur=<?=$professorId?>&vue=<?=$mode?>&date=<?=date('Y-m-d')?>">Aujourd’hui</a><a href="?professeur=<?=$professorId?>&vue=<?=$mode?>&date=<?=$next->format('Y-m-d')?>">›</a></div><div class="pa-modes"><?php foreach(['day'=>'Jour','week'=>'Semaine','month'=>'Mois'] as $key=>$label):?><a class="<?=$mode===$key?'active':''?>" href="?professeur=<?=$professorId?>&vue=<?=$key?>&date=<?=htmlspecialchars($anchor)?>"><?=$label?></a><?php endforeach;?></div><form method="get"><input type="hidden" name="professeur" value="<?=$professorId?>"><input type="hidden" name="vue" value="<?=$mode?>"><input type="date" name="date" value="<?=htmlspecialchars($anchor)?>"><button>Afficher</button></form></section>
<?php if(!$events):?><section class="card pa-empty"><span>📅</span><h3>Aucune journée sur cette période</h3><p>Les cours du planning annuel apparaîtront ici.</p></section><?php else:?>
<section class="pa-grid"><?php foreach($byDate as $date=>$items):?><article class="pa-day"><header><span><?=htmlspecialchars(ucfirst((new DateTimeImmutable($date))->format('l')))?></span><strong><?=(new DateTimeImmutable($date))->format('d/m/Y')?></strong></header><div class="pa-events"><?php foreach($items as $item):?><div class="pa-event <?=$item['fermeture']?'is-closed':''?>"><time><?=htmlspecialchars(substr($item['heure_debut'],0,5).'–'.substr($item['heure_fin'],0,5))?></time><div><strong><?=htmlspecialchars($item['atelier_libelle'])?></strong><span><?=htmlspecialchars($item['groupe_libelle'])?> · <?=htmlspecialchars($item['salle_libelle']?:'Salle non renseignée')?></span><small><?=intval($item['nb_participants'])?> participant(s)<?php if($item['capacite_max']):?> / <?=intval($item['capacite_max'])?><?php endif;?></small><?php if($item['fermeture']):?><b>Fermé : <?=htmlspecialchars($item['fermeture']['libelle'])?></b><?php endif;?></div></div><?php endforeach;?></div></article><?php endforeach;?></section>
<?php endif;?>
