import { jsx as t } from "../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { toChildArray as b } from "../../../external/.pnpm/preact@10.28.2/node_modules/preact/dist/preact.module.js";
import s from "classnames";
/* empty css              */
import { TableBody as v } from "./components/TableBody.js";
import { InteractiveBody as w } from "./components/InteractiveBody.js";
import C from "./components/SkeletonBody.js";
import { ErrorMessageDisplay as _ } from "../ErrorMessageDisplay/ErrorMessageDisplay.js";
import { useMemo as n } from "../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { DataGridProvider as x } from "./utils/DataGridProvider.js";
import { useDataGridContext as T } from "./hooks/useDataGridContext.js";
import { TableHeaderCell as k } from "./components/TableHeaderCell.js";
import N from "../../../core/Context/preact/useCoreContext.js";
const $ = Object.freeze({
  activeIndex: -1,
  index: -1
});
function c({ errorDisplay: e, ...l }) {
  return /* @__PURE__ */ t("div", { style: { width: "100%" }, children: /* @__PURE__ */ t(x, { children: /* @__PURE__ */ t(B, { ...l, errorDisplay: e }) }) });
}
function B({ autoFitColumns: e, errorDisplay: l, ...a }) {
  const r = n(() => b(a.children), [a.children]), g = n(() => r.find((d) => d?.type === u), [r]), o = n(() => a.data?.length === 0, [a.data]), y = n(() => !a.loading && (o || a.error), [o, a.error, a.loading]), { getMinWidthByColumn: f } = T(), { getImageAsset: m } = N(), i = a.columns.filter((d) => d.visible !== !1).map((d) => ({ ...d, minWidth: f(d.key) })), h = i.map((d) => `minmax(${(d.minWidth || 100) + (a.narrowColumns ? 0 : 40)}px, ${d.flex || 1}fr)`).join(" ");
  return /* @__PURE__ */ t(
    "div",
    {
      className: s("adyen-pe-data-grid", {
        "adyen-pe-data-grid--condensed": a.condensed,
        "adyen-pe-data-grid--outline": a.outline,
        "adyen-pe-data-grid--scrollable": a.scrollable,
        "adyen-pe-data-grid--loading": a.loading,
        "adyen-pe-data-grid--empty": o || a.error
      }),
      style: e ? void 0 : {
        "--adyen-pe-data-grid-cols": i.length,
        "--adyen-pe-data-grid-cells": h
      },
      children: [
        /* @__PURE__ */ t("div", { className: "adyen-pe-data-grid__table-wrapper", children: [
          /* @__PURE__ */ t("div", { role: "table", className: "adyen-pe-data-grid__table", children: [
            /* @__PURE__ */ t("div", { className: "adyen-pe-data-grid__head", role: "rowgroup", children: /* @__PURE__ */ t("div", { role: "rowheader", className: "adyen-pe-data-grid__header", style: a.loading ? { width: "100%" } : {}, children: i.map((d) => /* @__PURE__ */ t(k, { label: d.label, position: d.position, cellKey: d.key }, d.key)) }) }),
            /* @__PURE__ */ t(R, { ...a, columns: i, emptyBody: o })
          ] }),
          y && (o && !a.error ? /* @__PURE__ */ t(
            _,
            {
              withHeaderOffset: !0,
              title: a.emptyTableMessage?.title ?? "common.errors.noResults",
              message: a.emptyTableMessage?.message,
              imageDesktop: m?.({ name: "no-results-found" }),
              imageMobile: m?.({ name: "no-results-found", subFolder: "images/small" }),
              centered: !0
            }
          ) : a.error && l ? l() : null)
        ] }),
        g
      ]
    }
  );
}
function R(e) {
  const l = n(() => e.loading || e.emptyBody || e.error, [e.emptyBody, e.error, e.loading]);
  return /* @__PURE__ */ t(
    "div",
    {
      role: "rowgroup",
      className: s("adyen-pe-data-grid__body"),
      style: l && { display: "grid", gridTemplateColumns: "1fr" },
      children: l ? /* @__PURE__ */ t(C, { columnsNumber: e.columns.length, loading: e.loading }) : e.onRowClick ? /* @__PURE__ */ t(
        w,
        {
          onRowHover: e.onRowHover,
          data: e.data,
          columns: e.columns,
          onRowClick: e.onRowClick,
          customCells: e.customCells
        }
      ) : /* @__PURE__ */ t(
        v,
        {
          onRowHover: e.onRowHover,
          data: e.data,
          customCells: e.customCells,
          columns: e.columns
        }
      )
    }
  );
}
c.Footer = u;
function u({ children: e }) {
  return /* @__PURE__ */ t("div", { className: "adyen-pe-data-grid__footer", children: e });
}
c.defaultProps = {
  condensed: !1,
  outline: !0,
  scrollable: !0
};
export {
  $ as INITIAL_STATE,
  c as default
};
