import { a3 as p, f5 as _, am as q, fA as J, e1 as K, _ as x, H as i, fB as Q, cS as X, fC as Y, fD as Z, fa as tt, ad as et, eh as it, aI as ot, fE as nt, fF as at, fc as rt, fG as st, fj as lt, fk as ct } from "./56c67d3b.js";
import { createContext as dt, useRef as ht, useContext as V, useMemo as o } from "react";
import { ContextContainerComp as gt } from "./40fca083.js";
import "react-dom";
const mt = p.div`
  height: 100%;
  border: 1px solid ${(e) => e.$style.border};
  border-radius: ${(e) => e.$style.radius};
  padding: 3px ${(e) => e.$paddingWidth};
  rotate: ${(e) => e.$style.rotation};
  ${(e) => _(e.$style)}
  ${(e) => e.$animationStyle}
  
`, pt = p.div`
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
`, ut = p.div`
  overflow: ${(e) => e.$autoHeight ? "hidden" : "auto"}; 
  height: ${(e) => e.$autoHeight ? "auto" : "calc(100% - 32px)"};
`, ft = p.div` 
  height: 100%;
  display: flex;
  align-items: center;
  // justify-content: center;
`, wt = p.div`
  height: ${(e) => e.$autoHeight ? "auto" : "100%"};
  display: flex;
  flex-direction: ${(e) => e.$isHorizontal ? "row" : "column"};
`, W = dt({
  horizontalWidth: "100%",
  minHorizontalWidth: "100px"
}), xt = (e) => {
  const {
    horizontalWidth: a,
    minHorizontalWidth: t
  } = V(W);
  return /* @__PURE__ */ i("div", {
    style: {
      width: a,
      minWidth: t || "0px"
    },
    children: /* @__PURE__ */ i(lt, {
      ...e,
      emptyRows: 15,
      containerPadding: [4, 4],
      hintPlaceholder: ct
    })
  });
};
function yt({
  minHorizontalWidth: e,
  horizontalWidth: a,
  ...t
}) {
  const {
    itemIdx: c,
    offset: r,
    containerProps: d,
    autoHeight: y,
    scrollContainerRef: H,
    minHeight: u,
    horizontalGridCells: z
  } = t;
  return /* @__PURE__ */ i(W.Provider, {
    value: {
      horizontalWidth: a,
      minHorizontalWidth: e
    },
    children: /* @__PURE__ */ i(xt, {
      layout: d.layout,
      items: rt(d.items),
      horizontalGridCells: z,
      positionParams: d.positionParams,
      dispatch: c === r ? d.dispatch : x.noop,
      style: {
        height: "100%",
        // in case of horizontal mode, minHorizontalWidth is 0px
        width: e || "100%",
        backgroundColor: "transparent"
        // flex: "auto",
      },
      autoHeight: y,
      isDroppable: c === r,
      isDraggable: c === r,
      isResizable: c === r,
      isSelectable: c === r,
      scrollContainerRef: H,
      overflow: "hidden",
      minHeight: u,
      enableGridLines: !0
    })
  });
}
function bt(e) {
  const {
    comp: a
  } = e, t = a.children, c = ht(null), r = V(q), d = r.isDragging, [y, H] = J(0, d), u = o(() => t.dynamicHeight.getView(), [t.dynamicHeight]), z = o(() => t.heightUnitOfRow.getView(), [t.heightUnitOfRow]), v = o(() => t.container.getView(), [t.container]), P = o(() => t.itemIndexName.getView(), [t.itemIndexName]), I = o(() => t.itemDataName.getView(), [t.itemDataName]), {
    data: R,
    itemCount: C
  } = o(() => K(t.noOfRows.getView()), [t.noOfRows]), D = o(() => t.horizontalGridCells.getView(), [t.horizontalGridCells]), m = o(() => t.autoHeight.getView(), [t.autoHeight]), O = o(() => t.showHorizontalScrollbar.getView(), [t.showHorizontalScrollbar]), M = o(() => t.showVerticalScrollbar.getView(), [t.showVerticalScrollbar]), f = o(() => t.horizontal.getView(), [t.horizontal]), G = o(() => t.minHorizontalWidth.getView(), [t.minHorizontalWidth]), g = o(() => Math.max(1, t.noOfColumns.getView()), [t.noOfColumns]), s = o(() => {
    const l = t.pagination.getView(), h = l.total || C;
    let w = l.current, n = (w - 1) * l.pageSize;
    const $ = Math.max(0, Math.min(l.pageSize, h - n));
    return {
      pagination: {
        ...l,
        current: w,
        total: h
      },
      offset: n,
      currentPageSize: $,
      total: h
    };
  }, [t.pagination, C]), b = t.style.getView(), L = t.animationStyle.getView(), k = a.realSimpleContainer().children.layout.getView(), S = s.currentPageSize > 0 && (x.isEmpty(k) || r.isDragging), N = S ? 1 : Math.floor((s.currentPageSize + g - 1) / g), j = S ? "100%" : u ? "auto" : z * 44 + "px", B = d && m ? y + "px" : "100%", F = x.range(0, N).map((l) => /* @__PURE__ */ i("div", {
    style: {
      height: j,
      width: "100%"
    },
    children: /* @__PURE__ */ i(ft, {
      children: x.range(0, g).map((w) => {
        const n = l * g + w + s.offset;
        if (n >= s.total || n >= s.offset + s.pagination.pageSize || S && n > s.offset)
          return /* @__PURE__ */ i("div", {
            style: {
              flex: "auto"
            }
          }, n);
        const $ = v({
          [P]: n,
          [I]: Q(R, n)
        }, String(n)).getView(), T = () => {
          a.children.container.dispatch(st(gt.batchDeleteAction([String(n)])));
        };
        return /* @__PURE__ */ i(yt, {
          itemIdx: n,
          offset: s.offset,
          containerProps: $,
          horizontalGridCells: D,
          autoHeight: d || u,
          scrollContainerRef: c,
          minHeight: B,
          unMountFn: T,
          horizontalWidth: `${100 / g}%`,
          minHorizontalWidth: f ? G : void 0
        }, n);
      })
    })
  }, l)), A = r.getAppSettings().maxWidth, E = X(A) ? "4px" : "16px", U = Y(a.children);
  return Z(U, a.dispatch), /* @__PURE__ */ i(tt.Provider, {
    value: b.background,
    children: /* @__PURE__ */ et(mt, {
      $style: b,
      $paddingWidth: E,
      $animationStyle: L,
      children: [/* @__PURE__ */ i(ut, {
        ref: c,
        $autoHeight: m,
        children: /* @__PURE__ */ i(it, {
          style: {
            height: m ? "auto" : "100%",
            margin: "0px",
            padding: "0px"
          },
          hideScrollbar: f ? !O : !M,
          overflow: m ? f ? "scroll" : "hidden" : "scroll",
          children: /* @__PURE__ */ i(ot, {
            onResize: (l, h) => {
              h && H(h);
            },
            observerOptions: {
              box: "border-box"
            },
            render: () => /* @__PURE__ */ i(wt, {
              $isHorizontal: f,
              $isGrid: g > 1,
              $autoHeight: m,
              children: F
            })
          })
        })
      }), /* @__PURE__ */ i(pt, {
        children: /* @__PURE__ */ i(nt, {
          size: "small",
          itemRender: at,
          ...s.pagination
        })
      })]
    })
  });
}
export {
  bt as ListView
};
