import { jsx as t, jsxs as A } from "react/jsx-runtime";
import { classNames as d } from "./index-classNames.js";
import { lazyImport as J } from "./index-lazy-import.js";
import { ComponentContainer as K } from "./index-ComponentContainer.js";
import { Render as h } from "./index-Render.js";
import { TableFooter as Q } from "./index-TableFooter.js";
import { TableHeader as U } from "./index-TableHeader.js";
import { useState as o, useEffect as P, Suspense as V, createContext as W } from "react";
import { TablePlaceholder as X, TableRowPlaceholder as Y } from "./index-TablePlaceholder.js";
import f from "./index-Table.module.scss.js";
const Z = J(() => import("./index-TableBody.js"), "TableBody"), _ = W({}), de = (p) => {
  let {
    // eslint-disable-next-line prefer-const
    containerClassName: y = "",
    // eslint-disable-next-line prefer-const
    className: C = "",
    pagination: e = {
      total: 0,
      limit: 0,
      offset: 0,
      page: 0,
      minPage: 0,
      maxPage: 0,
      step: 1
    },
    // eslint-disable-next-line prefer-const
    data: a = {
      options: {},
      columns: [],
      collections: []
    },
    // eslint-disable-next-line prefer-const
    onNextPage: D = void 0,
    // eslint-disable-next-line prefer-const
    onPrevPage: T = void 0,
    // eslint-disable-next-line prefer-const
    onShowMore: x = void 0,
    // eslint-disable-next-line prefer-const
    isLoading: N = !1,
    // eslint-disable-next-line prefer-const
    onShowLess: w = void 0,
    // eslint-disable-next-line prefer-const
    hideFooter: n = !1
  } = p;
  const {
    blurredMessage: B,
    blurredCta: M,
    replacements: v,
    hideBlurredMessage: S,
    hasGreyBody: g
  } = p, l = a.collections ?? [], i = a.columns ?? [], r = a.options ?? {}, u = e.total, [G, L] = o(l), [s, O] = o(i), [R, j] = o(r), [$, F] = o(e.total), [H, k] = o(e.offset), [c, z] = o(e.limit), [ee, b] = o(e.page), [E, I] = o(e);
  P(() => {
    n && (z(0), k(0), b(1));
  }, [n]), P(() => {
    if (i && O(i), l && L(l), r && j(r), c > 0) {
      const m = (H + c) / c;
      e = {
        total: e.total ?? 0,
        limit: e.limit,
        offset: e.offset,
        minPage: e.minPage,
        maxPage: e.maxPage,
        step: e.step,
        page: m
      }, e && I(e), u && F(u), m && b(m);
    }
  }, [a]);
  const q = {
    data: {
      options: {
        ...R
      },
      columns: [...s],
      collections: [...G],
      blurredMessage: B,
      hideBlurredMessage: S,
      blurredCta: M,
      replacements: v
    },
    pagination: E,
    onNextPage: D,
    onPrevPage: T,
    onShowMore: x,
    onShowLess: w
  };
  return N ? t(X, {}) : t(_.Provider, {
    value: {
      ...q
    },
    children: t(K, {
      className: d(f.container, y),
      children: t("table", {
        className: d(f.table, C),
        children: A(h, {
          if: !!s,
          children: [t(U, {
            order: s && s[0].alias,
            className: d(f.tableHead),
            hasGreyTheme: g
          }), t(V, {
            fallback: t("tbody", {
              children: t("tr", {
                children: t("td", {
                  children: t(Y, {})
                })
              })
            }),
            children: t(Z, {
              hasGreyBody: g
            })
          }), t(h, {
            if: !n,
            children: t(Q, {})
          })]
        })
      })
    })
  });
};
export {
  de as Table,
  _ as TableProvider
};
