"use client";
import { jsxs as h, jsx as a } from "react/jsx-runtime";
import { Pagination as k, PaginationContent as M, PaginationItem as t, PaginationFirst as D, PaginationPrevious as w, PaginationLink as $, PaginationNext as j, PaginationLast as F } from "../../../pagination.js";
function R({
  table: n,
  isServerSide: l,
  clientPagination: f,
  serverState: i,
  onServerStateChange: g,
  totalItems: I,
  i18n: s
}) {
  const P = l ? i?.pagination?.pageIndex ?? 0 : n.getState().pagination.pageIndex, u = l ? i?.pagination?.pageSize ?? f.pageSize : n.getState().pagination.pageSize, x = l ? I ?? 0 : n.getFilteredRowModel().rows.length, N = x === 0 ? 0 : P * u + 1, z = x === 0 ? 0 : Math.min((P + 1) * u, x);
  return /* @__PURE__ */ h(k, { className: "h-6", children: [
    /* @__PURE__ */ a("div", { className: "flex h-full flex-1 items-center align-middle text-xs", children: /* @__PURE__ */ a("div", { className: "text-d-foreground hidden md:flex", children: `${N}-${z} / ${x} ${s.pagination.rows}` }) }),
    /* @__PURE__ */ h(M, { children: [
      /* @__PURE__ */ a(t, { className: "h-full", children: /* @__PURE__ */ a(
        D,
        {
          className: "h-full text-xs",
          size: "sm",
          isDisabled: !n.getCanPreviousPage(),
          label: s.pagination.first,
          onClick: () => {
            l && i && g ? g({
              ...i,
              pagination: {
                ...i.pagination,
                pageIndex: 0
              }
            }) : n.setPageIndex(0);
          },
          "aria-label": "Go to first page"
        }
      ) }),
      /* @__PURE__ */ a(t, { className: "h-full", children: /* @__PURE__ */ a(
        w,
        {
          className: "h-full text-xs",
          size: "sm",
          isDisabled: !n.getCanPreviousPage(),
          label: s.pagination.previous,
          onClick: () => {
            if (n.getCanPreviousPage())
              if (l && i && g) {
                const o = i.pagination.pageIndex ?? f.pageIndex, d = Math.max(o - 1, 0);
                g({
                  ...i,
                  pagination: {
                    ...i.pagination,
                    pageIndex: d
                  }
                });
              } else
                n.previousPage();
          }
        }
      ) }),
      (() => {
        const o = n.getState().pagination.pageIndex, d = n.getPageCount(), c = 5;
        let m = Math.max(
          0,
          o - Math.floor(c / 2)
        ), p = m + c;
        return p > d && (p = d, m = Math.max(0, p - c)), n.getPageOptions().slice(m, p).map((e, C) => /* @__PURE__ */ a(t, { className: "h-full", children: /* @__PURE__ */ a(
          $,
          {
            className: "h-full text-sm",
            size: "icon",
            isActive: o === e,
            onClick: () => {
              if (l && i && g) {
                if (o === e) return;
                g({
                  ...i,
                  pagination: {
                    ...i.pagination,
                    pageIndex: e
                  }
                });
              } else
                n.setPageIndex(e);
            },
            children: e + 1
          }
        ) }, C));
      })(),
      /* @__PURE__ */ a(t, { className: "h-full", children: /* @__PURE__ */ a(
        j,
        {
          className: "h-full text-xs",
          size: "sm",
          isDisabled: !n.getCanNextPage(),
          label: s.pagination.next,
          onClick: () => {
            n.getCanNextPage() && (l && i && g ? g({
              ...i,
              pagination: {
                ...i.pagination,
                pageIndex: i.pagination.pageIndex + 1
              }
            }) : n.nextPage());
          }
        }
      ) }),
      /* @__PURE__ */ a(t, { className: "h-full", children: /* @__PURE__ */ a(
        F,
        {
          className: "h-full text-xs",
          size: "sm",
          isDisabled: !n.getCanNextPage(),
          label: s.pagination.last,
          onClick: () => {
            l && i && g ? g({
              ...i,
              pagination: {
                ...i.pagination,
                pageIndex: n.getPageCount() - 1
              }
            }) : n.setPageIndex(n.getPageCount() - 1);
          },
          "aria-label": "Go to last page"
        }
      ) })
    ] }),
    /* @__PURE__ */ a("div", { className: "flex h-full flex-1 items-center justify-end align-middle text-xs", children: /* @__PURE__ */ a("div", { className: "text-d-foreground hidden md:flex", children: (n.getPageCount() ? n.getState().pagination.pageIndex + 1 : 0) + " / " + n.getPageCount() + " " + s.pagination.pages }) })
  ] });
}
export {
  R as DataTablePaginationComponent
};
