import { t as e } from "../chunks/grid-dI94AAbi.js";
import { c as t, h as n } from "../chunks/misc-BYxxlJz6.js";
import r, { Children as i, useMemo as a, useRef as o } from "react";
import { cn as s } from "@ryuzaki13/react-foundation-lib/utils";
import { jsx as c } from "react/jsx-runtime";
import { useFetchNextPageEffect as l } from "@ryuzaki13/react-foundation-lib/virtualizer";
import { useVirtualizer as u } from "@tanstack/react-virtual";
//#region src/list/List.tsx
var d = ({ children: t, className: n }) => i.count(t) === 0 ? /* @__PURE__ */ c("div", {}) : /* @__PURE__ */ c(e.Container, {
	gap: "sm",
	className: s("paddingSm borderBottom", n),
	children: t
}), f = ({ children: t, className: n }) => i.count(t) === 0 ? /* @__PURE__ */ c("div", {}) : /* @__PURE__ */ c(e.Container, {
	gap: "sm",
	className: s("paddingSm borderTop", n),
	children: t
});
function p({ item: e, render: t, separated: n }) {
	return /* @__PURE__ */ c(r.Fragment, { children: /* @__PURE__ */ c("li", {
		className: s(n && "borderBottom"),
		children: t(e)
	}) });
}
function m({ items: e, getKey: n, render: r, separated: i, className: a }) {
	return /* @__PURE__ */ c(t, {
		className: a,
		children: /* @__PURE__ */ c("ul", {
			className: "",
			children: e.map((e, t) => /* @__PURE__ */ c(p, {
				item: e,
				render: r,
				separated: i
			}, n(e, t)))
		})
	});
}
function h({ items: e, getKey: i, render: d, separated: f, className: p, isLoading: m, hasNextPage: h, fetchNextPage: g }) {
	let _ = o(null), v = ((e, t, n) => a(() => ({
		count: t ? e + 1 : e,
		getScrollElement: () => n.current,
		measureElement: (e) => Math.ceil(e.getBoundingClientRect().height),
		estimateSize: () => 120,
		overscan: 5
	}), [
		e,
		t,
		n
	]))(e.length, h, _), y = u(v), b = y.getVirtualItems();
	return l({
		virtualItems: b,
		currentItemsCount: e.length,
		hasNextPage: h,
		fetchNextPage: g
	}), /* @__PURE__ */ c(t, {
		ref: _,
		className: p,
		children: m ? /* @__PURE__ */ c(n, {}) : /* @__PURE__ */ c("ul", {
			style: { height: y.getTotalSize() },
			className: "relative w100",
			children: b.map((t) => {
				let a = t.index > e.length - 1, o = e[t.index];
				return /* @__PURE__ */ c(r.Fragment, { children: /* @__PURE__ */ c("li", {
					ref: y.measureElement,
					style: {
						position: "absolute",
						top: 0,
						left: 0,
						width: "100%",
						transform: `translateY(${Math.round(t.start)}px)`
					},
					"data-index": t.index,
					className: s(f && "borderBottom"),
					children: a ? /* @__PURE__ */ c(n, {}) : d(o)
				}) }, a ? "loader" : i(o, t.index));
			})
		})
	});
}
var g = ({ className: t, children: n }) => /* @__PURE__ */ c(e.Container, {
	templateRows: "auto 1fr auto",
	className: s("h100", t),
	children: n
});
g.Toolbar = d, g.Content = m, g.Footer = f, g.VirtualizedContent = h;
//#endregion
export { g as List };

//# sourceMappingURL=index.js.map