import { BreadcrumbItem } from "@/types/shared";
import Link from "next/link";

interface BreadcrumbProps {
  items: BreadcrumbItem[];
}

const Breadcrumb = ({ items }: BreadcrumbProps) => {
  const currentPage = items[items.length - 1];

  return (
    <div className="mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
      <h2 className="text-[26px] font-bold leading-[30px] text-dark dark:text-white">
        {currentPage.name}
      </h2>

      <nav>
        <ol className="flex items-center gap-2">
          {items.map((item, index) => {
            const isLast = index === items.length - 1;

            return isLast ? (
              <li key={index} className="font-medium text-primary">
                {item.name}
              </li>
            ) : (
              <li key={index} className="flex items-center gap-2">
                <Link
                  href={item.href}
                  className="font-medium hover:text-primary"
                >
                  {item.name}
                </Link>
                <span className="text-dark dark:text-white">/</span>
              </li>
            );
          })}
        </ol>
      </nav>
    </div>
  );
};

export default Breadcrumb;
