<?php
/**
 * Breadcrumbs Component
 * Usage: Set $breadcrumbs array before including this file.
 * Example: $breadcrumbs = [['label' => 'Home', 'url' => '/'], ['label' => 'Service Chain']];
 * The last item has no URL (current page).
 */
if (!isset($breadcrumbs) || empty($breadcrumbs)) return;
?>
<nav aria-label="Breadcrumb" class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-3">
    <ol class="flex items-center gap-2 text-sm text-slate-500 flex-wrap">
        <?php foreach ($breadcrumbs as $i => $crumb): ?>
            <?php $is_last = ($i === count($breadcrumbs) - 1); ?>
            <li class="flex items-center gap-2">
                <?php if ($i > 0): ?>
                    <i class="fa-solid fa-chevron-right text-[10px] text-slate-300"></i>
                <?php endif; ?>
                <?php if (!$is_last && isset($crumb['url'])): ?>
                    <a href="<?= htmlspecialchars($crumb['url']) ?>"
                       class="hover:text-blue-700 transition-colors font-medium">
                        <?php if ($i === 0): ?><i class="fa-solid fa-house text-xs mr-1"></i><?php endif; ?>
                        <?= htmlspecialchars($crumb['label']) ?>
                    </a>
                <?php else: ?>
                    <span class="text-slate-800 font-semibold">
                        <?= htmlspecialchars($crumb['label']) ?>
                    </span>
                <?php endif; ?>
            </li>
        <?php endforeach; ?>
    </ol>
</nav>
