@php
// choose the document-specific comment based on current status
$docComment = null;
if ($document->id_statut == 3) {
$docComment = $document->commentaire_motif;
} elseif ($document->id_statut == 4) {
$docComment = $document->commentaire_acceptation;
} elseif ($document->id_statut == 5) {
$docComment = $document->commentaire_avis;
}
// prefer document comment; otherwise fallback to relevant history comment (if any)
$currentComment = !empty($docComment) ? $docComment : ($relevantHistory->commentaire ?? null);
// detect if the displayed comment came from history (so we can show metadata)
$commentFromHistory = empty($docComment) && isset($relevantHistory) && !empty($relevantHistory->commentaire);
$historyAuthor = $relevantHistory->changer->name ?? $relevantHistory->changed_by ?? null;
$historyAt = isset($relevantHistory->created_at) ? $relevantHistory->created_at->format('Y-m-d H:i') : null;
@endphp
@if(!empty($currentComment))
{{ $currentComment }}
@endif