<?php
$cycleType = $cycleType ?? '';
$cycleLinks = $cycleLinks ?? [];
$cycleHistory = $cycleHistory ?? [];
$cycleStatus = $cycleStatus ?? '';
?>
<div class="darlink-card p-4 mb-4 no-print">
  <div class="d-flex justify-content-between align-items-center mb-3"><h5 class="mb-0">Cycle documentaire</h5><span class="badge text-bg-primary"><?= htmlspecialchars($cycleStatus) ?></span></div>
  <div class="d-flex flex-wrap gap-2 align-items-center">
    <?php if (!empty($cycleLinks['client'])): ?><a class="btn btn-sm btn-outline-secondary" href="index.php?page=clients_show&id=<?= (int)$cycleLinks['client']['id'] ?>">Client : <?= htmlspecialchars($cycleLinks['client']['numero']) ?></a><?php endif; ?>
    <?php if (!empty($cycleLinks['devis'])): ?><span>→</span><a class="btn btn-sm btn-outline-primary" href="index.php?page=devis_show&id=<?= (int)$cycleLinks['devis']['id'] ?>"><?= htmlspecialchars($cycleLinks['devis']['numero']) ?></a><?php endif; ?>
    <?php if (!empty($cycleLinks['bl'])): ?><span>→</span><a class="btn btn-sm btn-outline-primary" href="index.php?page=bons_livraison_show&id=<?= (int)$cycleLinks['bl']['id'] ?>"><?= htmlspecialchars($cycleLinks['bl']['numero']) ?></a><?php endif; ?>
    <?php if (!empty($cycleLinks['facture'])): ?><span>→</span><a class="btn btn-sm btn-outline-success" href="index.php?page=factures_show&id=<?= (int)$cycleLinks['facture']['id'] ?>"><?= htmlspecialchars($cycleLinks['facture']['numero']) ?></a><?php endif; ?>
    <?php foreach (($cycleLinks['avoirs'] ?? []) as $avoir): ?><span>→</span><a class="btn btn-sm btn-outline-info" href="index.php?page=documents_show&id=<?= (int)$avoir['id'] ?>"><?= htmlspecialchars($avoir['numero']) ?></a><?php endforeach; ?>
  </div>
  <?php if (!empty($cycleHistory)): ?><hr><div class="small text-muted mb-2">Historique</div><ul class="mb-0 small"><?php foreach ($cycleHistory as $event): ?><li><strong><?= htmlspecialchars($event['date_action']) ?></strong> — <?= htmlspecialchars($event['libelle']) ?></li><?php endforeach; ?></ul><?php endif; ?>
</div>
