"use client";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from "lucide-react";
import { Button } from "../../ui/button";
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue
} from "../../ui/select";
import { sel } from "../../../lib/test";
function PaginationControls({
  page,
  totalPages,
  total,
  limit,
  onPageChange,
  onLimitChange,
  showPageSize = true,
  pageSizeOptions = [10, 20, 50, 100]
}) {
  const startItem = total === 0 ? 0 : (page - 1) * limit + 1;
  const endItem = Math.min(page * limit, total);
  const canGoPrevious = page > 1;
  const canGoNext = page < totalPages;
  return /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-2 py-4", children: [
    /* @__PURE__ */ jsx("div", { className: "text-sm text-muted-foreground", children: total === 0 ? "No results" : /* @__PURE__ */ jsxs(Fragment, { children: [
      "Showing ",
      /* @__PURE__ */ jsx("span", { className: "font-medium", children: startItem }),
      " to",
      " ",
      /* @__PURE__ */ jsx("span", { className: "font-medium", children: endItem }),
      " of",
      " ",
      /* @__PURE__ */ jsx("span", { className: "font-medium", children: total }),
      " results"
    ] }) }),
    /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", children: [
      showPageSize && onLimitChange && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
        /* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: "Rows per page:" }),
        /* @__PURE__ */ jsxs(
          Select,
          {
            value: String(limit),
            onValueChange: (value) => onLimitChange(Number(value)),
            children: [
              /* @__PURE__ */ jsx(SelectTrigger, { className: "h-8 w-[70px]", "data-cy": sel("superadmin.pagination.pageSize"), children: /* @__PURE__ */ jsx(SelectValue, { placeholder: String(limit) }) }),
              /* @__PURE__ */ jsx(SelectContent, { children: pageSizeOptions.map((size) => /* @__PURE__ */ jsx(SelectItem, { value: String(size), children: size }, size)) })
            ]
          }
        )
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "text-sm text-muted-foreground", children: [
        "Page ",
        page,
        " of ",
        totalPages || 1
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
        /* @__PURE__ */ jsxs(
          Button,
          {
            variant: "outline",
            size: "icon",
            className: "h-8 w-8",
            onClick: () => onPageChange(1),
            disabled: !canGoPrevious,
            "data-cy": sel("superadmin.pagination.first"),
            children: [
              /* @__PURE__ */ jsx(ChevronsLeft, { className: "h-4 w-4" }),
              /* @__PURE__ */ jsx("span", { className: "sr-only", children: "First page" })
            ]
          }
        ),
        /* @__PURE__ */ jsxs(
          Button,
          {
            variant: "outline",
            size: "icon",
            className: "h-8 w-8",
            onClick: () => onPageChange(page - 1),
            disabled: !canGoPrevious,
            "data-cy": sel("superadmin.pagination.prev"),
            children: [
              /* @__PURE__ */ jsx(ChevronLeft, { className: "h-4 w-4" }),
              /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Previous page" })
            ]
          }
        ),
        /* @__PURE__ */ jsxs(
          Button,
          {
            variant: "outline",
            size: "icon",
            className: "h-8 w-8",
            onClick: () => onPageChange(page + 1),
            disabled: !canGoNext,
            "data-cy": sel("superadmin.pagination.next"),
            children: [
              /* @__PURE__ */ jsx(ChevronRight, { className: "h-4 w-4" }),
              /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Next page" })
            ]
          }
        ),
        /* @__PURE__ */ jsxs(
          Button,
          {
            variant: "outline",
            size: "icon",
            className: "h-8 w-8",
            onClick: () => onPageChange(totalPages),
            disabled: !canGoNext,
            "data-cy": sel("superadmin.pagination.last"),
            children: [
              /* @__PURE__ */ jsx(ChevronsRight, { className: "h-4 w-4" }),
              /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Last page" })
            ]
          }
        )
      ] })
    ] })
  ] });
}
export {
  PaginationControls
};
