<?php
// Sous-vue de la fiche animale ; les variables sont préparées par AnimalsController::show().
?>
<!-- ACTIVITÉ -->
<div class="tab-pane" id="tab-activity">
    <?php /** @var array $activity */ ?>
    <?php if (empty($activity)): ?>
    <div class="text-muted"><?= h(t('animal.no_activity')) ?></div>
    <?php else: ?>

    <?php
$actMeta = [
    'history' => ['label' => t('animal.system'),    'iconBg' => 'bg-blue',   'icon' => 'history',      'badge' => 'bg-blue-lt'],
'medical' => ['label' => t('animal.tab.medical'),    'iconBg' => 'bg-red',    'icon' => 'heart',        'badge' => 'bg-red-lt'],
'vaccine' => ['label' => t('animal.vaccine'),     'iconBg' => 'bg-yellow', 'icon' => 'shield-check', 'badge' => 'bg-yellow-lt'],
'deworming' => ['label' => t('animals.dewormer'),  'iconBg' => 'bg-lime',   'icon' => 'pill',         'badge' => 'bg-lime-lt'],
'treatment' => ['label' => t('animal.treatment'), 'iconBg' => 'bg-orange',  'icon' => 'pill',         'badge' => 'bg-orange-lt'],
'weight' => ['label' => t('common.weight'),      'iconBg' => 'bg-indigo', 'icon' => 'scale',        'badge' => 'bg-indigo-lt'],
'care_round' => ['label' => t('animal.care_round'),    'iconBg' => 'bg-red',    'icon' => 'alert-triangle','badge' => 'bg-red-lt'],
'death' => ['label' => t('status.decede'),      'iconBg' => 'bg-dark',   'icon' => 'rainbow',       'badge' => 'bg-dark-lt'],
];
        ?>

    <ul class="list list-timeline" style="list-style-type:none;">
        <?php foreach ($activity as $a):
            $kind = (string)($a['kind'] ?? 'history');
            if (!$canViewMedical && in_array($kind, ['medical','vaccine','treatment','deworming','weight','care_round','death'], true)) {
                continue;
            }
            $meta = $actMeta[$kind] ?? ['label' => ucfirst($kind), 'iconBg' => 'bg-muted', 'icon' => 'circle', 'badge' => 'bg-muted-lt'];

            $lbl = (string)($a['label'] ?? '');
            $details = (string)($a['details'] ?? '');
            $at = (string)($a['at'] ?? '');
            ?>
        <li>
            <!-- icône timeline (gauche) -->
            <div class="list-timeline-icon <?= h($meta['iconBg']) ?>">
                <i class="ti ti-<?= h($meta['icon']) ?>"></i>
            </div>

            <div class="list-timeline-content">
                <div class="d-flex align-items-start justify-content-between">

                    <div class="d-flex align-items-center gap-3 flex-grow-1">

                        <!-- BADGE FIXE aligné -->
                        <div style="min-width:110px">
                            <span class="badge <?= h($meta['badge']) ?>">
                                <?= strtoupper(h($meta['label'])) ?>
                            </span>
                        </div>

                        <!-- TITRE -->
                        <div class="fw-bold">
                            <?= h($lbl) ?>
                        </div>

                    </div>

                    <!-- DATE -->
                    <div class="text-muted small text-end" style="min-width:140px">
                        <?= h($at) ?>
                    </div>

                </div>


                <?php //if ($details !== ''):?>
                <!-- <div class="mt-2 ms-3"> -->
                <?php //echo nl2br(h($details));?>
                <!-- </div>-->
                <?php //endif;?>


            </div>
        </li>
        <?php endforeach; ?>
    </ul>

    <?php endif; ?>
</div>
