"use client";
import { jsx } from "react/jsx-runtime";
import { createContext, useRef, useState, useMemo, useLayoutEffect, useEffect, useCallback, useId, useImperativeHandle, useContext } from "react";
function z(e, t = "Assertion error") {
  if (!e)
    throw Error(t);
}
function W({
  group: e
}) {
  const { orientation: t, panels: n } = e;
  return n.reduce((o, i) => (o += t === "horizontal" ? i.element.offsetWidth : i.element.offsetHeight, o), 0);
}
function ae(e, t) {
  return t.sort(
    e === "horizontal" ? Qe : et
  );
}
function Qe(e, t) {
  const n = e.element.offsetLeft - t.element.offsetLeft;
  return n !== 0 ? n : e.element.offsetWidth - t.element.offsetWidth;
}
function et(e, t) {
  const n = e.element.offsetTop - t.element.offsetTop;
  return n !== 0 ? n : e.element.offsetHeight - t.element.offsetHeight;
}
function Me(e) {
  return e !== null && typeof e == "object" && "nodeType" in e && e.nodeType === Node.ELEMENT_NODE;
}
function Ie(e, t) {
  return {
    x: e.x >= t.left && e.x <= t.right ? 0 : Math.min(
      Math.abs(e.x - t.left),
      Math.abs(e.x - t.right)
    ),
    y: e.y >= t.top && e.y <= t.bottom ? 0 : Math.min(
      Math.abs(e.y - t.top),
      Math.abs(e.y - t.bottom)
    )
  };
}
function tt({
  orientation: e,
  rects: t,
  targetRect: n
}) {
  const o = {
    x: n.x + n.width / 2,
    y: n.y + n.height / 2
  };
  let i, s = Number.MAX_VALUE;
  for (const l of t) {
    const { x: r, y: a } = Ie(o, l), u = e === "horizontal" ? r : a;
    u < s && (s = u, i = l);
  }
  return z(i, "No rect found"), i;
}
function ke(e) {
  const { element: t, orientation: n, panels: o, separators: i } = e, s = ae(
    n,
    Array.from(t.children).filter(Me).map((f) => ({ element: f }))
  ).map(({ element: f }) => f), l = [];
  let r = false, a, u = [];
  for (const f of s)
    if (f.hasAttribute("data-panel")) {
      const p = o.find(
        (h) => h.element === f
      );
      if (p) {
        if (a) {
          const h = a.element.getBoundingClientRect(), m = f.getBoundingClientRect();
          let c;
          if (r) {
            const d = n === "horizontal" ? new DOMRect(h.right, h.top, 0, h.height) : new DOMRect(
              h.left,
              h.bottom,
              h.width,
              0
            ), y = n === "horizontal" ? new DOMRect(m.left, m.top, 0, m.height) : new DOMRect(m.left, m.top, m.width, 0);
            switch (u.length) {
              case 0: {
                c = [
                  d,
                  y
                ];
                break;
              }
              case 1: {
                const v = u[0], S = tt({
                  orientation: n,
                  rects: [h, m],
                  targetRect: v.element.getBoundingClientRect()
                });
                c = [
                  v,
                  S === h ? y : d
                ];
                break;
              }
              default: {
                c = u;
                break;
              }
            }
          } else
            u.length ? c = u : c = [
              n === "horizontal" ? new DOMRect(
                h.right,
                m.top,
                m.left - h.right,
                m.height
              ) : new DOMRect(
                m.left,
                h.bottom,
                m.width,
                m.top - h.bottom
              )
            ];
          for (const d of c)
            l.push({
              group: e,
              groupSize: W({ group: e }),
              panels: [a, p],
              separator: "width" in d ? void 0 : d,
              rect: "width" in d ? d : d.element.getBoundingClientRect()
            });
        }
        r = false, a = p, u = [];
      }
    } else if (f.hasAttribute("data-separator")) {
      const p = i.find(
        (h) => h.element === f
      );
      p ? u.push(p) : (a = void 0, u = []);
    } else
      r = true;
  return l;
}
function nt(e, t) {
  const n = getComputedStyle(e), o = parseFloat(n.fontSize);
  return t * o;
}
function ot(e, t) {
  const n = getComputedStyle(e.ownerDocument.body), o = parseFloat(n.fontSize);
  return t * o;
}
function rt(e) {
  return e / 100 * window.innerHeight;
}
function it(e) {
  return e / 100 * window.innerWidth;
}
function st(e) {
  switch (typeof e) {
    case "number":
      return [e, "px"];
    case "string": {
      const t = parseFloat(e);
      return e.endsWith("%") ? [t, "%"] : e.endsWith("px") ? [t, "px"] : e.endsWith("rem") ? [t, "rem"] : e.endsWith("em") ? [t, "em"] : e.endsWith("vh") ? [t, "vh"] : e.endsWith("vw") ? [t, "vw"] : [t, "%"];
    }
  }
}
function ee({
  groupSize: e,
  panelElement: t,
  styleProp: n
}) {
  let o;
  const [i, s] = st(n);
  switch (s) {
    case "%": {
      o = i / 100 * e;
      break;
    }
    case "px": {
      o = i;
      break;
    }
    case "rem": {
      o = ot(t, i);
      break;
    }
    case "em": {
      o = nt(t, i);
      break;
    }
    case "vh": {
      o = rt(i);
      break;
    }
    case "vw": {
      o = it(i);
      break;
    }
  }
  return o;
}
function k(e) {
  return parseFloat(e.toFixed(3));
}
function me(e) {
  const { panels: t } = e, n = W({ group: e });
  return n === 0 ? t.map((o) => ({
    collapsedSize: 0,
    collapsible: o.panelConstraints.collapsible === true,
    defaultSize: void 0,
    minSize: 0,
    maxSize: 100,
    panelId: o.id
  })) : t.map((o) => {
    const { element: i, panelConstraints: s } = o;
    let l = 0;
    if (s.collapsedSize) {
      const f = ee({
        groupSize: n,
        panelElement: i,
        styleProp: s.collapsedSize
      });
      l = k(f / n * 100);
    }
    let r;
    if (s.defaultSize) {
      const f = ee({
        groupSize: n,
        panelElement: i,
        styleProp: s.defaultSize
      });
      r = k(f / n * 100);
    }
    let a = 0;
    if (s.minSize) {
      const f = ee({
        groupSize: n,
        panelElement: i,
        styleProp: s.minSize
      });
      a = k(f / n * 100);
    }
    let u = 100;
    if (s.maxSize) {
      const f = ee({
        groupSize: n,
        panelElement: i,
        styleProp: s.maxSize
      });
      u = k(f / n * 100);
    }
    return {
      collapsedSize: l,
      collapsible: s.collapsible === true,
      defaultSize: r,
      minSize: a,
      maxSize: u,
      panelId: o.id
    };
  });
}
class at {
  #e = {};
  addListener(t, n) {
    const o = this.#e[t];
    return o === void 0 ? this.#e[t] = [n] : o.includes(n) || o.push(n), () => {
      this.removeListener(t, n);
    };
  }
  emit(t, n) {
    const o = this.#e[t];
    if (o !== void 0)
      if (o.length === 1)
        o[0].call(null, n);
      else {
        let i = false, s = null;
        const l = Array.from(o);
        for (let r = 0; r < l.length; r++) {
          const a = l[r];
          try {
            a.call(null, n);
          } catch (u) {
            s === null && (i = true, s = u);
          }
        }
        if (i)
          throw s;
      }
  }
  removeAllListeners() {
    this.#e = {};
  }
  removeListener(t, n) {
    const o = this.#e[t];
    if (o !== void 0) {
      const i = o.indexOf(n);
      i >= 0 && o.splice(i, 1);
    }
  }
}
function R(e, t, n = 0) {
  return Math.abs(k(e) - k(t)) <= n;
}
let E = {
  cursorFlags: 0,
  interactionState: {
    state: "inactive"
  },
  mountedGroups: /* @__PURE__ */ new Map()
};
const _ = new at();
function G() {
  return E;
}
function M(e) {
  const t = typeof e == "function" ? e(E) : e;
  if (E === t)
    return E;
  const n = E;
  return E = {
    ...E,
    ...t
  }, t.cursorFlags !== void 0 && _.emit("cursorFlagsChange", E.cursorFlags), t.interactionState !== void 0 && _.emit("interactionStateChange", E.interactionState), t.mountedGroups !== void 0 && (E.mountedGroups.forEach((o, i) => {
    o.derivedPanelConstraints.forEach((s) => {
      if (s.collapsible) {
        const { layout: l } = n.mountedGroups.get(i) ?? {};
        if (l) {
          const r = R(
            s.collapsedSize,
            o.layout[s.panelId]
          ), a = R(
            s.collapsedSize,
            l[s.panelId]
          );
          r && !a && (i.inMemoryLastExpandedPanelSizes[s.panelId] = l[s.panelId]);
        }
      }
    });
  }), _.emit("mountedGroupsChange", E.mountedGroups)), E;
}
function lt(e, t) {
  if (e.length !== t.length)
    return false;
  for (let n = 0; n < e.length; n++)
    if (e[n] != t[n])
      return false;
  return true;
}
function X(e, t) {
  return R(e, t) ? 0 : e > t ? 1 : -1;
}
function V({
  panelConstraints: e,
  size: t
}) {
  const {
    collapsedSize: n = 0,
    collapsible: o,
    maxSize: i = 100,
    minSize: s = 0
  } = e;
  if (X(t, s) < 0)
    if (o) {
      const l = (n + s) / 2;
      X(t, l) < 0 ? t = n : t = s;
    } else
      t = s;
  return t = Math.min(i, t), t = k(t), t;
}
function q({
  delta: e,
  initialLayout: t,
  panelConstraints: n,
  pivotIndices: o,
  prevLayout: i,
  trigger: s
}) {
  if (R(e, 0))
    return t;
  const l = Object.values(t), r = Object.values(i), a = [...l], [u, f] = o;
  z(u != null, "Invalid first pivot index"), z(f != null, "Invalid second pivot index");
  let p = 0;
  if (s === "keyboard") {
    {
      const c = e < 0 ? f : u, d = n[c];
      z(
        d,
        `Panel constraints not found for index ${c}`
      );
      const {
        collapsedSize: y = 0,
        collapsible: v,
        minSize: S = 0
      } = d;
      if (v) {
        const x = l[c];
        if (z(
          x != null,
          `Previous layout not found for panel index ${c}`
        ), R(x, y)) {
          const g = S - x;
          X(g, Math.abs(e)) > 0 && (e = e < 0 ? 0 - g : g);
        }
      }
    }
    {
      const c = e < 0 ? u : f, d = n[c];
      z(
        d,
        `No panel constraints found for index ${c}`
      );
      const {
        collapsedSize: y = 0,
        collapsible: v,
        minSize: S = 0
      } = d;
      if (v) {
        const x = l[c];
        if (z(
          x != null,
          `Previous layout not found for panel index ${c}`
        ), R(x, S)) {
          const g = x - y;
          X(g, Math.abs(e)) > 0 && (e = e < 0 ? 0 - g : g);
        }
      }
    }
  }
  {
    const c = e < 0 ? 1 : -1;
    let d = e < 0 ? f : u, y = 0;
    for (; ; ) {
      const S = l[d];
      z(
        S != null,
        `Previous layout not found for panel index ${d}`
      );
      const g = V({
        panelConstraints: n[d],
        size: 100
      }) - S;
      if (y += g, d += c, d < 0 || d >= n.length)
        break;
    }
    const v = Math.min(Math.abs(e), Math.abs(y));
    e = e < 0 ? 0 - v : v;
  }
  {
    let d = e < 0 ? u : f;
    for (; d >= 0 && d < n.length; ) {
      const y = Math.abs(e) - Math.abs(p), v = l[d];
      z(
        v != null,
        `Previous layout not found for panel index ${d}`
      );
      const S = v - y, x = V({
        panelConstraints: n[d],
        size: S
      });
      if (!R(v, x) && (p += v - x, a[d] = x, p.toFixed(3).localeCompare(Math.abs(e).toFixed(3), void 0, {
        numeric: true
      }) >= 0))
        break;
      e < 0 ? d-- : d++;
    }
  }
  if (lt(r, a))
    return i;
  {
    const c = e < 0 ? f : u, d = l[c];
    z(
      d != null,
      `Previous layout not found for panel index ${c}`
    );
    const y = d + p, v = V({
      panelConstraints: n[c],
      size: y
    });
    if (a[c] = v, !R(v, y)) {
      let S = y - v, g = e < 0 ? f : u;
      for (; g >= 0 && g < n.length; ) {
        const b = a[g];
        z(
          b != null,
          `Previous layout not found for panel index ${g}`
        );
        const w = b + S, C = V({
          panelConstraints: n[g],
          size: w
        });
        if (R(b, C) || (S -= C - b, a[g] = C), R(S, 0))
          break;
        e > 0 ? g-- : g++;
      }
    }
  }
  const h = Object.values(a).reduce(
    (c, d) => d + c,
    0
  );
  if (!R(h, 100, 0.1))
    return i;
  const m = Object.keys(i);
  return a.reduce((c, d, y) => (c[m[y]] = d, c), {});
}
function ne(e) {
  const t = e.parentElement;
  z(t, "Parent group element not found");
  const { mountedGroups: n } = G();
  for (const [o] of n)
    if (o.element === t)
      return o;
  throw Error("Could not find parent Group for separator element");
}
function U(e, t) {
  if (Object.keys(e).length !== Object.keys(t).length)
    return false;
  for (const n in e)
    if (t[n] === void 0 || X(e[n], t[n]) !== 0)
      return false;
  return true;
}
function N({
  layout: e,
  panelConstraints: t
}) {
  const o = [...Object.values(e)], i = o.reduce(
    (r, a) => r + a,
    0
  );
  if (o.length !== t.length)
    throw Error(
      `Invalid ${t.length} panel layout: ${o.map((r) => `${r}%`).join(", ")}`
    );
  if (!R(i, 100) && o.length > 0)
    for (let r = 0; r < t.length; r++) {
      const a = o[r];
      z(a != null, `No layout data found for index ${r}`);
      const u = 100 / i * a;
      o[r] = u;
    }
  let s = 0;
  for (let r = 0; r < t.length; r++) {
    const a = o[r];
    z(a != null, `No layout data found for index ${r}`);
    const u = V({
      panelConstraints: t[r],
      size: a
    });
    a != u && (s += a - u, o[r] = u);
  }
  if (!R(s, 0))
    for (let r = 0; r < t.length; r++) {
      const a = o[r];
      z(a != null, `No layout data found for index ${r}`);
      const u = a + s, f = V({
        panelConstraints: t[r],
        size: u
      });
      if (a !== f && (s -= f - a, o[r] = f, R(s, 0)))
        break;
    }
  const l = Object.keys(e);
  return o.reduce((r, a, u) => (r[l[u]] = a, r), {});
}
function Ge({
  groupId: e
}) {
  const t = () => {
    const { mountedGroups: n } = G();
    for (const [o, i] of n)
      if (o.id === e)
        return { group: o, ...i };
    throw Error(`Could not find Group with id "${e}"`);
  };
  return {
    getLayout() {
      const { defaultLayoutDeferred: n, layout: o } = t();
      return n ? {} : o;
    },
    setLayout(n) {
      const {
        defaultLayoutDeferred: o,
        derivedPanelConstraints: i,
        group: s,
        layout: l,
        separatorToPanels: r
      } = t(), a = N({
        layout: n,
        panelConstraints: i
      });
      return o ? l : (U(l, a) || M((u) => ({
        mountedGroups: new Map(u.mountedGroups).set(s, {
          defaultLayoutDeferred: o,
          derivedPanelConstraints: i,
          layout: a,
          separatorToPanels: r
        })
      })), a);
    }
  };
}
function De(e) {
  const { mountedGroups: t } = G(), n = t.get(e);
  return z(n, `Mounted Group ${e.id} not found`), n;
}
function T(e, t) {
  const n = ne(e), o = De(n), i = n.separators.find(
    (p) => p.element === e
  );
  z(i, "Matching separator not found");
  const s = o.separatorToPanels.get(i);
  z(s, "Matching panels not found");
  const l = s.map((p) => n.panels.indexOf(p)), a = Ge({ groupId: n.id }).getLayout(), u = q({
    delta: t,
    initialLayout: a,
    panelConstraints: o.derivedPanelConstraints,
    pivotIndices: l,
    prevLayout: a,
    trigger: "keyboard"
  }), f = N({
    layout: u,
    panelConstraints: o.derivedPanelConstraints
  });
  U(a, f) || M((p) => ({
    mountedGroups: new Map(p.mountedGroups).set(n, {
      defaultLayoutDeferred: o.defaultLayoutDeferred,
      derivedPanelConstraints: o.derivedPanelConstraints,
      layout: f,
      separatorToPanels: o.separatorToPanels
    })
  }));
}
function ye(e) {
  if (e.defaultPrevented)
    return;
  const t = e.currentTarget, n = ne(t);
  if (!n.disabled)
    switch (e.key) {
      case "ArrowDown": {
        e.preventDefault(), n.orientation === "vertical" && T(t, 5);
        break;
      }
      case "ArrowLeft": {
        e.preventDefault(), n.orientation === "horizontal" && T(t, -5);
        break;
      }
      case "ArrowRight": {
        e.preventDefault(), n.orientation === "horizontal" && T(t, 5);
        break;
      }
      case "ArrowUp": {
        e.preventDefault(), n.orientation === "vertical" && T(t, -5);
        break;
      }
      case "End": {
        e.preventDefault(), T(t, 100);
        break;
      }
      case "Enter": {
        e.preventDefault();
        const o = ne(t), { derivedPanelConstraints: i, layout: s, separatorToPanels: l } = De(o), r = o.separators.find(
          (p) => p.element === t
        );
        z(r, "Matching separator not found");
        const a = l.get(r);
        z(a, "Matching panels not found");
        const u = a[0], f = i.find(
          (p) => p.panelId === u.id
        );
        if (z(f, "Panel metadata not found"), f.collapsible) {
          const p = s[u.id], h = f.collapsedSize === p ? o.inMemoryLastExpandedPanelSizes[u.id] ?? f.minSize : f.collapsedSize;
          T(t, h - p);
        }
        break;
      }
      case "F6": {
        e.preventDefault();
        const i = ne(t).separators.map(
          (a) => a.element
        ), s = Array.from(i).findIndex(
          (a) => a === e.currentTarget
        );
        z(s !== null, "Index not found");
        const l = e.shiftKey ? s > 0 ? s - 1 : i.length - 1 : s + 1 < i.length ? s + 1 : 0;
        i[l].focus();
        break;
      }
      case "Home": {
        e.preventDefault(), T(t, -100);
        break;
      }
    }
}
const ut = (e) => e, re = () => {
}, Oe = 1, Te = 2, _e = 4, Ne = 8, ge = {
  coarse: 10,
  precise: 5
};
function ct(e, t, n) {
  let o, i = {
    x: 1 / 0,
    y: 1 / 0
  };
  for (const s of t) {
    const l = Ie(n, s.rect);
    switch (e) {
      case "horizontal": {
        l.x <= i.x && (o = s, i = l);
        break;
      }
      case "vertical": {
        l.y <= i.y && (o = s, i = l);
        break;
      }
    }
  }
  return o ? {
    distance: i,
    hitRegion: o
  } : void 0;
}
let te;
function ft() {
  return te === void 0 && (typeof matchMedia == "function" ? te = !!matchMedia("(pointer:coarse)").matches : te = false), te;
}
function dt(e) {
  return e !== null && typeof e == "object" && "nodeType" in e && e.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
}
function pt(e, t) {
  if (e === t) throw new Error("Cannot compare node with itself");
  const n = {
    a: xe(e),
    b: xe(t)
  };
  let o;
  for (; n.a.at(-1) === n.b.at(-1); )
    e = n.a.pop(), t = n.b.pop(), o = e;
  z(
    o,
    "Stacking order can only be calculated for elements with a common ancestor"
  );
  const i = {
    a: Se(ve(n.a)),
    b: Se(ve(n.b))
  };
  if (i.a === i.b) {
    const s = o.childNodes, l = {
      a: n.a.at(-1),
      b: n.b.at(-1)
    };
    let r = s.length;
    for (; r--; ) {
      const a = s[r];
      if (a === l.a) return 1;
      if (a === l.b) return -1;
    }
  }
  return Math.sign(i.a - i.b);
}
const ht = /\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;
function mt(e) {
  const t = getComputedStyle(Ae(e) ?? e).display;
  return t === "flex" || t === "inline-flex";
}
function yt(e) {
  const t = getComputedStyle(e);
  return !!(t.position === "fixed" || t.zIndex !== "auto" && (t.position !== "static" || mt(e)) || +t.opacity < 1 || "transform" in t && t.transform !== "none" || "webkitTransform" in t && t.webkitTransform !== "none" || "mixBlendMode" in t && t.mixBlendMode !== "normal" || "filter" in t && t.filter !== "none" || "webkitFilter" in t && t.webkitFilter !== "none" || "isolation" in t && t.isolation === "isolate" || ht.test(t.willChange) || t.webkitOverflowScrolling === "touch");
}
function ve(e) {
  let t = e.length;
  for (; t--; ) {
    const n = e[t];
    if (z(n, "Missing node"), yt(n)) return n;
  }
  return null;
}
function Se(e) {
  return e && Number(getComputedStyle(e).zIndex) || 0;
}
function xe(e) {
  const t = [];
  for (; e; )
    t.push(e), e = Ae(e);
  return t;
}
function Ae(e) {
  const { parentNode: t } = e;
  return dt(t) ? t.host : t;
}
function gt(e, t) {
  return e.x < t.x + t.width && e.x + e.width > t.x && e.y < t.y + t.height && e.y + e.height > t.y;
}
function vt({
  groupElement: e,
  hitRegion: t,
  pointerEventTarget: n
}) {
  if (!Me(n) || n.contains(e) || e.contains(n))
    return true;
  if (pt(n, e) > 0) {
    let o = n;
    for (; o; ) {
      if (o.contains(e))
        return true;
      if (gt(o.getBoundingClientRect(), t))
        return false;
      o = o.parentElement;
    }
  }
  return true;
}
function $e(e, t) {
  const n = [];
  return t.forEach((o, i) => {
    if (i.disabled)
      return;
    const s = ft() ? ge.coarse : ge.precise, l = ke(i), r = ct(i.orientation, l, {
      x: e.clientX,
      y: e.clientY
    });
    r && r.distance.x <= s && r.distance.y <= s && vt({
      groupElement: i.element,
      hitRegion: r.hitRegion.rect,
      pointerEventTarget: e.target
    }) && n.push(r.hitRegion);
  }), n;
}
function ze(e) {
  if (e.defaultPrevented)
    return;
  const { mountedGroups: t } = G(), n = $e(e, t), o = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Map();
  let r = false;
  n.forEach((a) => {
    o.add(a.group), a.panels.forEach((f) => {
      i.add(f);
    }), a.separator && (s.add(a.separator), r || (r = true, a.separator.element.focus()));
    const u = t.get(a.group);
    u && l.set(a.group, u.layout);
  }), M({
    interactionState: {
      hitRegions: n,
      initialLayoutMap: l,
      pointerDownAtPoint: { x: e.clientX, y: e.clientY },
      state: "active"
    }
  }), n.length && e.preventDefault();
}
function St({
  cursorFlags: e,
  groups: t,
  state: n
}) {
  let o = 0, i = 0;
  switch (n) {
    case "active":
    case "hover":
      t.forEach((s) => {
        if (!s.disableCursor)
          switch (s.orientation) {
            case "horizontal": {
              o++;
              break;
            }
            case "vertical": {
              i++;
              break;
            }
          }
      });
  }
  if (o === 0 && i === 0)
    return null;
  switch (n) {
    case "active": {
      const s = (e & Oe) !== 0, l = (e & Te) !== 0, r = (e & _e) !== 0, a = (e & Ne) !== 0;
      if (e) {
        if (s)
          return r ? "se-resize" : a ? "ne-resize" : "e-resize";
        if (l)
          return r ? "sw-resize" : a ? "nw-resize" : "w-resize";
        if (r)
          return "s-resize";
        if (a)
          return "n-resize";
      }
      break;
    }
  }
  return o > 0 && i > 0 ? "move" : o > 0 ? "ew-resize" : "ns-resize";
}
const be = /* @__PURE__ */ new WeakMap();
function le(e) {
  if (e.defaultView === null || e.defaultView === void 0)
    return;
  let { prevStyle: t, styleSheet: n } = be.get(e) ?? {};
  n === void 0 && (n = new e.defaultView.CSSStyleSheet(), e.adoptedStyleSheets = [n]);
  const { cursorFlags: o, interactionState: i } = G();
  switch (i.state) {
    case "active":
    case "hover": {
      const s = St({
        cursorFlags: o,
        groups: i.hitRegions.map((r) => r.group),
        state: i.state
      }), l = `*{cursor: ${s} !important; ${i.state === "active" ? "touch-action: none;" : ""} }`;
      if (t === l)
        return;
      t = l, s ? n.cssRules.length === 0 ? n.insertRule(l) : n.replaceSync(l) : n.cssRules.length === 1 && n.deleteRule(0);
      break;
    }
    case "inactive": {
      t = void 0, n.cssRules.length === 1 && n.deleteRule(0);
      break;
    }
  }
  be.set(e, {
    prevStyle: t,
    styleSheet: n
  });
}
function Fe({
  document: e,
  event: t,
  hitRegions: n,
  initialLayoutMap: o,
  mountedGroups: i,
  pointerDownAtPoint: s
}) {
  let l = 0;
  const r = new Map(i);
  n.forEach((a) => {
    const { group: u, groupSize: f } = a, { disableCursor: p, orientation: h, panels: m } = u;
    let c = 0;
    s ? h === "horizontal" ? c = (t.clientX - s.x) / f * 100 : c = (t.clientY - s.y) / f * 100 : h === "horizontal" ? c = t.clientX < 0 ? -100 : 100 : c = t.clientY < 0 ? -100 : 100;
    const d = o.get(u), {
      defaultLayoutDeferred: y,
      derivedPanelConstraints: v,
      layout: S,
      separatorToPanels: x
    } = i.get(u) ?? { defaultLayoutDeferred: false };
    if (v && d && S && x) {
      const g = q({
        delta: c,
        initialLayout: d,
        panelConstraints: v,
        pivotIndices: a.panels.map((b) => m.indexOf(b)),
        prevLayout: S,
        trigger: "mouse-or-touch"
      });
      if (U(g, S)) {
        if (c !== 0 && !p)
          switch (h) {
            case "horizontal": {
              l |= c < 0 ? Oe : Te;
              break;
            }
            case "vertical": {
              l |= c < 0 ? _e : Ne;
              break;
            }
          }
      } else {
        r.set(a.group, {
          defaultLayoutDeferred: y,
          derivedPanelConstraints: v,
          layout: g,
          separatorToPanels: x
        });
        const b = a.group.panels.map(({ id: w }) => w).join(",");
        a.group.inMemoryLayouts[b] = g;
      }
    }
  }), M({
    cursorFlags: l,
    mountedGroups: r
  }), le(e);
}
function we(e) {
  const { interactionState: t, mountedGroups: n } = G();
  switch (t.state) {
    case "active":
      Fe({
        document: e.currentTarget,
        event: e,
        hitRegions: t.hitRegions,
        initialLayoutMap: t.initialLayoutMap,
        mountedGroups: n
      });
  }
}
function Le(e) {
  if (e.defaultPrevented)
    return;
  const { interactionState: t, mountedGroups: n } = G();
  switch (t.state) {
    case "active": {
      if (
        // Skip this check for "pointerleave" events, else Firefox triggers a false positive (see #514)
        e.buttons === 0
      ) {
        M(
          (o) => o.interactionState.state === "inactive" ? o : {
            cursorFlags: 0,
            interactionState: {
              state: "inactive"
            }
          }
        );
        return;
      }
      Fe({
        document: e.currentTarget,
        event: e,
        hitRegions: t.hitRegions,
        initialLayoutMap: t.initialLayoutMap,
        mountedGroups: n,
        pointerDownAtPoint: t.pointerDownAtPoint
      });
      break;
    }
    default: {
      const o = $e(e, n);
      o.length === 0 ? t.state !== "inactive" && M({
        interactionState: { state: "inactive" }
      }) : M({
        interactionState: {
          hitRegions: o,
          state: "hover"
        }
      }), le(e.currentTarget);
      break;
    }
  }
}
function Pe(e) {
  if (e.defaultPrevented)
    return;
  e.preventDefault();
  const { interactionState: t } = G();
  switch (t.state) {
    case "active":
      M({
        cursorFlags: 0,
        interactionState: {
          state: "inactive"
        }
      }), le(e.currentTarget);
  }
}
function Re(e) {
  let t = 0, n = 0;
  const o = {};
  for (const s of e)
    if (s.defaultSize !== void 0) {
      t++;
      const l = k(s.defaultSize);
      n += l, o[s.panelId] = l;
    } else
      o[s.panelId] = void 0;
  const i = e.length - t;
  if (i !== 0) {
    const s = k((100 - n) / i);
    for (const l of e)
      l.defaultSize === void 0 && (o[l.panelId] = s);
  }
  return o;
}
function xt(e, t, n) {
  const o = n[0];
  if (!o)
    return;
  const i = e.panels.find((l) => l.element === t);
  if (!i || !i.onResize)
    return;
  const s = W({ group: e });
  i.onResize(
    {
      asPercentage: k(
        o.inlineSize / s * 100
      ),
      inPixels: o.inlineSize
    },
    i.id
  );
}
function zt(e, t) {
  if (Object.keys(e).length !== Object.keys(t).length)
    return false;
  for (const o in e)
    if (e[o] !== t[o])
      return false;
  return true;
}
function bt(e, t) {
  const n = e.map((i) => i.id), o = Object.keys(t);
  if (n.length !== o.length)
    return false;
  for (const i of n)
    if (!o.includes(i))
      return false;
  return true;
}
const B = /* @__PURE__ */ new Map();
function wt(e) {
  let t = true;
  z(
    e.element.ownerDocument.defaultView,
    "Cannot register an unmounted Group"
  );
  const n = e.element.ownerDocument.defaultView.ResizeObserver, o = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), s = new n((c) => {
    for (const d of c) {
      const { borderBoxSize: y, target: v } = d;
      if (v === e.element) {
        if (t) {
          if (W({ group: e }) === 0)
            return;
          M((x) => {
            const g = x.mountedGroups.get(e);
            if (g) {
              const b = me(e), w = g.defaultLayoutDeferred ? Re(b) : g.layout, C = N({
                layout: w,
                panelConstraints: b
              });
              return !g.defaultLayoutDeferred && U(w, C) && zt(
                g.derivedPanelConstraints,
                b
              ) ? x : {
                mountedGroups: new Map(x.mountedGroups).set(e, {
                  defaultLayoutDeferred: false,
                  derivedPanelConstraints: b,
                  layout: C,
                  separatorToPanels: g.separatorToPanels
                })
              };
            }
            return x;
          });
        }
      } else
        xt(e, v, y);
    }
  });
  s.observe(e.element), e.panels.forEach((c) => {
    z(
      !o.has(c.id),
      `Panel ids must be unique; id "${c.id}" was used more than once`
    ), o.add(c.id), c.onResize && s.observe(c.element);
  });
  const l = W({ group: e }), r = me(e), a = e.panels.map(({ id: c }) => c).join(",");
  let u = e.defaultLayout;
  u && (bt(e.panels, u) || (u = void 0));
  const f = e.inMemoryLayouts[a] ?? u ?? Re(r), p = N({
    layout: f,
    panelConstraints: r
  }), h = ke(e), m = e.element.ownerDocument;
  return M((c) => {
    const d = /* @__PURE__ */ new Map();
    return B.set(
      m,
      (B.get(m) ?? 0) + 1
    ), h.forEach((y) => {
      y.separator && d.set(y.separator, y.panels);
    }), {
      mountedGroups: new Map(c.mountedGroups).set(e, {
        defaultLayoutDeferred: l === 0,
        derivedPanelConstraints: r,
        layout: p,
        separatorToPanels: d
      })
    };
  }), e.separators.forEach((c) => {
    z(
      !i.has(c.id),
      `Separator ids must be unique; id "${c.id}" was used more than once`
    ), i.add(c.id), c.element.addEventListener("keydown", ye);
  }), B.get(m) === 1 && (m.addEventListener("pointerdown", ze), m.addEventListener("pointerleave", we), m.addEventListener("pointermove", Le), m.addEventListener("pointerup", Pe)), function() {
    t = false, B.set(
      m,
      Math.max(0, (B.get(m) ?? 0) - 1)
    ), M((d) => {
      const y = new Map(d.mountedGroups);
      return y.delete(e), { mountedGroups: y };
    }), e.separators.forEach((d) => {
      d.element.removeEventListener("keydown", ye);
    }), B.get(m) || (m.removeEventListener("pointerdown", ze), m.removeEventListener("pointerleave", we), m.removeEventListener("pointermove", Le), m.removeEventListener("pointerup", Pe)), s.disconnect();
  };
}
function ue(e) {
  const t = useId();
  return `${e ?? t}`;
}
const A = typeof window < "u" ? useLayoutEffect : useEffect;
function ce(e) {
  const t = useRef(e);
  return A(() => {
    t.current = e;
  }, [e]), useCallback((n) => t.current?.(n), [t]);
}
function fe(...e) {
  return ce((t) => {
    e.forEach((n) => {
      if (n)
        switch (typeof n) {
          case "function": {
            n(t);
            break;
          }
          case "object": {
            n.current = t;
            break;
          }
        }
    });
  });
}
function Lt(e) {
  const t = useRef({ ...e });
  return A(() => {
    for (const n in e)
      t.current[n] = e[n];
  }, [e]), t.current;
}
const je = "--react-resizable-panels--panel--pointer-events";
function He(e, t) {
  const n = e.replace(/[^a-zA-Z0-9\-_]/g, ""), o = t.replace(/[^a-zA-Z0-9\-_]/g, "");
  return `--react-resizable-panels--${n}--${o}`;
}
const Be = createContext(null);
function Pt(e, t) {
  const n = useRef({
    getLayout: () => ({}),
    setLayout: ut
  });
  useImperativeHandle(t, () => n.current, []), A(() => {
    Object.assign(
      n.current,
      Ge({ groupId: e })
    );
  });
}
function Tt({
  children: e,
  className: t,
  defaultLayout: n,
  disableCursor: o,
  disabled: i,
  elementRef: s,
  groupRef: l,
  id: r,
  onLayoutChange: a,
  orientation: u = "horizontal",
  style: f,
  ...p
}) {
  const h = useRef({}), m = ce((L) => {
    U(h.current, L) || (h.current = L, a?.(L));
  }), c = ue(r), [d, y] = useState(false), v = useRef(null), [S, x] = useState(n ?? {}), [g, b] = useState([]), [w, C] = useState([]), Y = useRef({
    lastExpandedPanelSizes: {},
    layouts: {}
  }), oe = fe(v, s);
  Pt(c, l);
  const Z = useMemo(
    () => ({
      id: c,
      orientation: u,
      registerPanel: (L) => (b((P) => ae(u, [...P, L])), () => {
        b((P) => P.filter((O) => O !== L));
      }),
      registerSeparator: (L) => (C(
        (P) => ae(u, [...P, L])
      ), () => {
        C(
          (P) => P.filter((O) => O !== L)
        );
      })
    }),
    [c, u]
  ), $ = Lt({
    defaultLayout: n,
    disableCursor: o
  }), F = useRef(null);
  A(() => {
    const L = v.current;
    if (L === null)
      return;
    const P = {
      defaultLayout: $.defaultLayout,
      disableCursor: !!$.disableCursor,
      disabled: !!i,
      element: L,
      id: c,
      inMemoryLastExpandedPanelSizes: Y.current.lastExpandedPanelSizes,
      inMemoryLayouts: Y.current.layouts,
      orientation: u,
      panels: g,
      separators: w
    };
    F.current = P;
    const O = wt(P), pe = G().mountedGroups.get(P);
    if (pe) {
      const { defaultLayoutDeferred: j, derivedPanelConstraints: H, layout: Q } = pe;
      !j && H.length > 0 && (x(Q), m?.(Q));
    }
    const Ve = _.addListener(
      "interactionStateChange",
      (j) => {
        switch (j.state) {
          case "active": {
            y(
              j.hitRegions.some(
                (H) => H.group === P
              )
            );
            break;
          }
          default: {
            y(false);
            break;
          }
        }
      }
    ), We = _.addListener(
      "mountedGroupsChange",
      (j) => {
        const H = j.get(P);
        if (H) {
          const { defaultLayoutDeferred: Q, derivedPanelConstraints: Ue, layout: he } = H;
          if (Q || Ue.length === 0)
            return;
          x(he), m?.(he);
        }
      }
    );
    return () => {
      F.current = null, O(), Ve(), We();
    };
  }, [
    i,
    c,
    m,
    u,
    g,
    w,
    $
  ]), useEffect(() => {
    const L = F.current;
    L && (L.defaultLayout = n, L.disableCursor = !!o);
  });
  const J = {
    [je]: d ? "none" : void 0
  };
  for (const L in S) {
    const P = He(c, L), O = S[L];
    J[P] = O;
  }
  return /* @__PURE__ */ jsx(Be.Provider, { value: Z, children: /* @__PURE__ */ jsx(
    "div",
    {
      ...p,
      "aria-orientation": u,
      className: t,
      "data-group": true,
      "data-testid": c,
      id: c,
      ref: oe,
      style: {
        ...f,
        ...J,
        display: "flex",
        flexDirection: u === "horizontal" ? "row" : "column",
        flexWrap: "nowrap"
      },
      children: e
    }
  ) });
}
function de() {
  const e = useContext(Be);
  return z(
    e,
    "Group Context not found; did you render a Panel or Separator outside of a Group?"
  ), e;
}
function Et({
  groupId: e,
  panelId: t
}) {
  const n = () => {
    const { mountedGroups: r } = G();
    for (const [
      a,
      {
        defaultLayoutDeferred: u,
        derivedPanelConstraints: f,
        layout: p,
        separatorToPanels: h
      }
    ] of r)
      if (a.id === e)
        return {
          defaultLayoutDeferred: u,
          derivedPanelConstraints: f,
          group: a,
          layout: p,
          separatorToPanels: h
        };
    throw Error(`Group ${e} not found`);
  }, o = () => {
    const r = n().derivedPanelConstraints.find(
      (a) => a.panelId === t
    );
    if (r !== void 0)
      return r;
    throw Error(`Panel constraints not found for Panel ${t}`);
  }, i = () => {
    const r = n().group.panels.find((a) => a.id === t);
    if (r !== void 0)
      return r;
    throw Error(`Layout not found for Panel ${t}`);
  }, s = () => {
    const r = n().layout[t];
    if (r !== void 0)
      return r;
    throw Error(`Layout not found for Panel ${t}`);
  }, l = (r) => {
    const a = s();
    if (r === a)
      return;
    const {
      defaultLayoutDeferred: u,
      derivedPanelConstraints: f,
      group: p,
      layout: h,
      separatorToPanels: m
    } = n(), c = p.panels.findIndex((S) => S.id === t), d = c === p.panels.length - 1, y = q({
      delta: d ? a - r : r - a,
      initialLayout: h,
      panelConstraints: f,
      pivotIndices: d ? [c - 1, c] : [c, c + 1],
      prevLayout: h,
      trigger: "imperative-api"
    }), v = N({
      layout: y,
      panelConstraints: f
    });
    U(h, v) || M((S) => ({
      mountedGroups: new Map(S.mountedGroups).set(p, {
        defaultLayoutDeferred: u,
        derivedPanelConstraints: f,
        layout: v,
        separatorToPanels: m
      })
    }));
  };
  return {
    collapse: () => {
      const { collapsible: r, collapsedSize: a } = o(), { expandToSizeRef: u } = i(), f = s();
      r && f !== a && (u.current = f, l(a));
    },
    expand: () => {
      const { collapsible: r, collapsedSize: a, minSize: u } = o(), { expandToSizeRef: f } = i(), p = s();
      if (r && p === a) {
        let h = f.current ?? u;
        h === 0 && (h = 1), l(h);
      }
    },
    getSize: () => {
      const { group: r } = n(), a = s(), { element: u } = i(), f = r.orientation === "horizontal" ? u.offsetWidth : u.offsetHeight;
      return {
        asPercentage: a,
        inPixels: f
      };
    },
    isCollapsed: () => {
      const { collapsible: r, collapsedSize: a } = o(), u = s();
      return r && R(a, u);
    },
    resize: (r) => {
      if (s() !== r) {
        let u;
        switch (typeof r) {
          case "number": {
            const { group: f } = n(), p = W({ group: f });
            u = k(r / p * 100);
            break;
          }
          case "string": {
            u = parseFloat(r);
            break;
          }
        }
        l(u);
      }
    }
  };
}
function Mt(e, t) {
  const { id: n } = de(), o = useRef({
    collapse: re,
    expand: re,
    getSize: () => ({
      asPercentage: 0,
      inPixels: 0
    }),
    isCollapsed: () => false,
    resize: re
  });
  useImperativeHandle(t, () => o.current, []), A(() => {
    Object.assign(
      o.current,
      Et({ groupId: n, panelId: e })
    );
  });
}
function $t({
  children: e,
  className: t,
  collapsedSize: n = "0%",
  collapsible: o = false,
  defaultSize: i,
  elementRef: s,
  id: l,
  maxSize: r = "100%",
  minSize: a = "0%",
  onResize: u,
  panelRef: f,
  style: p,
  ...h
}) {
  const m = !!l, c = ue(l), d = useRef(null), y = fe(d, s), { id: v, registerPanel: S } = de(), x = u !== null, g = ce((w) => {
    u?.(w, l);
  });
  A(() => {
    const w = d.current;
    if (w !== null)
      return S({
        element: w,
        expandToSizeRef: { current: void 0 },
        id: c,
        idIsStable: m,
        onResize: x ? g : void 0,
        panelConstraints: {
          collapsedSize: n,
          collapsible: o,
          defaultSize: i,
          maxSize: r,
          minSize: a
        }
      });
  }, [
    n,
    o,
    i,
    x,
    c,
    m,
    r,
    a,
    g,
    S
  ]), Mt(c, f);
  const b = He(v, c);
  return /* @__PURE__ */ jsx(
    "div",
    {
      ...h,
      "data-panel": true,
      "data-testid": c,
      id: c,
      ref: y,
      style: {
        ...It,
        flexBasis: 0,
        flexGrow: `var(${b}, 1)`,
        flexShrink: 1,
        // Prevent Panel content from interfering with panel size
        overflow: "hidden",
        // Disable pointer events inside of a panel during resize
        // This avoid edge cases like nested iframes
        pointerEvents: `var(${je})`
      },
      children: /* @__PURE__ */ jsx(
        "div",
        {
          className: t,
          style: {
            width: "100%",
            height: "100%",
            ...p
          },
          children: e
        }
      )
    }
  );
}
const It = {
  minHeight: "unset",
  maxHeight: "unset",
  height: "unset",
  minWidth: "unset",
  maxWidth: "unset",
  width: "unset",
  flex: "unset",
  flexBasis: "unset",
  flexShrink: "unset",
  flexGrow: "unset",
  border: "unset",
  borderWidth: "unset",
  padding: "unset",
  margin: "unset"
};
function kt({
  layout: e,
  panelConstraints: t,
  panelId: n,
  panelIndex: o
}) {
  let i, s;
  const l = e[n], r = t.find(
    (a) => a.panelId === n
  );
  if (r) {
    const a = r.maxSize, u = s = r.collapsible ? r.collapsedSize : r.minSize, f = [o, o + 1];
    s = N({
      layout: q({
        delta: u - l,
        initialLayout: e,
        panelConstraints: t,
        pivotIndices: f,
        prevLayout: e,
        trigger: "keyboard"
      }),
      panelConstraints: t
    })[n], i = N({
      layout: q({
        delta: a - l,
        initialLayout: e,
        panelConstraints: t,
        pivotIndices: f,
        prevLayout: e,
        trigger: "keyboard"
      }),
      panelConstraints: t
    })[n];
  }
  return {
    valueControls: n,
    valueMax: i,
    valueMin: s,
    valueNow: l
  };
}
function Ht({
  children: e,
  className: t,
  elementRef: n,
  id: o,
  style: i,
  ...s
}) {
  const l = ue(o), [r, a] = useState({}), [u, f] = useState("inactive"), [p, h] = useState(null), m = fe(h, n), {
    id: c,
    orientation: d,
    registerSeparator: y
  } = de(), v = d === "horizontal" ? "vertical" : "horizontal";
  return A(() => {
    if (p !== null) {
      const S = {
        element: p,
        id: l
      }, x = y(S), g = _.addListener(
        "interactionStateChange",
        (w) => {
          f(
            w.state !== "inactive" && w.hitRegions.some(
              (C) => C.separator === S
            ) ? w.state : "inactive"
          );
        }
      ), b = _.addListener(
        "mountedGroupsChange",
        (w) => {
          w.forEach(
            ({ derivedPanelConstraints: C, layout: Y, separatorToPanels: oe }, Z) => {
              if (Z.id === c) {
                const $ = oe.get(S);
                if ($) {
                  const F = $[0], J = Z.panels.indexOf(F);
                  a(
                    kt({
                      layout: Y,
                      panelConstraints: C,
                      panelId: F.id,
                      panelIndex: J
                    })
                  );
                }
              }
            }
          );
        }
      );
      return () => {
        g(), b(), x();
      };
    }
  }, [p, c, l, y]), /* @__PURE__ */ jsx(
    "div",
    {
      ...s,
      "aria-controls": r.valueControls,
      "aria-orientation": v,
      "aria-valuemax": r.valueMax,
      "aria-valuemin": r.valueMin,
      "aria-valuenow": r.valueNow,
      children: e,
      className: t,
      "data-separator": u,
      "data-testid": l,
      id: l,
      ref: m,
      role: "separator",
      style: {
        flexBasis: "auto",
        ...i,
        flexGrow: 0,
        flexShrink: 0
      },
      tabIndex: 0
    }
  );
}
export {
  Tt as Group,
  $t as Panel,
  Ht as Separator
};
//# sourceMappingURL=react-resizable-panels.js.map
