<?php

use App\Helpers\BadgeHelper;
use App\Models\ActivityLogModel;

/**
 * @var ActivityLogModel $timelines
 */

?>
<div class="card shadow-sm border-0">
  <div class="card-header bg-white">
    <h5 class="mb-0">
      Timeline Ticket
    </h5>
  </div>
  <div class="card-body">
    <?php if (empty($timelines)): ?>
      <div class="text-center text-muted py-5">
        <i class="bi bi-clock-history fs-1 d-block mb-2"></i>
        Belum ada aktivitas.
      </div>
    <?php else: ?>
      <?php foreach ($timelines as $index => $activity): ?>
        <?php
        $color = BadgeHelper::activityColor($activity->getLogType());
        $icon = BadgeHelper::activityIcon($activity->getLogType());

        $last = $index === count((array) $timelines) - 1;
        ?>
        <div class="position-relative ps-5 pb-4">
          <?php if (!$last): ?>
            <div
              class="position-absolute top-0"
              style="
      left:14px;
      width:3px;
      height:100%;
      background:var(--bs-<?= $color ?>);
      ">
            </div>
          <?php endif; ?>
          <div
            class="position-absolute rounded-circle bg-<?= $color ?> d-flex align-items-center justify-content-center"
            style="
      left:0;
      top:0;
      width:30px;
      height:30px;
      ">
            <i class="bi <?= $icon ?> text-white"></i>
          </div>
          <h6 class="mb-1">
            <?= str_replace("_", " ", ucfirst(strtolower($activity->getLogType()))) ?>
          </h6>
          <small class="text-muted">
            <?= date('d M Y H:i', strtotime($activity->getTanggalAktivitas())) ?>
            &bull;
            <?= htmlspecialchars($activity->getNamaUser()) ?>
          </small>
          <p class="mt-2 mb-0">
            <?= htmlspecialchars($activity->getAktivitas()) ?>
          </p>
        </div>
      <?php endforeach; ?>
    <?php endif; ?>
  </div>
</div>