import Link from "next/link";

export type BreadcrumbItem = {
  label: string;
  href?: string;
};

export default function Breadcrumb({ items }: { items: BreadcrumbItem[] }) {
  if (!items.length) return null;

  return (
    <nav aria-label="breadcrumb">
      <ol className="breadcrumb">
        {items.map((item, index) => (
          <li
            key={item.label + index}
            className={`breadcrumb-item ${index === items.length - 1 ? "active" : ""}`}
          >
            {index === items.length - 1 || !item.href ? (
              <span>{item.label}</span>
            ) : (
              <Link href={item.href} className="text-decoration-none">
                {item.label}
              </Link>
            )}
          </li>
        ))}
      </ol>
    </nav>
  );
}
