import Link from "@/components/Link";
import { Fragment } from "react";

export type Crumb = { name: string; href: string };

/**
 * Visible trail matching the page's BreadcrumbList schema (crumbTrail in lib/seo); the last item is the current
 * page. Takes plain items, not a path, so client components can render it without the route list.
 */
export default function Breadcrumbs({ items }: { items: Crumb[] }) {
  return (
    <nav className="an-crumbs" aria-label="Breadcrumb">
      {items.map((c, i) =>
        i < items.length - 1 ? (
          <Fragment key={c.href}>
            <Link href={c.href} className="u-c-12257">{c.name}</Link>
            <span aria-hidden="true">/</span>
          </Fragment>
        ) : (
          <span key={c.href} aria-current="page">{c.name}</span>
        ),
      )}
    </nav>
  );
}
