<?php
// Sous-vue de la fiche animale ; les variables sont préparées par AnimalsController::show().
?>
<!-- HISTORIQUE -->
<div class="tab-pane" id="tab-hist">
    <?php $visibleHistory = $canViewMedical ? $history : array_values(array_filter($history, static fn (array $row): bool => !in_array((string)($row['type'] ?? ''), ['medical','treatment','vaccine','deworming','death'], true))); ?>
    <?php if (empty($visibleHistory)): ?>
    <div class="text-muted"><?= h(t('animal.no_history_event')) ?></div>
    <?php else: ?>
    <ul class="list list-timeline">
        <?php foreach ($visibleHistory as $h):
            $style = $historyStyles[$h['type']] ?? ['bg' => 'bg-muted','icon' => 'circle'];
            ?>
        <li>
            <div class="list-timeline-icon <?= $style['bg'] ?>">
                <i class="ti ti-<?= $style['icon'] ?>"></i>
            </div>
            <div class="list-timeline-content">
                <div class="fw-bold"><?= h($h['label']) ?></div>
                <div class="text-muted small"><?= h($h['created_at']) ?></div>
                <?php if (!empty($h['actor_name'])): ?><div class="text-muted small">
                    <?= h(t('common.by', ['name' => $h['actor_name']])) ?></div><?php endif; ?>
                <?php if (!empty($h['details'])): ?>
                <div class="mt-1"><?= nl2br(h($h['details'])) ?></div>
                <?php endif; ?>
            </div>
        </li>
        <?php endforeach; ?>
    </ul>
    <?php endif; ?>
</div>
