/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
"use client";
import { createSlot } from "../../../utils/createSlot.js";
import { usePaginationContext } from "./paginationContext.js";
import { usePaginationItemClassName, usePaginationItemLabelClassName } from "./paginationStyles.js";
import { forwardRef, isValidElement } from "react";
import { jsx } from "react/jsx-runtime";
//#region src/components/client/Pagination/PaginationLink.tsx
const Slot = createSlot();
const PaginationLink = forwardRef(function PaginationLink({ page, href, asChild = false, children, className, onClick, ...rest }, ref) {
	const { activePage, size, variant, getItemAriaLabel, onPageChange } = usePaginationContext();
	const isActive = page === activePage;
	const itemClass = usePaginationItemClassName(size, variant, isActive, className);
	const labelClass = usePaginationItemLabelClassName(size);
	const ariaLabel = getItemAriaLabel(page, isActive);
	const handleClick = (event) => {
		onClick?.(event);
		if (!event.defaultPrevented && !isActive && onPageChange) {
			event.preventDefault();
			onPageChange(page);
		}
	};
	const Comp = asChild ? Slot : "a";
	const label = children ?? page;
	if (asChild && isValidElement(children)) return /* @__PURE__ */ jsx(Comp, {
		ref,
		href: isActive ? void 0 : href,
		className: itemClass,
		"aria-current": isActive ? "page" : void 0,
		"aria-label": ariaLabel,
		onClick: isActive ? void 0 : handleClick,
		...rest,
		children
	});
	return /* @__PURE__ */ jsx(Comp, {
		ref,
		href: isActive ? void 0 : href,
		className: itemClass,
		"aria-current": isActive ? "page" : void 0,
		"aria-label": ariaLabel,
		onClick: isActive ? void 0 : handleClick,
		...rest,
		children: /* @__PURE__ */ jsx("span", {
			className: labelClass,
			children: label
		})
	});
});
PaginationLink.displayName = "PaginationLink";
//#endregion
export { PaginationLink };
