"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
;/* empty css                                                                                                                                                                                        */
;/* empty css                                                                                                                                                                                         */
;/* empty css                                                                                                                                                                                                 */
;/* empty css                                                                                                                                                                                            */
;/* empty css                                                                                                                                                                                            */
const index = require("../../primitive/Select/index.cjs");
require("clsx");
const styles = require("../../utils/styles.cjs");
const Flex = require("../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/components/Flex/Flex.cjs");
const Text = require("../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/components/Text/Text.cjs");
const Pagination = require("../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/components/Pagination/Pagination.cjs");
const parseFromValuesOrFunc = (fn, arg) => fn instanceof Function ? fn(arg) : fn;
const defaultRowsPerPage = [5, 10, 15, 20, 25, 30, 50, 100].map((x) => ({ value: x.toString(), label: `${x} / page` }));
const ProTablePagination = ({ table, ...props }) => {
  const {
    getPrePaginationRowModel,
    getState,
    options: {
      icons: { IconChevronLeft, IconChevronRight, IconChevronLeftPipe, IconChevronRightPipe },
      mantinePaginationProps,
      rowCount
    },
    setPageIndex,
    setPageSize
  } = table;
  const {
    pagination: { pageIndex = 0, pageSize = 10 }
  } = getState();
  const paginationProps = {
    ...parseFromValuesOrFunc(mantinePaginationProps, {
      table
    }),
    ...props
  };
  const totalRowCount = rowCount ?? getPrePaginationRowModel().rows.length;
  const numberOfPages = Math.ceil(totalRowCount / pageSize);
  const showFirstLastPageButtons = ((paginationProps == null ? void 0 : paginationProps.total) || numberOfPages) > 2;
  const {
    rowsPerPageOptions = defaultRowsPerPage,
    showRowsPerPage = false,
    showTotal = false,
    withEdges = showFirstLastPageButtons,
    localization,
    ...rest
  } = paginationProps ?? {};
  return /* @__PURE__ */ jsxRuntime.jsxs(
    Flex.Flex,
    {
      align: "center",
      justify: !showTotal && !showRowsPerPage ? "center" : showTotal ? "space-between" : "flex-end",
      mt: "xs",
      ...paginationProps.wrapperProps,
      children: [
        paginationProps.showTotal && /* @__PURE__ */ jsxRuntime.jsxs(Flex.Flex, { align: "center", gap: 2, children: [
          /* @__PURE__ */ jsxRuntime.jsxs(Text.Text, { c: "carbon.7", children: [
            (localization == null ? void 0 : localization.total) || "Total:",
            " "
          ] }),
          /* @__PURE__ */ jsxRuntime.jsx(Text.Text, { c: "carbon.8", children: totalRowCount.toLocaleString() })
        ] }),
        /* @__PURE__ */ jsxRuntime.jsxs(Flex.Flex, { align: "center", gap: "xs", children: [
          /* @__PURE__ */ jsxRuntime.jsx(
            Pagination.Pagination,
            {
              nextIcon: IconChevronRight,
              onChange: paginationProps.onChange ?? ((newPageIndex) => setPageIndex(newPageIndex - 1)),
              previousIcon: IconChevronLeft,
              firstIcon: IconChevronLeftPipe,
              lastIcon: IconChevronRightPipe,
              total: (paginationProps == null ? void 0 : paginationProps.total) ?? numberOfPages,
              value: paginationProps.value ?? pageIndex + 1,
              withEdges,
              styles: styles.mergeStylesList([
                (theme) => ({
                  control: {
                    border: "none",
                    color: theme.colors.carbon[9],
                    borderRadius: theme.defaultRadius,
                    "&[data-active]": {
                      color: theme.colors.carbon[9],
                      background: theme.colors.carbon[4]
                    }
                  }
                }),
                rest.styles
              ]),
              ...rest
            }
          ),
          showRowsPerPage && /* @__PURE__ */ jsxRuntime.jsx(
            index.Select,
            {
              w: 114,
              size: "sm",
              allowDeselect: false,
              "aria-labelledby": "rpp-label",
              data: (paginationProps == null ? void 0 : paginationProps.rowsPerPageOptions) ?? defaultRowsPerPage,
              onChange: (value) => setPageSize(+value),
              value: pageSize.toString()
            }
          )
        ] })
      ]
    }
  );
};
exports.ProTablePagination = ProTablePagination;
exports.parseFromValuesOrFunc = parseFromValuesOrFunc;
