import { jsxs as w, Fragment as N, jsx as g } from "@emotion/react/jsx-runtime";
import { PagerActions as O } from "../PagerActions/PagerActions.js";
import { useState as L, useMemo as r, useEffect as x, useCallback as T } from "react";
import { useModuleDictionary as j } from "@m4l/core";
import { PAGER_DICTIONARY as P } from "../../dicctionary.js";
import { ContainerTotalRowSelectStyled as E, TotalRowStyled as I, LabelSelectContainerStyled as W, RowsPerPageStyled as F, ActionsContainerStyled as G } from "../../slots/PagerSlots.js";
import { Select as V } from "../../../extended/mui/Select/Select.js";
const U = (v) => {
  const {
    count: t,
    page: u,
    rowsPerPage: d = 25,
    rowsPerPageOptions: l = [10, 25, 50, 100],
    onRowsPerPageChange: h,
    onPageChange: c,
    size: m,
    labelOf: p,
    labelTotalRows: z
  } = v, [n, S] = L(d), [b, f] = L(Math.max(0, u)), { getLabel: o } = j(), s = r(() => Math.max(1, Math.ceil(t / n)), [t, n]);
  x(() => {
    f(Math.max(0, Math.min(u, s - 1)));
  }, [u, s]), x(() => {
    l.includes(d) && S(d);
  }, [d, l]);
  const i = r(() => Math.max(0, Math.min(b, s - 1)), [b, s]), R = r(() => o(P.page), [o]), C = r(() => o(P.rows), [o]), A = r(() => o(P.rows_per_page), [o]), M = r(() => o(P.no_records), [o]), _ = r(() => {
    if (t === 0)
      return M;
    const e = i + 1;
    return `${R} ${e} ${p} ${s}`;
  }, [i, s, t, p, R, M]), $ = T((e) => {
    const a = Number(e.id), D = Math.ceil(t / a), y = Math.min(i, D - 1);
    S(a), f(y), h && h({ id: a, value: a, label: `${a} ${C}` }), c && c(null, y);
  }, [t, i, C, c, h]), k = T((e) => {
    e && $(e);
  }, [$]);
  return /* @__PURE__ */ w(N, { children: [
    l?.length > 1 ? /* @__PURE__ */ w(E, { children: [
      /* @__PURE__ */ g(I, { skeletonWidth: 50, size: m, variant: "bodyStandard", children: `${z}: ${Math.min(n, t - i * n)} ${p} ${t}` }),
      /* @__PURE__ */ w(W, { children: [
        /* @__PURE__ */ g(F, { skeletonWidth: 50, size: m, variant: "bodyStandard", children: `${A}:` }),
        /* @__PURE__ */ g(
          V,
          {
            size: m,
            value: l.includes(n) ? n.toString() : l[0].toString(),
            onChange: k,
            options: l.map((e) => ({
              id: e.toString(),
              value: e.toString(),
              label: e.toString()
            }))
          }
        )
      ] })
    ] }) : null,
    /* @__PURE__ */ g(G, { children: /* @__PURE__ */ g(
      O,
      {
        size: m,
        count: t,
        page: i,
        rowsPerPage: n,
        pageCounter: _,
        onPageChange: (e, a) => {
          f(a), c && c(e, a);
        }
      }
    ) })
  ] });
};
export {
  U as CustomTablePagination
};
