import { b9 as m, bg as G, fy as U, dT as E, c1 as x, V as i, fz as T, d4 as _, d5 as q, P as J, d6 as K, bh as Q, cy as X, fA as Y, fB as Z, d7 as tt, O as et, db as it, dc as nt } from "./684d2f28.js";
import { createContext as ot, useRef as at, useContext as $, useMemo as o } from "react";
import { ContextContainerComp as rt } from "./5d871440.js";
import "react-dom";
const st = m.div`
  height: 100%;
  border: 1px solid ${(e) => e.$style.border};
  border-radius: ${(e) => e.$style.radius};
  padding: 3px ${(e) => e.$paddingWidth};
  background-color: ${(e) => e.$style.background};
`, ct = m.div`
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
`, lt = m.div`
  height: ${(e) => e.$autoHeight ? "100%" : "calc(100% - 32px)"};
`, dt = m.div` 
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: 'wrap'};
`, gt = m.div`
  height: ${(e) => e.$autoHeight ? "auto" : "100%"};
  display: flex;
  flex-direction: ${(e) => e.$isHorizontal ? "row" : "column"};
  height: 100%;
`, V = ot({
  horizontalWidth: "100%",
  minHorizontalWidth: "100px"
}), ht = (e) => {
  const {
    horizontalWidth: d,
    minHorizontalWidth: t
  } = $(V);
  return /* @__PURE__ */ i("div", {
    style: {
      width: d,
      minWidth: t
    },
    children: /* @__PURE__ */ i(it, {
      ...e,
      emptyRows: 15,
      containerPadding: [4, 4],
      hintPlaceholder: nt
    })
  });
};
function mt({
  minHorizontalWidth: e,
  horizontalWidth: d,
  ...t
}) {
  const {
    itemIdx: c,
    offset: a,
    containerProps: l,
    autoHeight: w,
    scrollContainerRef: y,
    minHeight: p
  } = t;
  return /* @__PURE__ */ i(V.Provider, {
    value: {
      horizontalWidth: d,
      minHorizontalWidth: e
    },
    children: /* @__PURE__ */ i(ht, {
      layout: l.layout,
      items: tt(l.items),
      positionParams: l.positionParams,
      dispatch: c === a ? l.dispatch : x.noop,
      style: {
        height: "100%",
        backgroundColor: "transparent",
        flex: "auto"
      },
      autoHeight: w,
      isDroppable: c === a,
      isDraggable: c === a,
      isResizable: c === a,
      isSelectable: c === a,
      scrollContainerRef: y,
      overflow: "hidden",
      minHeight: p,
      enableGridLines: !0
    })
  });
}
function yt(e) {
  const {
    comp: d
  } = e, t = d.children, c = at(null), a = $(G), l = a.isDragging, [w, y] = U(0, l), p = o(() => t.dynamicHeight.getView(), [t.dynamicHeight]), P = o(() => t.heightUnitOfRow.getView(), [t.heightUnitOfRow]), R = o(() => t.container.getView(), [t.container]), S = o(() => t.itemIndexName.getView(), [t.itemIndexName]), v = o(() => t.itemDataName.getView(), [t.itemDataName]), {
    data: I,
    itemCount: z
  } = o(() => E(t.noOfRows.getView()), [t.noOfRows]), u = o(() => t.autoHeight.getView(), [t.autoHeight]), O = o(() => t.scrollbars.getView(), [t.scrollbars]), C = o(() => t.horizontal.getView(), [t.horizontal]), D = o(() => t.minHorizontalWidth.getView(), [t.minHorizontalWidth]), h = o(() => Math.max(1, t.noOfColumns.getView()), [t.noOfColumns]), r = o(() => {
    const s = t.pagination.getView(), g = s.total || z;
    let f = s.current, n = (f - 1) * s.pageSize;
    const H = Math.max(0, Math.min(s.pageSize, g - n));
    return {
      pagination: {
        ...s,
        current: f,
        total: g
      },
      offset: n,
      currentPageSize: H,
      total: g
    };
  }, [t.pagination, z]), W = t.style.getView(), M = d.realSimpleContainer().children.layout.getView(), b = r.currentPageSize > 0 && (x.isEmpty(M) || a.isDragging), L = b ? 1 : Math.floor((r.currentPageSize + h - 1) / h), k = b ? "100%" : p ? "auto" : P * 44 + "px", N = l && u ? w + "px" : "100%", F = x.range(0, L).map((s) => /* @__PURE__ */ i("div", {
    style: {
      height: k,
      width: "100%"
    },
    children: /* @__PURE__ */ i(dt, {
      children: x.range(0, h).map((f) => {
        const n = s * h + f + r.offset;
        if (n >= r.total || n >= r.offset + r.pagination.pageSize || b && n > r.offset)
          return /* @__PURE__ */ i("div", {
            style: {
              flex: "auto"
            }
          }, n);
        const H = R({
          [S]: n,
          [v]: T(I, n)
        }, String(n)).getView(), B = () => {
          d.children.container.dispatch(et(rt.batchDeleteAction([String(n)])));
        };
        return /* @__PURE__ */ i(mt, {
          itemIdx: n,
          offset: r.offset,
          containerProps: H,
          autoHeight: l || p,
          scrollContainerRef: c,
          minHeight: N,
          unMountFn: B,
          horizontalWidth: `${100 / h}%`,
          minHorizontalWidth: C ? D : "0px"
        }, n);
      })
    })
  }, s)), j = a.getAppSettings().maxWidth, A = _(j) ? "4px" : "16px";
  return /* @__PURE__ */ i(q.Provider, {
    value: W.background,
    children: /* @__PURE__ */ J(st, {
      $style: W,
      $paddingWidth: A,
      children: [/* @__PURE__ */ i(lt, {
        ref: c,
        $autoHeight: u,
        children: /* @__PURE__ */ i(K, {
          style: {
            height: u ? "auto" : "100%",
            margin: "0px",
            padding: "0px"
          },
          hideScrollbar: !O,
          children: /* @__PURE__ */ i(Q, {
            children: /* @__PURE__ */ i(X, {
              onResize: (s, g) => {
                g && y(g);
              },
              observerOptions: {
                box: "border-box"
              },
              children: /* @__PURE__ */ i(gt, {
                $isHorizontal: C,
                $autoHeight: u,
                children: F
              })
            })
          })
        })
      }), /* @__PURE__ */ i(ct, {
        children: /* @__PURE__ */ i(Y, {
          size: "small",
          itemRender: Z,
          ...r.pagination
        })
      })]
    })
  });
}
export {
  yt as ListView
};
