import * as c from "react";
import { P as L, c as R } from "./index-DCcK_d4W.mjs";
import { P as I } from "./index-DDrLXRUs.mjs";
import { c as ne, u as C, b as le } from "./index-DOfn3ixy.mjs";
import { u as A } from "./index-DLcqcWxM.mjs";
import { u as ce } from "./index-ByaXH_ih.mjs";
import { c as se } from "./index-rKs9bXHr.mjs";
import { jsx as b, jsxs as ie, Fragment as ae } from "react/jsx-runtime";
function de(e, t) {
  return c.useReducer((r, l) => t[r][l] ?? r, e);
}
var V = "ScrollArea", [j] = ne(V), [ue, v] = j(V), q = c.forwardRef(
  (e, t) => {
    const {
      __scopeScrollArea: r,
      type: l = "hover",
      dir: o,
      scrollHideDelay: n = 600,
      ...s
    } = e, [i, a] = c.useState(null), [f, d] = c.useState(null), [h, u] = c.useState(null), [S, w] = c.useState(null), [y, M] = c.useState(null), [P, _] = c.useState(0), [U, D] = c.useState(0), [W, x] = c.useState(!1), [H, z] = c.useState(!1), m = A(t, (E) => a(E)), p = ce(o);
    return /* @__PURE__ */ b(
      ue,
      {
        scope: r,
        type: l,
        dir: p,
        scrollHideDelay: n,
        scrollArea: i,
        viewport: f,
        onViewportChange: d,
        content: h,
        onContentChange: u,
        scrollbarX: S,
        onScrollbarXChange: w,
        scrollbarXEnabled: W,
        onScrollbarXEnabledChange: x,
        scrollbarY: y,
        onScrollbarYChange: M,
        scrollbarYEnabled: H,
        onScrollbarYEnabledChange: z,
        onCornerWidthChange: _,
        onCornerHeightChange: D,
        children: /* @__PURE__ */ b(
          L.div,
          {
            dir: p,
            ...s,
            ref: m,
            style: {
              position: "relative",
              // Pass corner sizes as CSS vars to reduce re-renders of context consumers
              "--radix-scroll-area-corner-width": P + "px",
              "--radix-scroll-area-corner-height": U + "px",
              ...e.style
            }
          }
        )
      }
    );
  }
);
q.displayName = V;
var $ = "ScrollAreaViewport", G = c.forwardRef(
  (e, t) => {
    const { __scopeScrollArea: r, children: l, nonce: o, ...n } = e, s = v($, r), i = c.useRef(null), a = A(t, i, s.onViewportChange);
    return /* @__PURE__ */ ie(ae, { children: [
      /* @__PURE__ */ b(
        "style",
        {
          dangerouslySetInnerHTML: {
            __html: "[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"
          },
          nonce: o
        }
      ),
      /* @__PURE__ */ b(
        L.div,
        {
          "data-radix-scroll-area-viewport": "",
          ...n,
          ref: a,
          style: {
            /**
             * We don't support `visible` because the intention is to have at least one scrollbar
             * if this component is used and `visible` will behave like `auto` in that case
             * https://developer.mozilla.org/en-US/docs/Web/CSS/overflow#description
             *
             * We don't handle `auto` because the intention is for the native implementation
             * to be hidden if using this component. We just want to ensure the node is scrollable
             * so could have used either `scroll` or `auto` here. We picked `scroll` to prevent
             * the browser from having to work out whether to render native scrollbars or not,
             * we tell it to with the intention of hiding them in CSS.
             */
            overflowX: s.scrollbarXEnabled ? "scroll" : "hidden",
            overflowY: s.scrollbarYEnabled ? "scroll" : "hidden",
            ...e.style
          },
          children: /* @__PURE__ */ b("div", { ref: s.onContentChange, style: { minWidth: "100%", display: "table" }, children: l })
        }
      )
    ] });
  }
);
G.displayName = $;
var g = "ScrollAreaScrollbar", J = c.forwardRef(
  (e, t) => {
    const { forceMount: r, ...l } = e, o = v(g, e.__scopeScrollArea), { onScrollbarXEnabledChange: n, onScrollbarYEnabledChange: s } = o, i = e.orientation === "horizontal";
    return c.useEffect(() => (i ? n(!0) : s(!0), () => {
      i ? n(!1) : s(!1);
    }), [i, n, s]), o.type === "hover" ? /* @__PURE__ */ b(fe, { ...l, ref: t, forceMount: r }) : o.type === "scroll" ? /* @__PURE__ */ b(he, { ...l, ref: t, forceMount: r }) : o.type === "auto" ? /* @__PURE__ */ b(K, { ...l, ref: t, forceMount: r }) : o.type === "always" ? /* @__PURE__ */ b(k, { ...l, ref: t }) : null;
  }
);
J.displayName = g;
var fe = c.forwardRef((e, t) => {
  const { forceMount: r, ...l } = e, o = v(g, e.__scopeScrollArea), [n, s] = c.useState(!1);
  return c.useEffect(() => {
    const i = o.scrollArea;
    let a = 0;
    if (i) {
      const f = () => {
        window.clearTimeout(a), s(!0);
      }, d = () => {
        a = window.setTimeout(() => s(!1), o.scrollHideDelay);
      };
      return i.addEventListener("pointerenter", f), i.addEventListener("pointerleave", d), () => {
        window.clearTimeout(a), i.removeEventListener("pointerenter", f), i.removeEventListener("pointerleave", d);
      };
    }
  }, [o.scrollArea, o.scrollHideDelay]), /* @__PURE__ */ b(I, { present: r || n, children: /* @__PURE__ */ b(
    K,
    {
      "data-state": n ? "visible" : "hidden",
      ...l,
      ref: t
    }
  ) });
}), he = c.forwardRef((e, t) => {
  const { forceMount: r, ...l } = e, o = v(g, e.__scopeScrollArea), n = e.orientation === "horizontal", s = Y(() => a("SCROLL_END"), 100), [i, a] = de("hidden", {
    hidden: {
      SCROLL: "scrolling"
    },
    scrolling: {
      SCROLL_END: "idle",
      POINTER_ENTER: "interacting"
    },
    interacting: {
      SCROLL: "interacting",
      POINTER_LEAVE: "idle"
    },
    idle: {
      HIDE: "hidden",
      SCROLL: "scrolling",
      POINTER_ENTER: "interacting"
    }
  });
  return c.useEffect(() => {
    if (i === "idle") {
      const f = window.setTimeout(() => a("HIDE"), o.scrollHideDelay);
      return () => window.clearTimeout(f);
    }
  }, [i, o.scrollHideDelay, a]), c.useEffect(() => {
    const f = o.viewport, d = n ? "scrollLeft" : "scrollTop";
    if (f) {
      let h = f[d];
      const u = () => {
        const S = f[d];
        h !== S && (a("SCROLL"), s()), h = S;
      };
      return f.addEventListener("scroll", u), () => f.removeEventListener("scroll", u);
    }
  }, [o.viewport, n, a, s]), /* @__PURE__ */ b(I, { present: r || i !== "hidden", children: /* @__PURE__ */ b(
    k,
    {
      "data-state": i === "hidden" ? "hidden" : "visible",
      ...l,
      ref: t,
      onPointerEnter: R(e.onPointerEnter, () => a("POINTER_ENTER")),
      onPointerLeave: R(e.onPointerLeave, () => a("POINTER_LEAVE"))
    }
  ) });
}), K = c.forwardRef((e, t) => {
  const r = v(g, e.__scopeScrollArea), { forceMount: l, ...o } = e, [n, s] = c.useState(!1), i = e.orientation === "horizontal", a = Y(() => {
    if (r.viewport) {
      const f = r.viewport.offsetWidth < r.viewport.scrollWidth, d = r.viewport.offsetHeight < r.viewport.scrollHeight;
      s(i ? f : d);
    }
  }, 10);
  return T(r.viewport, a), T(r.content, a), /* @__PURE__ */ b(I, { present: l || n, children: /* @__PURE__ */ b(
    k,
    {
      "data-state": n ? "visible" : "hidden",
      ...o,
      ref: t
    }
  ) });
}), k = c.forwardRef((e, t) => {
  const { orientation: r = "vertical", ...l } = e, o = v(g, e.__scopeScrollArea), n = c.useRef(null), s = c.useRef(0), [i, a] = c.useState({
    content: 0,
    viewport: 0,
    scrollbar: { size: 0, paddingStart: 0, paddingEnd: 0 }
  }), f = re(i.viewport, i.content), d = {
    ...l,
    sizes: i,
    onSizesChange: a,
    hasThumb: f > 0 && f < 1,
    onThumbChange: (u) => n.current = u,
    onThumbPointerUp: () => s.current = 0,
    onThumbPointerDown: (u) => s.current = u
  };
  function h(u, S) {
    return ge(u, s.current, i, S);
  }
  return r === "horizontal" ? /* @__PURE__ */ b(
    be,
    {
      ...d,
      ref: t,
      onThumbPositionChange: () => {
        if (o.viewport && n.current) {
          const u = o.viewport.scrollLeft, S = F(u, i, o.dir);
          n.current.style.transform = `translate3d(${S}px, 0, 0)`;
        }
      },
      onWheelScroll: (u) => {
        o.viewport && (o.viewport.scrollLeft = u);
      },
      onDragScroll: (u) => {
        o.viewport && (o.viewport.scrollLeft = h(u, o.dir));
      }
    }
  ) : r === "vertical" ? /* @__PURE__ */ b(
    Se,
    {
      ...d,
      ref: t,
      onThumbPositionChange: () => {
        if (o.viewport && n.current) {
          const u = o.viewport.scrollTop, S = F(u, i);
          n.current.style.transform = `translate3d(0, ${S}px, 0)`;
        }
      },
      onWheelScroll: (u) => {
        o.viewport && (o.viewport.scrollTop = u);
      },
      onDragScroll: (u) => {
        o.viewport && (o.viewport.scrollTop = h(u));
      }
    }
  ) : null;
}), be = c.forwardRef((e, t) => {
  const { sizes: r, onSizesChange: l, ...o } = e, n = v(g, e.__scopeScrollArea), [s, i] = c.useState(), a = c.useRef(null), f = A(t, a, n.onScrollbarXChange);
  return c.useEffect(() => {
    a.current && i(getComputedStyle(a.current));
  }, [a]), /* @__PURE__ */ b(
    Z,
    {
      "data-orientation": "horizontal",
      ...o,
      ref: f,
      sizes: r,
      style: {
        bottom: 0,
        left: n.dir === "rtl" ? "var(--radix-scroll-area-corner-width)" : 0,
        right: n.dir === "ltr" ? "var(--radix-scroll-area-corner-width)" : 0,
        "--radix-scroll-area-thumb-width": X(r) + "px",
        ...e.style
      },
      onThumbPointerDown: (d) => e.onThumbPointerDown(d.x),
      onDragScroll: (d) => e.onDragScroll(d.x),
      onWheelScroll: (d, h) => {
        if (n.viewport) {
          const u = n.viewport.scrollLeft + d.deltaX;
          e.onWheelScroll(u), te(u, h) && d.preventDefault();
        }
      },
      onResize: () => {
        a.current && n.viewport && s && l({
          content: n.viewport.scrollWidth,
          viewport: n.viewport.offsetWidth,
          scrollbar: {
            size: a.current.clientWidth,
            paddingStart: O(s.paddingLeft),
            paddingEnd: O(s.paddingRight)
          }
        });
      }
    }
  );
}), Se = c.forwardRef((e, t) => {
  const { sizes: r, onSizesChange: l, ...o } = e, n = v(g, e.__scopeScrollArea), [s, i] = c.useState(), a = c.useRef(null), f = A(t, a, n.onScrollbarYChange);
  return c.useEffect(() => {
    a.current && i(getComputedStyle(a.current));
  }, [a]), /* @__PURE__ */ b(
    Z,
    {
      "data-orientation": "vertical",
      ...o,
      ref: f,
      sizes: r,
      style: {
        top: 0,
        right: n.dir === "ltr" ? 0 : void 0,
        left: n.dir === "rtl" ? 0 : void 0,
        bottom: "var(--radix-scroll-area-corner-height)",
        "--radix-scroll-area-thumb-height": X(r) + "px",
        ...e.style
      },
      onThumbPointerDown: (d) => e.onThumbPointerDown(d.y),
      onDragScroll: (d) => e.onDragScroll(d.y),
      onWheelScroll: (d, h) => {
        if (n.viewport) {
          const u = n.viewport.scrollTop + d.deltaY;
          e.onWheelScroll(u), te(u, h) && d.preventDefault();
        }
      },
      onResize: () => {
        a.current && n.viewport && s && l({
          content: n.viewport.scrollHeight,
          viewport: n.viewport.offsetHeight,
          scrollbar: {
            size: a.current.clientHeight,
            paddingStart: O(s.paddingTop),
            paddingEnd: O(s.paddingBottom)
          }
        });
      }
    }
  );
}), [me, Q] = j(g), Z = c.forwardRef((e, t) => {
  const {
    __scopeScrollArea: r,
    sizes: l,
    hasThumb: o,
    onThumbChange: n,
    onThumbPointerUp: s,
    onThumbPointerDown: i,
    onThumbPositionChange: a,
    onDragScroll: f,
    onWheelScroll: d,
    onResize: h,
    ...u
  } = e, S = v(g, r), [w, y] = c.useState(null), M = A(t, (m) => y(m)), P = c.useRef(null), _ = c.useRef(""), U = S.viewport, D = l.content - l.viewport, W = C(d), x = C(a), H = Y(h, 10);
  function z(m) {
    if (P.current) {
      const p = m.clientX - P.current.left, E = m.clientY - P.current.top;
      f({ x: p, y: E });
    }
  }
  return c.useEffect(() => {
    const m = (p) => {
      const E = p.target;
      w?.contains(E) && W(p, D);
    };
    return document.addEventListener("wheel", m, { passive: !1 }), () => document.removeEventListener("wheel", m, { passive: !1 });
  }, [U, w, D, W]), c.useEffect(x, [l, x]), T(w, H), T(S.content, H), /* @__PURE__ */ b(
    me,
    {
      scope: r,
      scrollbar: w,
      hasThumb: o,
      onThumbChange: C(n),
      onThumbPointerUp: C(s),
      onThumbPositionChange: x,
      onThumbPointerDown: C(i),
      children: /* @__PURE__ */ b(
        L.div,
        {
          ...u,
          ref: M,
          style: { position: "absolute", ...u.style },
          onPointerDown: R(e.onPointerDown, (m) => {
            m.button === 0 && (m.target.setPointerCapture(m.pointerId), P.current = w.getBoundingClientRect(), _.current = document.body.style.webkitUserSelect, document.body.style.webkitUserSelect = "none", S.viewport && (S.viewport.style.scrollBehavior = "auto"), z(m));
          }),
          onPointerMove: R(e.onPointerMove, z),
          onPointerUp: R(e.onPointerUp, (m) => {
            const p = m.target;
            p.hasPointerCapture(m.pointerId) && p.releasePointerCapture(m.pointerId), document.body.style.webkitUserSelect = _.current, S.viewport && (S.viewport.style.scrollBehavior = ""), P.current = null;
          })
        }
      )
    }
  );
}), N = "ScrollAreaThumb", ee = c.forwardRef(
  (e, t) => {
    const { forceMount: r, ...l } = e, o = Q(N, e.__scopeScrollArea);
    return /* @__PURE__ */ b(I, { present: r || o.hasThumb, children: /* @__PURE__ */ b(ve, { ref: t, ...l }) });
  }
), ve = c.forwardRef(
  (e, t) => {
    const { __scopeScrollArea: r, style: l, ...o } = e, n = v(N, r), s = Q(N, r), { onThumbPositionChange: i } = s, a = A(
      t,
      (h) => s.onThumbChange(h)
    ), f = c.useRef(void 0), d = Y(() => {
      f.current && (f.current(), f.current = void 0);
    }, 100);
    return c.useEffect(() => {
      const h = n.viewport;
      if (h) {
        const u = () => {
          if (d(), !f.current) {
            const S = Pe(h, i);
            f.current = S, i();
          }
        };
        return i(), h.addEventListener("scroll", u), () => h.removeEventListener("scroll", u);
      }
    }, [n.viewport, d, i]), /* @__PURE__ */ b(
      L.div,
      {
        "data-state": s.hasThumb ? "visible" : "hidden",
        ...o,
        ref: a,
        style: {
          width: "var(--radix-scroll-area-thumb-width)",
          height: "var(--radix-scroll-area-thumb-height)",
          ...l
        },
        onPointerDownCapture: R(e.onPointerDownCapture, (h) => {
          const S = h.target.getBoundingClientRect(), w = h.clientX - S.left, y = h.clientY - S.top;
          s.onThumbPointerDown({ x: w, y });
        }),
        onPointerUp: R(e.onPointerUp, s.onThumbPointerUp)
      }
    );
  }
);
ee.displayName = N;
var B = "ScrollAreaCorner", pe = c.forwardRef(
  (e, t) => {
    const r = v(B, e.__scopeScrollArea), l = !!(r.scrollbarX && r.scrollbarY);
    return r.type !== "scroll" && l ? /* @__PURE__ */ b(we, { ...e, ref: t }) : null;
  }
);
pe.displayName = B;
var we = c.forwardRef((e, t) => {
  const { __scopeScrollArea: r, ...l } = e, o = v(B, r), [n, s] = c.useState(0), [i, a] = c.useState(0), f = !!(n && i);
  return T(o.scrollbarX, () => {
    const d = o.scrollbarX?.offsetHeight || 0;
    o.onCornerHeightChange(d), a(d);
  }), T(o.scrollbarY, () => {
    const d = o.scrollbarY?.offsetWidth || 0;
    o.onCornerWidthChange(d), s(d);
  }), f ? /* @__PURE__ */ b(
    L.div,
    {
      ...l,
      ref: t,
      style: {
        width: n,
        height: i,
        position: "absolute",
        right: o.dir === "ltr" ? 0 : void 0,
        left: o.dir === "rtl" ? 0 : void 0,
        bottom: 0,
        ...e.style
      }
    }
  ) : null;
});
function O(e) {
  return e ? parseInt(e, 10) : 0;
}
function re(e, t) {
  const r = e / t;
  return isNaN(r) ? 0 : r;
}
function X(e) {
  const t = re(e.viewport, e.content), r = e.scrollbar.paddingStart + e.scrollbar.paddingEnd, l = (e.scrollbar.size - r) * t;
  return Math.max(l, 18);
}
function ge(e, t, r, l = "ltr") {
  const o = X(r), n = o / 2, s = t || n, i = o - s, a = r.scrollbar.paddingStart + s, f = r.scrollbar.size - r.scrollbar.paddingEnd - i, d = r.content - r.viewport, h = l === "ltr" ? [0, d] : [d * -1, 0];
  return oe([a, f], h)(e);
}
function F(e, t, r = "ltr") {
  const l = X(t), o = t.scrollbar.paddingStart + t.scrollbar.paddingEnd, n = t.scrollbar.size - o, s = t.content - t.viewport, i = n - l, a = r === "ltr" ? [0, s] : [s * -1, 0], f = se(e, a);
  return oe([0, s], [0, i])(f);
}
function oe(e, t) {
  return (r) => {
    if (e[0] === e[1] || t[0] === t[1]) return t[0];
    const l = (t[1] - t[0]) / (e[1] - e[0]);
    return t[0] + l * (r - e[0]);
  };
}
function te(e, t) {
  return e > 0 && e < t;
}
var Pe = (e, t = () => {
}) => {
  let r = { left: e.scrollLeft, top: e.scrollTop }, l = 0;
  return (function o() {
    const n = { left: e.scrollLeft, top: e.scrollTop }, s = r.left !== n.left, i = r.top !== n.top;
    (s || i) && t(), r = n, l = window.requestAnimationFrame(o);
  })(), () => window.cancelAnimationFrame(l);
};
function Y(e, t) {
  const r = C(e), l = c.useRef(0);
  return c.useEffect(() => () => window.clearTimeout(l.current), []), c.useCallback(() => {
    window.clearTimeout(l.current), l.current = window.setTimeout(r, t);
  }, [r, t]);
}
function T(e, t) {
  const r = C(t);
  le(() => {
    let l = 0;
    if (e) {
      const o = new ResizeObserver(() => {
        cancelAnimationFrame(l), l = window.requestAnimationFrame(r);
      });
      return o.observe(e), () => {
        window.cancelAnimationFrame(l), o.unobserve(e);
      };
    }
  }, [e, r]);
}
var _e = q, De = G, We = J, He = ee;
export {
  _e as R,
  We as S,
  He as T,
  De as V
};
//# sourceMappingURL=index-B8Mazo6u.mjs.map
