/*! © 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/PaginationItem.tsx
const Slot = createSlot();
const PaginationItem = forwardRef(function PaginationItem({ page, 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?.(page);
	};
	const label = children ?? page;
	const Comp = asChild ? Slot : "button";
	if (asChild && isValidElement(children)) return /* @__PURE__ */ jsx(Comp, {
		ref,
		type: "button",
		className: itemClass,
		"aria-current": isActive ? "page" : void 0,
		"aria-label": ariaLabel,
		onClick: isActive ? void 0 : handleClick,
		disabled: isActive,
		...rest,
		children
	});
	return /* @__PURE__ */ jsx(Comp, {
		ref,
		type: "button",
		className: itemClass,
		"aria-current": isActive ? "page" : void 0,
		"aria-label": ariaLabel,
		onClick: isActive ? void 0 : handleClick,
		disabled: isActive,
		...rest,
		children: /* @__PURE__ */ jsx("span", {
			className: labelClass,
			children: label
		})
	});
});
PaginationItem.displayName = "PaginationItem";
//#endregion
export { PaginationItem };
