<?php use App\Core\{Csrf,Permission};$h=static fn($v)=>htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8');$canViewArchived=(bool)($canViewArchived??false);$activeContracts=array_values(array_filter($contracts,static fn($c)=>$c['statut']!=='archive'&&empty($c['deleted_at'])));$archivedContracts=$canViewArchived?array_values(array_filter($contracts,static fn($c)=>$c['statut']==='archive'||!empty($c['deleted_at']))):[]; ?>
<link rel="stylesheet" href="/public/assets/css/cda-professor-contracts-9613.css">
<main class="pc-page">
 <a class="pc-back" href="/public/professeurs-pro/voir?id=<?=(int)$professor['id']?>">← Retour au dossier professeur</a>
 <header class="pc-heading"><div><span>RESSOURCES HUMAINES</span><h1>Contrats de <?=$h($professor['prenom'].' '.$professor['nom'])?></h1><p>Historique contractuel, volumes horaires et règles d’ancienneté.</p></div><?php if(Permission::can('professeurs.contrats.create')):?><a class="pc-primary" href="/public/professeurs/contrats/nouveau?professeur_id=<?=(int)$professor['id']?>">＋ Nouveau contrat</a><?php endif?></header>
 <?php if(!empty($_SESSION['success'])):?><div class="pc-flash"><?=$h($_SESSION['success'])?></div><?php unset($_SESSION['success']);endif?>
 <section class="pc-summary"><article><b><?=count($activeContracts)?></b><span>contrat<?=count($activeContracts)>1?'s':''?> en cours</span></article><article><b><?=count(array_filter($activeContracts,static fn($c)=>$c['statut']==='actif'))?></b><span>actif(s)</span></article><article><b><?=count(array_filter($activeContracts,static fn($c)=>!empty($c['contrat_principal'])))?></b><span>principal</span></article></section>
 <section class="pc-grid">
 <?php foreach($activeContracts as $c):$override=$c['compte_anciennete_override'];$seniority=$override===null?'Selon le type'.($c['compte_anciennete_effectif']?' · Oui':' · Non'):((int)$override===1?'Forcée à oui':'Forcée à non');?>
  <article class="pc-card" style="--pc-color:<?=$h($c['type_couleur']?:'#64748B')?>">
   <header><div class="pc-icon"><?=$h($c['type_icone']?:'📄')?></div><div><span><?=$h($c['type_code'])?></span><h2><?=$h($c['type_libelle'])?></h2></div><em class="is-<?=$h($c['statut'])?>"><?=$h(ucfirst($c['statut']))?></em></header>
   <div class="pc-period"><b><?=$h(date('d/m/Y',strtotime($c['date_debut'])))?></b><span>→</span><b><?=$c['date_fin']?$h(date('d/m/Y',strtotime($c['date_fin']))):'En cours'?></b></div>
   <dl><div><dt>Fonction</dt><dd><?=$h($c['fonction']?:'Non renseignée')?></dd></div><div><dt>Volume</dt><dd><?=$c['volume_heures']!==null?$h(number_format((float)$c['volume_heures'],2,',',' ').' h · '.$c['unite_heures']):'Non renseigné'?></dd></div><div><dt>Ancienneté</dt><dd><?=$h($seniority)?></dd></div><div><dt>Contrat</dt><dd><?=!empty($c['contrat_principal'])?'Principal':'Complémentaire'?></dd></div></dl>
   <footer><?php if(Permission::can('professeurs.contrats.edit')):?><a href="/public/professeurs/contrats/modifier?id=<?=(int)$c['id']?>">✎ Modifier</a><?php endif?><?php if(Permission::can('professeurs.contrats.archive')):?><form method="post" action="/public/professeurs/contrats/archiver" onsubmit="return confirm('Archiver ce contrat ?')"><?=Csrf::field()?><input type="hidden" name="id" value="<?=(int)$c['id']?>"><input type="hidden" name="professeur_id" value="<?=(int)$professor['id']?>"><button>Archiver</button></form><?php endif?></footer>
  </article>
 <?php endforeach?>
 <?php if(!$activeContracts):?><article class="pc-empty"><span>📄</span><h2>Aucun contrat actif</h2><p>Créez le premier contrat de ce professeur.</p></article><?php endif?>
 </section>
 <?php if($canViewArchived):?><details class="pc-archives"><summary>Contrats archivés (<?=count($archivedContracts)?>)</summary><section class="pc-grid"><?php foreach($archivedContracts as $c):?><article class="pc-card is-archived" style="--pc-color:<?=$h($c['type_couleur']?:'#64748B')?>"><header><div class="pc-icon"><?=$h($c['type_icone']?:'📄')?></div><div><span><?=$h($c['type_code'])?></span><h2><?=$h($c['type_libelle'])?></h2></div><em>Archivé</em></header><div class="pc-period"><b><?=$h(date('d/m/Y',strtotime($c['date_debut'])))?></b><span>→</span><b><?=$c['date_fin']?$h(date('d/m/Y',strtotime($c['date_fin']))):'En cours'?></b></div><dl><div><dt>Fonction</dt><dd><?=$h($c['fonction']?:'Non renseignée')?></dd></div><div><dt>Volume</dt><dd><?=$c['volume_heures']!==null?$h(number_format((float)$c['volume_heures'],2,',',' ').' h · '.$c['unite_heures']):'Non renseigné'?></dd></div></dl></article><?php endforeach?><?php if(!$archivedContracts):?><article class="pc-empty"><p>Aucun contrat archivé.</p></article><?php endif?></section></details><?php endif?>
</main>
