import { __exports as _ } from "./index-react-list2.js";
import le from "react";
import ue from "react/jsx-runtime";
var D;
function ve() {
  return D ? _ : (D = 1, (function(N) {
    (function(g, O) {
      O(N, le, ue);
    })(typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : _, function(g, O, P) {
      Object.defineProperty(g, "__esModule", {
        value: !0
      }), g.default = void 0;
      function d(a) {
        "@babel/helpers - typeof";
        return d = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(t) {
          return typeof t;
        } : function(t) {
          return t && typeof Symbol == "function" && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
        }, d(a);
      }
      function V(a, t) {
        if (!(a instanceof t)) throw new TypeError("Cannot call a class as a function");
      }
      function T(a, t) {
        for (var r = 0; r < t.length; r++) {
          var e = t[r];
          e.enumerable = e.enumerable || !1, e.configurable = !0, "value" in e && (e.writable = !0), Object.defineProperty(a, F(e.key), e);
        }
      }
      function B(a, t, r) {
        return t && T(a.prototype, t), r && T(a, r), Object.defineProperty(a, "prototype", { writable: !1 }), a;
      }
      function Y(a, t, r) {
        return t = w(t), U(a, k() ? Reflect.construct(t, r || [], w(a).constructor) : t.apply(a, r));
      }
      function U(a, t) {
        if (t && (d(t) == "object" || typeof t == "function")) return t;
        if (t !== void 0) throw new TypeError("Derived constructors may only return object or undefined");
        return W(a);
      }
      function W(a) {
        if (a === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
        return a;
      }
      function k() {
        try {
          var a = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
          }));
        } catch {
        }
        return (k = function() {
          return !!a;
        })();
      }
      function w(a) {
        return w = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(t) {
          return t.__proto__ || Object.getPrototypeOf(t);
        }, w(a);
      }
      function q(a, t) {
        if (typeof t != "function" && t !== null) throw new TypeError("Super expression must either be null or a function");
        a.prototype = Object.create(t && t.prototype, { constructor: { value: a, writable: !0, configurable: !0 } }), Object.defineProperty(a, "prototype", { writable: !1 }), t && R(a, t);
      }
      function R(a, t) {
        return R = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(r, e) {
          return r.__proto__ = e, r;
        }, R(a, t);
      }
      function A(a, t) {
        var r = Object.keys(a);
        if (Object.getOwnPropertySymbols) {
          var e = Object.getOwnPropertySymbols(a);
          t && (e = e.filter(function(i) {
            return Object.getOwnPropertyDescriptor(a, i).enumerable;
          })), r.push.apply(r, e);
        }
        return r;
      }
      function I(a) {
        for (var t = 1; t < arguments.length; t++) {
          var r = arguments[t] != null ? arguments[t] : {};
          t % 2 ? A(Object(r), !0).forEach(function(e) {
            C(a, e, r[e]);
          }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(a, Object.getOwnPropertyDescriptors(r)) : A(Object(r)).forEach(function(e) {
            Object.defineProperty(a, e, Object.getOwnPropertyDescriptor(r, e));
          });
        }
        return a;
      }
      function C(a, t, r) {
        return (t = F(t)) in a ? Object.defineProperty(a, t, { value: r, enumerable: !0, configurable: !0, writable: !0 }) : a[t] = r, a;
      }
      function F(a) {
        var t = Z(a, "string");
        return d(t) == "symbol" ? t : t + "";
      }
      function Z(a, t) {
        if (d(a) != "object" || !a) return a;
        var r = a[Symbol.toPrimitive];
        if (r !== void 0) {
          var e = r.call(a, t);
          if (d(e) != "object") return e;
          throw new TypeError("@@toPrimitive must return a primitive value.");
        }
        return (t === "string" ? String : Number)(a);
      }
      var H = {
        x: "clientWidth",
        y: "clientHeight"
      }, X = {
        x: "clientTop",
        y: "clientLeft"
      }, J = {
        x: "innerWidth",
        y: "innerHeight"
      }, b = {
        x: "offsetWidth",
        y: "offsetHeight"
      }, j = {
        x: "offsetLeft",
        y: "offsetTop"
      }, Q = {
        x: "overflowX",
        y: "overflowY"
      }, ee = {
        x: "scrollWidth",
        y: "scrollHeight"
      }, L = {
        x: "scrollLeft",
        y: "scrollTop"
      }, te = {
        x: "width",
        y: "height"
      }, S = function() {
      }, z = (function() {
        if (typeof window > "u") return !1;
        var a = !1;
        try {
          document.createElement("div").addEventListener("test", S, {
            get passive() {
              return a = !0, !1;
            }
          });
        } catch {
        }
        return a;
      })() ? {
        passive: !0
      } : !1, ce = "ReactList failed to reach a stable state.", re = 40, ie = function(t, r) {
        for (var e in r) if (t[e] !== r[e]) return !1;
        return !0;
      }, ae = function(t) {
        for (var r = t.props.axis, e = t.getEl(), i = Q[r]; e = e.parentElement; )
          switch (window.getComputedStyle(e)[i]) {
            case "auto":
            case "scroll":
            case "overlay":
              return e;
          }
        return window;
      }, ne = function(t) {
        var r = t.props.axis, e = t.scrollParent;
        return e === window ? window[J[r]] : e[H[r]];
      }, E = function(t, r) {
        var e = t.length, i = t.minSize, s = t.type, n = r.from, o = r.size, l = r.itemsPerRow;
        o = Math.max(o, i);
        var u = o % l;
        return u && (o += l - u), o > e && (o = e), n = s === "simple" || !n ? 0 : Math.max(Math.min(n, e - o), 0), (u = n % l) && (n -= u, o += u), n === r.from && o === r.size ? r : I(I({}, r), {}, {
          from: n,
          size: o
        });
      }, M = g.default = /* @__PURE__ */ (function(a) {
        function t(r) {
          var e;
          return V(this, t), e = Y(this, t, [r]), e.state = E(r, {
            itemsPerRow: 1,
            from: r.initialIndex,
            size: 0
          }), e.cache = {}, e.cachedScrollPosition = null, e.prevPrevState = {}, e.unstable = !1, e.updateCounter = 0, e;
        }
        return q(t, a), B(t, [{
          key: "componentDidMount",
          value: function() {
            this.updateFrameAndClearCache = this.updateFrameAndClearCache.bind(this), window.addEventListener("resize", this.updateFrameAndClearCache), this.updateFrame(this.scrollTo.bind(this, this.props.initialIndex));
          }
        }, {
          key: "componentDidUpdate",
          value: function(e) {
            var i = this;
            if (this.props.axis !== e.axis && this.clearSizeCache(), !this.unstable) {
              if (++this.updateCounter > re) {
                this.unstable = !0;
                return;
              }
              this.updateCounterTimeoutId || (this.updateCounterTimeoutId = setTimeout(function() {
                i.updateCounter = 0, delete i.updateCounterTimeoutId;
              }, 0)), this.updateFrame();
            }
          }
        }, {
          key: "maybeSetState",
          value: function(e, i) {
            if (ie(this.state, e)) return i();
            this.setState(e, i);
          }
        }, {
          key: "componentWillUnmount",
          value: function() {
            window.removeEventListener("resize", this.updateFrameAndClearCache), this.scrollParent.removeEventListener("scroll", this.updateFrameAndClearCache, z), this.scrollParent.removeEventListener("mousewheel", S, z);
          }
        }, {
          key: "getOffset",
          value: function(e) {
            var i = this.props.axis, s = e[X[i]] || 0, n = j[i];
            do
              s += e[n] || 0;
            while (e = e.offsetParent);
            return s;
          }
        }, {
          key: "getEl",
          value: function() {
            return this.el || this.items;
          }
        }, {
          key: "getScrollPosition",
          value: function() {
            if (typeof this.cachedScrollPosition == "number")
              return this.cachedScrollPosition;
            var e = this.scrollParent, i = this.props.axis, s = L[i], n = e === window ? (
              // Firefox always returns document.body[scrollKey] as 0 and Chrome/Safari
              // always return document.documentElement[scrollKey] as 0, so take
              // whichever has a value.
              document.body[s] || document.documentElement[s]
            ) : e[s], o = this.getScrollSize() - this.props.scrollParentViewportSizeGetter(this), l = Math.max(0, Math.min(n, o)), u = this.getEl();
            return this.cachedScrollPosition = this.getOffset(e) + l - this.getOffset(u), this.cachedScrollPosition;
          }
        }, {
          key: "setScroll",
          value: function(e) {
            var i = this.scrollParent, s = this.props.axis;
            if (e += this.getOffset(this.getEl()), i === window) return window.scrollTo(0, e);
            e -= this.getOffset(this.scrollParent), i[L[s]] = e;
          }
        }, {
          key: "getScrollSize",
          value: function() {
            var e = this.scrollParent, i = document, s = i.body, n = i.documentElement, o = ee[this.props.axis];
            return e === window ? Math.max(s[o], n[o]) : e[o];
          }
        }, {
          key: "hasDeterminateSize",
          value: function() {
            var e = this.props, i = e.itemSizeGetter, s = e.type;
            return s === "uniform" || i;
          }
        }, {
          key: "getStartAndEnd",
          value: function() {
            var e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.props.threshold, i = this.getScrollPosition(), s = Math.max(0, i - e), n = i + this.props.scrollParentViewportSizeGetter(this) + e;
            return this.hasDeterminateSize() && (n = Math.min(n, this.getSpaceBefore(this.props.length))), {
              start: s,
              end: n
            };
          }
        }, {
          key: "getItemSizeAndItemsPerRow",
          value: function() {
            var e = this.props, i = e.axis, s = e.useStaticSize, n = this.state, o = n.itemSize, l = n.itemsPerRow;
            if (s && o && l)
              return {
                itemSize: o,
                itemsPerRow: l
              };
            var u = this.items.children;
            if (!u.length) return {};
            var f = u[0], c = f[b[i]], h = Math.abs(c - o);
            if ((isNaN(h) || h >= 1) && (o = c), !o) return {};
            var p = j[i], m = f[p];
            l = 1;
            for (var v = u[l]; v && v[p] === m; v = u[l])
              ++l;
            return {
              itemSize: o,
              itemsPerRow: l
            };
          }
        }, {
          key: "clearSizeCache",
          value: function() {
            this.cachedScrollPosition = null;
          }
          // Called by 'scroll' and 'resize' events, clears scroll position cache.
        }, {
          key: "updateFrameAndClearCache",
          value: function(e) {
            return this.clearSizeCache(), this.updateFrame(e);
          }
        }, {
          key: "updateFrame",
          value: function(e) {
            switch (this.updateScrollParent(), typeof e != "function" && (e = S), this.props.type) {
              case "simple":
                return this.updateSimpleFrame(e);
              case "variable":
                return this.updateVariableFrame(e);
              case "uniform":
                return this.updateUniformFrame(e);
            }
          }
        }, {
          key: "updateScrollParent",
          value: function() {
            var e = this.scrollParent;
            this.scrollParent = this.props.scrollParentGetter(this), e !== this.scrollParent && (e && (e.removeEventListener("scroll", this.updateFrameAndClearCache), e.removeEventListener("mousewheel", S)), this.clearSizeCache(), this.scrollParent.addEventListener("scroll", this.updateFrameAndClearCache, z), this.scrollParent.addEventListener("mousewheel", S, z));
          }
        }, {
          key: "updateSimpleFrame",
          value: function(e) {
            var i = this.getStartAndEnd(), s = i.end, n = this.items.children, o = 0;
            if (n.length) {
              var l = this.props.axis, u = n[0], f = n[n.length - 1];
              o = this.getOffset(f) + f[b[l]] - this.getOffset(u);
            }
            if (o > s) return e();
            var c = this.props, h = c.pageSize, p = c.length, m = Math.min(this.state.size + h, p);
            this.maybeSetState({
              size: m
            }, e);
          }
        }, {
          key: "updateVariableFrame",
          value: function(e) {
            this.props.itemSizeGetter || this.cacheSizes();
            for (var i = this.getStartAndEnd(), s = i.start, n = i.end, o = this.props, l = o.length, u = o.pageSize, f = 0, c = 0, h = 0, p = l - 1; c < p; ) {
              var m = this.getSizeOfItem(c);
              if (m == null || f + m > s) break;
              f += m, ++c;
            }
            for (var v = l - c; h < v && f < n; ) {
              var y = this.getSizeOfItem(c + h);
              if (y == null) {
                h = Math.min(h + u, v);
                break;
              }
              f += y, ++h;
            }
            this.maybeSetState(E(this.props, {
              from: c,
              itemsPerRow: 1,
              size: h
            }), e);
          }
        }, {
          key: "updateUniformFrame",
          value: function(e) {
            var i = this.getItemSizeAndItemsPerRow(), s = i.itemSize, n = i.itemsPerRow;
            if (!s || !n) return e();
            var o = this.getStartAndEnd(), l = o.start, u = o.end, f = E(this.props, {
              from: Math.floor(l / s) * n,
              size: (Math.ceil((u - l) / s) + 1) * n,
              itemsPerRow: n
            }), c = f.from, h = f.size;
            return this.maybeSetState({
              itemsPerRow: n,
              from: c,
              itemSize: s,
              size: h
            }, e);
          }
        }, {
          key: "getSpaceBefore",
          value: function(e) {
            var i = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
            if (i[e] != null) return i[e];
            var s = this.state, n = s.itemSize, o = s.itemsPerRow;
            if (n)
              return i[e] = Math.floor(e / o) * n;
            for (var l = e; l > 0 && i[--l] == null; ) ;
            for (var u = i[l] || 0, f = l; f < e; ++f) {
              i[f] = u;
              var c = this.getSizeOfItem(f);
              if (c == null) break;
              u += c;
            }
            return i[e] = u;
          }
        }, {
          key: "cacheSizes",
          value: function() {
            for (var e = this.cache, i = this.state.from, s = this.items.children, n = b[this.props.axis], o = 0, l = s.length; o < l; ++o)
              e[i + o] = s[o][n];
          }
        }, {
          key: "getSizeOfItem",
          value: function(e) {
            var i = this.cache, s = this.items, n = this.props, o = n.axis, l = n.itemSizeGetter, u = n.itemSizeEstimator, f = n.type, c = this.state, h = c.from, p = c.itemSize, m = c.size;
            if (p) return p;
            if (l) return l(e);
            if (e in i) return i[e];
            if (f === "simple" && e >= h && e < h + m && s) {
              var v = s.children[e - h];
              if (v) return v[b[o]];
            }
            if (u) return u(e, i);
          }
        }, {
          key: "scrollTo",
          value: function(e) {
            e != null && this.setScroll(this.getSpaceBefore(e));
          }
        }, {
          key: "scrollAround",
          value: function(e) {
            var i = this.getScrollPosition(), s = this.getSpaceBefore(e), n = s - this.props.scrollParentViewportSizeGetter(this) + this.getSizeOfItem(e), o = Math.min(n, s), l = Math.max(n, s);
            if (i <= o) return this.setScroll(o);
            if (i > l) return this.setScroll(l);
          }
        }, {
          key: "getVisibleRange",
          value: function() {
            for (var e = this.state, i = e.from, s = e.size, n = this.getStartAndEnd(0), o = n.start, l = n.end, u = {}, f, c, h = i; h < i + s; ++h) {
              var p = this.getSpaceBefore(h, u), m = p + this.getSizeOfItem(h);
              f == null && m > o && (f = h), f != null && p < l && (c = h);
            }
            return [f, c];
          }
        }, {
          key: "renderItems",
          value: function() {
            for (var e = this, i = this.props, s = i.itemRenderer, n = i.itemsRenderer, o = this.state, l = o.from, u = o.size, f = [], c = 0; c < u; ++c) f.push(s(l + c, c));
            return n(f, function(h) {
              return e.items = h;
            });
          }
        }, {
          key: "render",
          value: function() {
            var e = this, i = this.props, s = i.axis, n = i.length, o = i.type, l = i.useTranslate3d, u = this.state, f = u.from, c = u.itemsPerRow, h = this.renderItems();
            if (o === "simple") return h;
            var p = {
              position: "relative"
            }, m = {}, v = Math.ceil(n / c) * c, y = this.getSpaceBefore(v, m);
            y && (p[te[s]] = y, s === "x" && (p.overflowX = "hidden"));
            var $ = this.getSpaceBefore(f, m), G = s === "x" ? $ : 0, K = s === "y" ? $ : 0, x = l ? "translate3d(".concat(G, "px, ").concat(K, "px, 0)") : "translate(".concat(G, "px, ").concat(K, "px)"), se = {
              msTransform: x,
              WebkitTransform: x,
              transform: x
            };
            return /* @__PURE__ */ (0, P.jsx)("div", {
              style: p,
              ref: function(oe) {
                return e.el = oe;
              },
              children: /* @__PURE__ */ (0, P.jsx)("div", {
                style: se,
                children: h
              })
            });
          }
        }], [{
          key: "getDerivedStateFromProps",
          value: function(e, i) {
            var s = E(e, i);
            return s === i ? null : s;
          }
        }]);
      })(O.Component);
      C(M, "displayName", "ReactList"), C(M, "defaultProps", {
        axis: "y",
        itemRenderer: function(t, r) {
          return /* @__PURE__ */ (0, P.jsx)("div", {
            children: t
          }, r);
        },
        itemsRenderer: function(t, r) {
          return /* @__PURE__ */ (0, P.jsx)("div", {
            ref: r,
            children: t
          });
        },
        length: 0,
        minSize: 1,
        pageSize: 10,
        scrollParentGetter: ae,
        scrollParentViewportSizeGetter: ne,
        threshold: 100,
        type: "simple",
        useStaticSize: !1,
        useTranslate3d: !1
      });
    });
  })(_), _);
}
export {
  ve as __require
};
