import { jsxs, jsx } from "react/jsx-runtime";
/* empty css                                                                                                                                                                                       */
/* empty css                                                                                                                                                                                        */
/* empty css                                                                                                                                                                                                */
/* empty css                                                                                                                                                                                           */
/* empty css                                                                                                                                                                                           */
import { Select } from "../../primitive/Select/index.mjs";
import "clsx";
import { mergeStylesList } from "../../utils/styles.mjs";
import { Flex } from "../../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.mjs";
import { Text } from "../../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.mjs";
import { Pagination } from "../../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.mjs";
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__ */ jsxs(
    Flex,
    {
      align: "center",
      justify: !showTotal && !showRowsPerPage ? "center" : showTotal ? "space-between" : "flex-end",
      mt: "xs",
      ...paginationProps.wrapperProps,
      children: [
        paginationProps.showTotal && /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
          /* @__PURE__ */ jsxs(Text, { c: "carbon.7", children: [
            (localization == null ? void 0 : localization.total) || "Total:",
            " "
          ] }),
          /* @__PURE__ */ jsx(Text, { c: "carbon.8", children: totalRowCount.toLocaleString() })
        ] }),
        /* @__PURE__ */ jsxs(Flex, { align: "center", gap: "xs", children: [
          /* @__PURE__ */ jsx(
            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: 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__ */ jsx(
            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()
            }
          )
        ] })
      ]
    }
  );
};
export {
  ProTablePagination,
  parseFromValuesOrFunc
};
