"use client";
'use strict';

var classVarianceAuthority = require('class-variance-authority');
var lucideReact = require('lucide-react');
var button = require('@base-ui/react/button');
var clsx = require('clsx');
var tailwindMerge = require('tailwind-merge');
var jsxRuntime = require('react/jsx-runtime');

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
function cn(...inputs) {
  return tailwindMerge.twMerge(clsx.clsx(inputs));
}
var buttonVariants = classVarianceAuthority.cva(
  "group/button inline-flex shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-[var(--radius-sm)] border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap shadow-none transition-all outline-none select-none active:scale-[0.98] focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 disabled:active:scale-100 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
  {
    variants: {
      variant: {
        default: "bg-primary text-primary-foreground shadow-none hover:bg-[var(--primary-hover)] active:bg-[var(--primary-hover)]",
        outline: "border-border bg-background shadow-none hover:bg-muted hover:text-foreground active:bg-muted active:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50 dark:active:bg-input/50",
        secondary: "border border-border bg-card font-medium text-foreground shadow-none hover:border-input-hover hover:bg-zinc-50 active:border-input-hover active:bg-zinc-100 aria-expanded:border-input-hover aria-expanded:bg-zinc-50 aria-expanded:text-foreground dark:bg-secondary dark:text-secondary-foreground dark:hover:bg-[var(--theme-background-button-secondary-hover)] dark:active:bg-[var(--theme-background-button-secondary-hover)] dark:aria-expanded:bg-[var(--theme-background-button-secondary-hover)]",
        soft: "bg-primary/10 text-primary hover:bg-primary/20 active:bg-primary/20 focus-visible:border-primary/40 focus-visible:ring-primary/20 dark:bg-primary/20 dark:hover:bg-primary/30 dark:active:bg-primary/30",
        ghost: "hover:bg-muted hover:text-foreground active:bg-muted active:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50 dark:active:bg-muted/50",
        muted: "text-muted-foreground hover:bg-muted hover:text-foreground active:bg-muted active:text-foreground dark:hover:bg-muted/50 dark:active:bg-muted/50",
        destructive: "bg-destructive text-white hover:opacity-95 active:opacity-95 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive dark:text-white dark:hover:opacity-95 dark:active:opacity-95 dark:focus-visible:ring-destructive/40"
      },
      size: {
        "2xs": "h-6 gap-1 rounded-[min(var(--radius-sm),6px)] px-2.5 text-xs in-data-[slot=button-group]:rounded-sm has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2 [&_svg:not([class*='size-'])]:size-3",
        xs: "h-7 gap-1 rounded-[min(var(--radius-sm),7px)] px-2.5 text-xs in-data-[slot=button-group]:rounded-sm has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2 [&_svg:not([class*='size-'])]:size-3",
        sm: "h-8 gap-1.5 rounded-[min(var(--radius-sm),8px)] px-3 text-[0.8rem] in-data-[slot=button-group]:rounded-sm has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2 [&_svg:not([class*='size-'])]:size-3.5",
        default: "h-9 gap-1.5 px-3 has-data-[icon=inline-end]:pr-3 has-data-[icon=inline-start]:pl-3",
        md: "h-9 gap-1.5 px-3 has-data-[icon=inline-end]:pr-3 has-data-[icon=inline-start]:pl-3",
        /** Shift 2.0 top nav: 36px height, 8px vertical / 14px horizontal padding, 14px medium text, 16px icon, 6px gap */
        header: "h-9 min-h-[36px] gap-1.5 py-2 px-3.5 text-sm font-medium has-data-[icon=inline-end]:pr-3.5 has-data-[icon=inline-start]:pl-3.5 [&_svg:not([class*='size-'])]:size-4",
        lg: "h-10 gap-1.5 px-3.5 has-data-[icon=inline-end]:pr-3.5 has-data-[icon=inline-start]:pl-3.5 [&_svg:not([class*='size-'])]:size-4",
        xl: "h-12 gap-2 px-[1.125rem] text-base has-data-[icon=inline-end]:pr-4 has-data-[icon=inline-start]:pl-4 [&_svg:not([class*='size-'])]:size-5",
        icon: "h-9 w-9 shrink-0 px-0.5 in-data-[slot=button-group]:rounded-[var(--radius-sm)]",
        "icon-2xs": "h-6 w-6 shrink-0 px-0.5 rounded-[min(var(--radius-sm),6px)] in-data-[slot=button-group]:rounded-sm [&_svg:not([class*='size-'])]:size-3",
        "icon-xs": "h-7 w-7 shrink-0 px-0.5 rounded-[min(var(--radius-sm),6px)] in-data-[slot=button-group]:rounded-sm [&_svg:not([class*='size-'])]:size-3",
        "icon-sm": "h-8 w-8 shrink-0 px-0.5 rounded-[min(var(--radius-sm),8px)] in-data-[slot=button-group]:rounded-sm [&_svg:not([class*='size-'])]:size-3.5",
        "icon-lg": "h-10 w-10 shrink-0 px-0.5 in-data-[slot=button-group]:rounded-[var(--radius-sm)] [&_svg:not([class*='size-'])]:size-4",
        "icon-xl": "h-12 w-12 shrink-0 px-0.5 [&_svg:not([class*='size-'])]:size-5"
      }
    },
    defaultVariants: {
      variant: "default",
      size: "default"
    }
  }
);
function Button(_a) {
  var _b = _a, {
    className,
    variant = "default",
    size = "default",
    leadingIcon,
    trailingIcon,
    badge,
    loading = false,
    children,
    disabled
  } = _b, props = __objRest(_b, [
    "className",
    "variant",
    "size",
    "leadingIcon",
    "trailingIcon",
    "badge",
    "loading",
    "children",
    "disabled"
  ]);
  const isDisabled = disabled || loading;
  return /* @__PURE__ */ jsxRuntime.jsx(
    button.Button,
    __spreadProps(__spreadValues({
      "data-slot": "button",
      "aria-busy": loading || void 0,
      disabled: isDisabled,
      className: cn(buttonVariants({ variant, size, className }))
    }, props), {
      children: loading ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "size-4 animate-spin shrink-0", "aria-hidden": true }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
        leadingIcon ? /* @__PURE__ */ jsxRuntime.jsx("span", { "data-icon": "inline-start", className: "contents", children: leadingIcon }) : null,
        children != null && children !== "" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
          children,
          badge != null ? badge : null
        ] }) : null,
        trailingIcon ? /* @__PURE__ */ jsxRuntime.jsx("span", { "data-icon": "inline-end", className: "contents", children: trailingIcon }) : null
      ] })
    })
  );
}
var pageItemVariants = classVarianceAuthority.cva(
  "shrink-0 select-none transition-colors",
  {
    variants: {
      variant: {
        default: "flex items-center justify-center rounded-sm font-medium text-xs min-h-7 min-w-7 w-7",
        dot: "rounded-full size-2"
      },
      state: {
        default: "",
        hover: "",
        active: ""
      }
    },
    compoundVariants: [
      // Default (number) states
      {
        variant: "default",
        state: "default",
        className: "text-muted-foreground/30"
      },
      {
        variant: "default",
        state: "hover",
        className: "bg-muted text-muted-foreground cursor-pointer"
      },
      {
        variant: "default",
        state: "active",
        className: "border border-primary bg-primary/12 text-primary cursor-pointer dark:bg-primary/18"
      },
      // Dot states
      {
        variant: "dot",
        state: "default",
        className: "bg-foreground/6"
      },
      {
        variant: "dot",
        state: "hover",
        className: "bg-foreground/8 cursor-pointer"
      },
      {
        variant: "dot",
        state: "active",
        className: "border-2 border-primary bg-primary/12 cursor-pointer dark:bg-primary/18"
      }
    ],
    defaultVariants: {
      variant: "default",
      state: "default"
    }
  }
);
function PageItem(_a) {
  var _b = _a, {
    className,
    variant = "default",
    state = "default",
    label
  } = _b, props = __objRest(_b, [
    "className",
    "variant",
    "state",
    "label"
  ]);
  const isInteractive = state === "active" || props.onClick !== void 0;
  const Element = isInteractive ? "button" : "span";
  if (variant === "dot") {
    return /* @__PURE__ */ jsxRuntime.jsx(
      Element,
      __spreadValues({
        "data-slot": "page-item",
        "data-state": state,
        className: cn(pageItemVariants({ variant, state }), className)
      }, isInteractive ? props : {})
    );
  }
  return /* @__PURE__ */ jsxRuntime.jsx(
    Element,
    __spreadProps(__spreadValues({
      "data-slot": "page-item",
      "data-state": state,
      className: cn(pageItemVariants({ variant, state }), className)
    }, isInteractive ? props : {}), {
      children: label
    })
  );
}
var navButtonVariants = classVarianceAuthority.cva(
  "inline-flex shrink-0 items-center justify-center rounded-sm min-h-7 min-w-7 transition-colors",
  {
    variants: {
      disabled: {
        true: "bg-foreground/8 text-foreground/30 cursor-default",
        false: "bg-foreground/6 text-muted-foreground hover:bg-foreground/10 cursor-pointer"
      }
    },
    defaultVariants: {
      disabled: false
    }
  }
);
function NavButton(_a) {
  var _b = _a, {
    className,
    direction,
    disabled
  } = _b, props = __objRest(_b, [
    "className",
    "direction",
    "disabled"
  ]);
  return /* @__PURE__ */ jsxRuntime.jsx(
    "button",
    __spreadProps(__spreadValues({
      "data-slot": "paginator-nav",
      disabled,
      className: cn(navButtonVariants({ disabled: !!disabled }), className)
    }, props), {
      children: direction === "prev" ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeft, { className: "size-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: "size-4" })
    })
  );
}
function buildPageRange(currentPage, totalPages, maxVisible) {
  if (totalPages <= maxVisible + 2) {
    return Array.from({ length: totalPages }, (_, i) => i + 1);
  }
  const pages = [];
  const half = Math.floor(maxVisible / 2);
  let start = Math.max(2, currentPage - half);
  let end = Math.min(totalPages - 1, currentPage + half);
  if (currentPage <= half + 1) {
    end = maxVisible;
  }
  if (currentPage >= totalPages - half) {
    start = totalPages - maxVisible + 1;
  }
  pages.push(1);
  if (start > 2) {
    pages.push("ellipsis");
  }
  for (let i = start; i <= end; i++) {
    pages.push(i);
  }
  if (end < totalPages - 1) {
    pages.push("ellipsis");
  }
  pages.push(totalPages);
  return pages;
}
function Paginator(_a) {
  var _b = _a, {
    className,
    variant = "simple",
    currentPage,
    totalPages,
    totalItems,
    pageSize,
    onPageChange,
    maxVisiblePages = 4
  } = _b, props = __objRest(_b, [
    "className",
    "variant",
    "currentPage",
    "totalPages",
    "totalItems",
    "pageSize",
    "onPageChange",
    "maxVisiblePages"
  ]);
  const isFirstPage = currentPage <= 1;
  const isLastPage = currentPage >= totalPages;
  const handlePrev = () => {
    if (!isFirstPage) onPageChange == null ? void 0 : onPageChange(currentPage - 1);
  };
  const handleNext = () => {
    if (!isLastPage) onPageChange == null ? void 0 : onPageChange(currentPage + 1);
  };
  const inlineTextClass = "text-[11px]";
  const simpleTextClass = "text-xs";
  const simpleButtonClass = "px-2 py-1 text-xs";
  const trackGapClass = "gap-2";
  const numberGapClass = "gap-1";
  const dotGapClass = "gap-1.5";
  if (variant === "inline") {
    const total = totalItems != null ? totalItems : 0;
    const pageWindowSize = pageSize != null ? pageSize : 0;
    const itemEnd = total === 0 ? 0 : Math.min(currentPage * pageWindowSize, total);
    const itemStart = total === 0 ? 0 : (currentPage - 1) * pageWindowSize + 1;
    const hasRange = totalItems != null && pageSize != null;
    const inlineIconNavBtnClass = "text-primary enabled:hover:bg-sidebar-accent enabled:hover:text-primary disabled:text-muted-foreground disabled:hover:bg-transparent disabled:hover:text-muted-foreground";
    return /* @__PURE__ */ jsxRuntime.jsxs(
      "nav",
      __spreadProps(__spreadValues({
        "data-slot": "paginator",
        "aria-label": "Pagination",
        className: cn(
          "-mr-1 flex min-h-9 items-center gap-2",
          className
        )
      }, props), {
        children: [
          /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex min-h-0 min-w-0 shrink items-center justify-center", children: hasRange ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: cn("whitespace-nowrap font-medium tabular-nums text-muted-foreground", inlineTextClass), children: [
            itemStart,
            "\u2013",
            itemEnd,
            " of ",
            total,
            " results"
          ] }) : /* @__PURE__ */ jsxRuntime.jsxs("span", { className: cn("font-medium tabular-nums text-muted-foreground", inlineTextClass), children: [
            "Page ",
            currentPage,
            " of ",
            totalPages
          ] }) }),
          /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex shrink-0 items-center gap-0", children: [
            /* @__PURE__ */ jsxRuntime.jsx(
              Button,
              {
                type: "button",
                variant: "ghost",
                size: "sm",
                disabled: isFirstPage,
                onClick: handlePrev,
                "aria-label": "Previous page",
                className: cn(
                  "aspect-square !size-7 shrink-0 !gap-0 !rounded-sm !p-0",
                  inlineIconNavBtnClass
                ),
                children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeft, { className: "size-4 shrink-0", "aria-hidden": true })
              }
            ),
            /* @__PURE__ */ jsxRuntime.jsx(
              Button,
              {
                type: "button",
                variant: "ghost",
                size: "sm",
                disabled: isLastPage,
                onClick: handleNext,
                "aria-label": "Next page",
                className: cn(
                  "aspect-square !size-7 shrink-0 !gap-0 !rounded-sm !p-0",
                  inlineIconNavBtnClass
                ),
                children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: "size-4 shrink-0", "aria-hidden": true })
              }
            )
          ] })
        ]
      })
    );
  }
  if (variant === "simple") {
    const itemEnd = Math.min(currentPage * (pageSize != null ? pageSize : 0), totalItems != null ? totalItems : 0);
    const itemStart = totalItems ? (currentPage - 1) * (pageSize != null ? pageSize : 0) + 1 : 0;
    const displayedCount = totalItems != null && pageSize != null;
    return /* @__PURE__ */ jsxRuntime.jsxs(
      "nav",
      __spreadProps(__spreadValues({
        "data-slot": "paginator",
        "aria-label": "Pagination",
        className: cn("flex items-center justify-between", className)
      }, props), {
        children: [
          displayedCount ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: cn("text-muted-foreground", simpleTextClass), children: [
            itemStart,
            "\u2013",
            itemEnd,
            " of ",
            totalItems,
            " results"
          ] }) : /* @__PURE__ */ jsxRuntime.jsxs("span", { className: cn("text-muted-foreground", simpleTextClass), children: [
            "Page ",
            currentPage,
            " of ",
            totalPages
          ] }),
          /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1", children: [
            /* @__PURE__ */ jsxRuntime.jsx(
              "button",
              {
                disabled: isFirstPage,
                onClick: handlePrev,
                className: cn(
                  "inline-flex items-center justify-center rounded-sm font-medium transition-colors",
                  simpleButtonClass,
                  isFirstPage ? "bg-foreground/8 text-foreground/30 cursor-default" : "bg-foreground/6 text-muted-foreground hover:bg-foreground/10 cursor-pointer"
                ),
                children: "Prev"
              }
            ),
            /* @__PURE__ */ jsxRuntime.jsx(
              "button",
              {
                disabled: isLastPage,
                onClick: handleNext,
                className: cn(
                  "inline-flex items-center justify-center rounded-sm font-medium transition-colors",
                  simpleButtonClass,
                  isLastPage ? "bg-foreground/8 text-foreground/30 cursor-default" : "bg-foreground/6 text-muted-foreground hover:bg-foreground/10 cursor-pointer"
                ),
                children: "Next"
              }
            )
          ] })
        ]
      })
    );
  }
  if (variant === "numbered") {
    const pages = buildPageRange(currentPage, totalPages, maxVisiblePages);
    return /* @__PURE__ */ jsxRuntime.jsxs(
      "nav",
      __spreadProps(__spreadValues({
        "data-slot": "paginator",
        "aria-label": "Pagination",
        className: cn("flex items-center", trackGapClass, className)
      }, props), {
        children: [
          /* @__PURE__ */ jsxRuntime.jsx(
            NavButton,
            {
              direction: "prev",
              disabled: isFirstPage,
              onClick: handlePrev,
              "aria-label": "Previous page"
            }
          ),
          /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("flex items-center", numberGapClass), children: pages.map(
            (page, idx) => page === "ellipsis" ? /* @__PURE__ */ jsxRuntime.jsx(
              PageItem,
              {
                variant: "default",
                state: "default",
                label: "\u2026"
              },
              `ellipsis-${idx}`
            ) : /* @__PURE__ */ jsxRuntime.jsx(
              PageItem,
              {
                variant: "default",
                state: page === currentPage ? "active" : "default",
                label: String(page),
                onClick: () => onPageChange == null ? void 0 : onPageChange(page)
              },
              page
            )
          ) }),
          /* @__PURE__ */ jsxRuntime.jsx(
            NavButton,
            {
              direction: "next",
              disabled: isLastPage,
              onClick: handleNext,
              "aria-label": "Next page"
            }
          )
        ]
      })
    );
  }
  return /* @__PURE__ */ jsxRuntime.jsxs(
    "nav",
    __spreadProps(__spreadValues({
      "data-slot": "paginator",
      "aria-label": "Pagination",
      className: cn("flex items-center", trackGapClass, className)
    }, props), {
      children: [
        /* @__PURE__ */ jsxRuntime.jsx(
          NavButton,
          {
            direction: "prev",
            disabled: isFirstPage,
            onClick: handlePrev,
            "aria-label": "Previous page"
          }
        ),
        /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("flex items-center", dotGapClass), children: Array.from({ length: totalPages }, (_, i) => i + 1).map((page) => /* @__PURE__ */ jsxRuntime.jsx(
          PageItem,
          {
            variant: "dot",
            state: page === currentPage ? "active" : "default",
            onClick: () => onPageChange == null ? void 0 : onPageChange(page),
            "aria-label": `Page ${page}`
          },
          page
        )) }),
        /* @__PURE__ */ jsxRuntime.jsx(
          NavButton,
          {
            direction: "next",
            disabled: isLastPage,
            onClick: handleNext,
            "aria-label": "Next page"
          }
        )
      ]
    })
  );
}

exports.NavButton = NavButton;
exports.PageItem = PageItem;
exports.Paginator = Paginator;
exports.navButtonVariants = navButtonVariants;
exports.pageItemVariants = pageItemVariants;
//# sourceMappingURL=paginator.cjs.map
//# sourceMappingURL=paginator.cjs.map