@php
// select the document-specific comment field according to current statut
$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 the document's comment; otherwise fallback to the relevant history comment
$currentComment = !empty($docComment) ? $docComment : ($relevantHistory->commentaire ?? null);
// detect whether 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;
// label class by status (adjust if you use different styling)
$labelClass = '';
if ($document->id_statut == 3) $labelClass = 'text-danger';
if ($document->id_statut == 4) $labelClass = 'text-warning';
if ($document->id_statut == 5) $labelClass = 'text-primary';
@endphp
@if(!empty($currentComment))
{{ $currentComment }}
@endif