import Link from "next/link";

type Crumb = {
  label: string;
  href?: string;
};

export default function ZxdbBreadcrumbs({ items }: { items: Crumb[] }) {
  if (items.length === 0) return null;

  const lastIndex = items.length - 1;

  return (
    <nav aria-label="breadcrumb">
      <ol className="breadcrumb">
        {items.map((item, index) => {
          const isActive = index === lastIndex || !item.href;
          return (
            <li key={`${item.label}-${index}`} className={`breadcrumb-item${isActive ? " active" : ""}`} aria-current={isActive ? "page" : undefined}>
              {isActive ? item.label : <Link href={item.href ?? "#"}>{item.label}</Link>}
            </li>
          );
        })}
      </ol>
    </nav>
  );
}
