<?php use App\Core\Permission; ?>
<link rel="stylesheet" href="/public/assets/css/cda-professors-pro.css">

<section class="prof-profile-hero">
<div class="prof-avatar large">
<?= htmlspecialchars(
    strtoupper(
        mb_substr((string)$professor['prenom'],0,1)
        .mb_substr((string)$professor['nom'],0,1)
    )
) ?>
</div>

<div>
<span class="page-kicker">Dossier administratif professeur</span>
<h2><?= htmlspecialchars((string)$professor['prenom'].' '.(string)$professor['nom']) ?></h2>
<p><?= htmlspecialchars((string)$professor['code_professeur']) ?></p>
</div>

<div class="profile-actions">
<a class="button button-secondary" href="/public/professeurs-rh">
Retour
</a>

<?php if(Permission::can('professeurs.edit')): ?>
<a class="button button-secondary"
href="/public/professeurs/modifier?id=<?= (int)$professor['id'] ?>">
Modifier les informations
</a>
<?php endif; ?>

<?php if(Permission::can('professeurs.disciplines.manage')): ?>
<a class="button button-primary"
href="/public/professeurs-pro/disciplines?id=<?= (int)$professor['id'] ?>">
Gérer les disciplines
</a>
<?php endif; ?>

<?php if(Permission::can('professeurs.contrats.create')): ?>
<a class="button button-primary"
href="/public/professeurs/contrats/nouveau?professeur_id=<?= (int)$professor['id'] ?>">
+ Nouveau contrat
</a>
<?php endif; ?>
</div>
</section>

<nav class="prof-tabs">
<a class="active" href="#disciplines">🎼 Disciplines</a>
<a href="#contrats">📄 Contrats</a>
<a href="#alertes">🔔 Alertes</a>
<a href="/public/groupes">📅 Groupes</a>
<a href="/public/professeurs/modifier?id=<?= (int)$professor['id'] ?>">✏️ Informations</a>
</nav>

<section class="prof-section" id="disciplines">
<header>
<h3>Disciplines enseignées</h3>
<span><?= count($disciplines) ?> discipline(s)</span>
</header>

<div class="discipline-badges">
<?php if(!$disciplines): ?>
<p class="empty-note">Aucune discipline affectée.</p>
<?php endif; ?>

<?php foreach($disciplines as $discipline): ?>
<div style="--discipline-color:<?= htmlspecialchars((string)$discipline['couleur']) ?>">
<span><?= htmlspecialchars((string)$discipline['icone']) ?></span>
<div>
<strong><?= htmlspecialchars((string)$discipline['libelle']) ?></strong>
<small>
<?= htmlspecialchars((string)$discipline['code']) ?>
<?= $discipline['principale'] ? ' · Principale' : '' ?>
</small>
</div>
</div>
<?php endforeach; ?>
</div>
</section>

<section class="prof-section" id="contrats">
<header>
<h3>Contrats</h3>
<a href="/public/professeurs/contrats?professeur_id=<?= (int)$professor['id'] ?>">
Voir tous les contrats
</a>
</header>

<div class="contract-mini-list">
<?php if(!$contracts): ?>
<p class="empty-note">Aucun contrat enregistré.</p>
<?php endif; ?>

<?php foreach($contracts as $contract): ?>
<article style="--contract-color:<?= htmlspecialchars((string)($contract['type_couleur'] ?: '#64748B')) ?>">
<span><?= htmlspecialchars((string)($contract['type_icone'] ?: '📄')) ?></span>
<div>
<strong><?= htmlspecialchars((string)$contract['type_libelle']) ?></strong>
<small>
<?= htmlspecialchars(date('d/m/Y',strtotime((string)$contract['date_debut']))) ?>
→
<?= $contract['date_fin']
    ? htmlspecialchars(date('d/m/Y',strtotime((string)$contract['date_fin'])))
    : 'En cours' ?>
</small>
</div>
<b><?= htmlspecialchars((string)$contract['statut']) ?></b>
</article>
<?php endforeach; ?>
</div>
</section>

<section class="prof-section" id="alertes">
<header>
<h3>Alertes RH</h3>
<span><?= count($alerts) ?> alerte(s)</span>
</header>

<div class="alert-mini-list">
<?php if(!$alerts): ?>
<p class="empty-note">Aucune alerte active.</p>
<?php endif; ?>

<?php foreach($alerts as $alert): ?>
<article class="priority-<?= htmlspecialchars((string)$alert['priorite']) ?>">
<strong><?= htmlspecialchars((string)$alert['titre']) ?></strong>
<p><?= htmlspecialchars((string)$alert['message']) ?></p>
<small>
Déclenchement :
<?= htmlspecialchars(date('d/m/Y',strtotime((string)$alert['date_declenchement']))) ?>
·
<?= htmlspecialchars((string)$alert['statut']) ?>
</small>
</article>
<?php endforeach; ?>
</div>
</section>
