import type { FC, ReactElement } from "react";
import { useContext } from "react";
import type { IBreadcrumbsLink } from "../config/types";
import { BreadcrumbsContext } from "../context";

/**
 * Компонент ссылки внутри отдельного элемента хлебных крошек
 * @returns {ReactElement}
 */
export const BreadcrumbsLink: FC<IBreadcrumbsLink> = ({
  isCurrent = false,
  href = "",
  labelSlot = null,
}): ReactElement => {
  const { getCN } = useContext(BreadcrumbsContext);

  return (
    <a
      className={getCN("link", { isCurrent })}
      href={href}
      itemProp={"item"}
      aria-current={isCurrent ? "page" : undefined}
    >
      <span
        itemProp={"name"}
      >
        {labelSlot}
      </span>
    </a>
  );
};
