import { jsxs as N, jsx as i } from "react/jsx-runtime";
import { classNames as a } from "./index-classNames.js";
import { ComponentContainer as T } from "./index-ComponentContainer.js";
import { ListItem as w } from "./index-ListItem2.js";
import { Text as d } from "./index-Text.js";
import { useRef as L, useState as j, useEffect as A } from "react";
import B from "./index-ListItems.module.scss.js";
const z = (p) => {
  const {
    className: u,
    listClassName: h,
    testId: k = "list-items-testid",
    items: r = [],
    topNote: n,
    bottomNote: l,
    stickyItemStyles: I,
    activeIndex: g,
    stickyIndex: v,
    onHover: S,
    onClick: m,
    hasSidebarPositionCircle: b
  } = p, o = L(null), [x, c] = j("none"), f = (e) => {
    var t;
    for (const C of e) {
      const y = C.getBoundingClientRect(), s = (t = o.current) == null ? void 0 : t.getBoundingClientRect();
      y.top === (s == null ? void 0 : s.top) ? c("top") : y.bottom + 5 > ((s == null ? void 0 : s.bottom) ?? 0) ? c("bottom") : c("none");
    }
  };
  return A(() => {
    var e;
    if (o.current) {
      const t = Array.from(((e = o.current) == null ? void 0 : e.querySelectorAll(".sticky")) ?? []);
      o.current.addEventListener("scroll", () => {
        f(t);
      }), f(t);
    }
  }, [o, r]), N(T, {
    style: {
      height: "100%"
    },
    testId: k,
    className: a(B.container, u),
    children: [typeof n == "string" ? i(d, {
      children: n
    }) : n, i("ul", {
      ref: o,
      style: {
        height: "99%",
        overflow: "scroll",
        overflowX: "hidden",
        position: "relative"
      },
      className: a(h),
      children: r && r.map((e, t) => i(w, {
        idx: t,
        item: e,
        element: e.element,
        hoverable: !!m,
        onHover: S,
        onClick: m,
        scrollIntoView: g === t,
        isSticky: v === t,
        stickyItemStyles: I,
        stickyType: x,
        hasSidebarPositionCircle: b
      }, e.id))
    }), typeof l == "string" ? i(d, {
      children: l
    }) : l]
  });
};
export {
  z as ListItems
};
