import { jsxs as z, Fragment as se, jsx as o } from "react/jsx-runtime";
import { b as be, h as Ie, t as we, g as De, i as ht, d as ft, u as Ce, s as pt, a as _t } from "./core-CfXsl755.js";
import gt, { useRef as q, useState as D, useEffect as X, useCallback as b, useReducer as wt, useMemo as ve, useContext as Pe, createContext as Ye, forwardRef as Te } from "react";
import { createPortal as fe } from "react-dom";
const Dt = ({
  visible: e,
  onClose: n,
  title: r,
  items: i,
  showCancelButton: h = !0,
  cancelText: d,
  className: m,
  style: g
}) => {
  const { t: p } = be();
  return e ? /* @__PURE__ */ z(se, { children: [
    /* @__PURE__ */ o("div", { className: "nice-actionsheet__overlay", onClick: n }),
    /* @__PURE__ */ z("div", { className: `nice-actionsheet ${m || ""}`, style: g, children: [
      r && /* @__PURE__ */ o("div", { className: "nice-actionsheet__title", children: r }),
      /* @__PURE__ */ o("div", { className: "nice-actionsheet__items", children: i.map((x, a) => /* @__PURE__ */ z(
        "button",
        {
          className: `nice-actionsheet__item ${x.type === "danger" ? "nice-actionsheet__item--danger" : ""}`,
          disabled: x.disabled,
          onClick: () => {
            x.onClick?.(), n();
          },
          children: [
            x.icon && /* @__PURE__ */ o("span", { className: "nice-actionsheet__icon", children: x.icon }),
            x.text
          ]
        },
        a
      )) }),
      h && /* @__PURE__ */ o("button", { className: "nice-actionsheet__cancel", onClick: n, children: d || p("cancel", "Cancel") })
    ] })
  ] }) : null;
}, Pt = ({
  open: e,
  onClose: n,
  children: r,
  title: i,
  size: h = "md",
  closeOnBackdropClick: d = !0,
  closeOnEscape: m = !0,
  disableFocusTrap: g = !1,
  disableBodyScroll: p = !0,
  zIndex: x = 1e3,
  className: a,
  style: M
}) => {
  const C = q(null);
  Ie(C, e && !g), X(() => {
    if (!p && e) {
      const s = document.body.style.overflow;
      return document.body.style.overflow = "hidden", () => {
        document.body.style.overflow = s;
      };
    }
  }, [e, p]), X(() => {
    if (!m || !e) return;
    const s = (k) => {
      k.key === "Escape" && (k.preventDefault(), n());
    };
    return document.addEventListener("keydown", s), () => document.removeEventListener("keydown", s);
  }, [m, e, n]);
  const f = b((s) => {
    d && s.target === s.currentTarget && n();
  }, [d, n]);
  if (!e) return null;
  const N = {
    sm: "nice-modal--sm",
    md: "nice-modal--md",
    lg: "nice-modal--lg",
    xl: "nice-modal--xl",
    full: "nice-modal--full"
  }[h];
  return fe(
    /* @__PURE__ */ o(
      "div",
      {
        className: "nice-modal__overlay",
        style: { zIndex: x },
        onClick: f,
        role: "presentation",
        children: /* @__PURE__ */ o(
          "div",
          {
            ref: C,
            className: `nice-modal ${N} ${a || ""}`,
            role: "dialog",
            "aria-modal": "true",
            "aria-label": i,
            style: M,
            tabIndex: -1,
            children: r
          }
        )
      }
    ),
    document.body
  );
}, Yt = ({
  children: e,
  showClose: n = !0,
  onClose: r,
  className: i
}) => /* @__PURE__ */ z("div", { className: `nice-modal__header ${i || ""}`, children: [
  /* @__PURE__ */ o("div", { className: "nice-modal__title", children: e }),
  n && r && /* @__PURE__ */ o(
    "button",
    {
      type: "button",
      className: "nice-modal__close",
      onClick: r,
      "aria-label": "Close",
      children: /* @__PURE__ */ o("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ o("path", { d: "M4 4l12 12M4 16L16 4" }) })
    }
  )
] }), Xt = ({ children: e, className: n }) => /* @__PURE__ */ o("div", { className: `nice-modal__body ${n || ""}`, children: e }), Ot = ({ children: e, className: n }) => /* @__PURE__ */ o("div", { className: `nice-modal__footer ${n || ""}`, children: e }), Ht = ({
  open: e,
  onClose: n,
  children: r,
  position: i = "right",
  size: h = 320,
  title: d,
  closeOnBackdropClick: m = !0,
  closeOnEscape: g = !0,
  swipeToClose: p = !0,
  zIndex: x = 1e3,
  className: a,
  style: M
}) => {
  const C = q(null), [f, N] = D(!1), [s, k] = D(0);
  Ie(C, e), X(() => {
    if (!g || !e) return;
    const l = (E) => {
      E.key === "Escape" && (E.preventDefault(), n());
    };
    return document.addEventListener("keydown", l), () => document.removeEventListener("keydown", l);
  }, [g, e, n]);
  const c = b((l) => {
    let E = 0;
    switch (i) {
      case "left":
        E = Math.min(0, l.deltaX);
        break;
      case "right":
        E = Math.max(0, l.deltaX);
        break;
      case "top":
        E = Math.min(0, l.deltaY);
        break;
      case "bottom":
        E = Math.max(0, l.deltaY);
        break;
    }
    k(E);
  }, [i]), v = b((l) => {
    let T = !1;
    switch (i) {
      case "left":
        T = l.deltaX < -100;
        break;
      case "right":
        T = l.deltaX > 100;
        break;
      case "top":
        T = l.deltaY < -100;
        break;
      case "bottom":
        T = l.deltaY > 100;
        break;
    }
    T && (we("light"), n()), k(0), N(!1);
  }, [i, n]), { ref: _ } = ht({
    enabled: p && e,
    onPanStart: () => N(!0),
    onPan: c,
    onPanEnd: v
  }), I = b((l) => {
    m && l.target === l.currentTarget && n();
  }, [m, n]);
  if (!e) return null;
  const R = i === "left" || i === "right", O = R ? { width: typeof h == "number" ? `${h}px` : h } : { height: typeof h == "number" ? `${h}px` : h }, t = () => {
    if (f)
      return R ? `translateX(${s}px)` : `translateY(${s}px)`;
  };
  return fe(
    /* @__PURE__ */ z(se, { children: [
      /* @__PURE__ */ o(
        "div",
        {
          className: `nice-drawer__overlay ${e ? "nice-drawer__overlay--visible" : ""}`,
          style: { zIndex: x },
          onClick: I
        }
      ),
      /* @__PURE__ */ o(
        "div",
        {
          ref: (l) => {
            C.current = l, _.current = l;
          },
          className: `nice-drawer nice-drawer--${i} ${e ? "nice-drawer--open" : ""} ${a || ""}`,
          style: {
            ...O,
            zIndex: x + 1,
            transform: t(),
            transition: f ? "none" : void 0,
            ...M
          },
          role: "dialog",
          "aria-modal": "true",
          "aria-label": d,
          tabIndex: -1,
          children: r
        }
      )
    ] }),
    document.body
  );
}, qt = ({
  open: e,
  onClose: n,
  children: r,
  title: i,
  showHandle: h = !0,
  snapPoints: d = [0.5, 0.9],
  initialSnap: m = 0,
  expandable: g = !0,
  closeOnBackdropClick: p = !0,
  closeOnEscape: x = !0,
  hapticFeedback: a = !0,
  zIndex: M = 1e3,
  className: C,
  style: f
}) => {
  const N = q(null), s = q(null), [k, c] = D(m), [v, _] = D(!1), [I, R] = D(0), O = q(0);
  X(() => {
    e && (c(m), R(0));
  }, [e, m]), Ie(N, e), X(() => {
    if (!x || !e) return;
    const u = (y) => {
      y.key === "Escape" && (y.preventDefault(), n());
    };
    return document.addEventListener("keydown", u), () => document.removeEventListener("keydown", u);
  }, [x, e, n]), X(() => {
    if (e) {
      const u = document.body.style.overflow;
      return document.body.style.overflow = "hidden", () => {
        document.body.style.overflow = u;
      };
    }
  }, [e]);
  const t = b((u) => {
    const y = u.target.closest(".nice-bottom-sheet__handle"), w = s.current, A = !w || w.scrollTop <= 0;
    !y && !A || (_(!0), O.current = u.touches[0].clientY);
  }, []), l = b((u) => {
    if (!v) return;
    const y = u.touches[0].clientY - O.current;
    (y > 0 || k < d.length - 1) && R(y);
  }, [v, k, d.length]), E = b(() => {
    if (!v) return;
    const u = window.innerHeight;
    d[k] * u;
    const y = -I, w = u * 0.15;
    y > w && g && k < d.length - 1 ? (c(k + 1), a && we("selection")) : y < -w && (k > 0 ? (c(k - 1), a && we("selection")) : (a && we("light"), n())), _(!1), R(0);
  }, [v, I, k, d, g, a, n]), T = b(() => {
    p && n();
  }, [p, n]);
  if (!e) return null;
  const P = d[k] * 100, S = v ? I : 0;
  return fe(
    /* @__PURE__ */ z(se, { children: [
      /* @__PURE__ */ o(
        "div",
        {
          className: `nice-bottom-sheet__overlay ${e ? "nice-bottom-sheet__overlay--visible" : ""}`,
          style: { zIndex: M },
          onClick: T
        }
      ),
      /* @__PURE__ */ z(
        "div",
        {
          ref: N,
          className: `nice-bottom-sheet ${e ? "nice-bottom-sheet--open" : ""} ${C || ""}`,
          style: {
            zIndex: M + 1,
            height: `${P}vh`,
            transform: `translateY(${Math.max(0, S)}px)`,
            transition: v ? "none" : "transform 0.3s ease-out, height 0.3s ease-out",
            ...f
          },
          role: "dialog",
          "aria-modal": "true",
          "aria-label": i,
          tabIndex: -1,
          onTouchStart: t,
          onTouchMove: l,
          onTouchEnd: E,
          children: [
            h && /* @__PURE__ */ o("div", { className: "nice-bottom-sheet__handle", "aria-hidden": "true" }),
            i && /* @__PURE__ */ o("div", { className: "nice-bottom-sheet__title", children: i }),
            /* @__PURE__ */ o("div", { ref: s, className: "nice-bottom-sheet__content", children: r })
          ]
        }
      )
    ] }),
    document.body
  );
}, Bt = ({
  trigger: e,
  children: n,
  placement: r = "bottom",
  triggerMode: i = "click",
  open: h,
  onOpenChange: d,
  hoverDelay: m = 200,
  offset: g = 8,
  className: p,
  showArrow: x = !0
}) => {
  const [a, M] = D(!1), C = q(null), f = q(null), N = q(null), s = h !== void 0, k = s ? h : a, c = b((t) => {
    s || M(t), d?.(t);
  }, [s, d]);
  De(f, () => {
    i !== "manual" && k && c(!1);
  });
  const v = b(() => {
    i === "click" && c(!k);
  }, [i, k, c]), _ = b(() => {
    i === "hover" && (N.current && window.clearTimeout(N.current), N.current = window.setTimeout(() => c(!0), m));
  }, [i, m, c]), I = b(() => {
    i === "hover" && (N.current && window.clearTimeout(N.current), N.current = window.setTimeout(() => c(!1), m));
  }, [i, m, c]), [R, O] = D({ top: 0, left: 0 });
  return X(() => {
    if (!k || !C.current || !f.current) return;
    const t = C.current.getBoundingClientRect(), l = f.current.getBoundingClientRect(), E = window.innerWidth, T = window.innerHeight;
    let P = 0, S = 0;
    const [u, y = "center"] = r.split("-");
    switch (u) {
      case "top":
        P = t.top - l.height - g, S = t.left + (t.width - l.width) / 2;
        break;
      case "bottom":
        P = t.bottom + g, S = t.left + (t.width - l.width) / 2;
        break;
      case "left":
        P = t.top + (t.height - l.height) / 2, S = t.left - l.width - g;
        break;
      case "right":
        P = t.top + (t.height - l.height) / 2, S = t.right + g;
        break;
    }
    u === "top" || u === "bottom" ? (y === "start" && (S = t.left), y === "end" && (S = t.right - l.width)) : (y === "start" && (P = t.top), y === "end" && (P = t.bottom - l.height)), S = Math.max(8, Math.min(E - l.width - 8, S)), P = Math.max(8, Math.min(T - l.height - 8, P)), O({ top: P, left: S });
  }, [k, r, g]), /* @__PURE__ */ z(se, { children: [
    /* @__PURE__ */ o(
      "div",
      {
        ref: C,
        className: "nice-popover__trigger",
        onClick: v,
        onMouseEnter: _,
        onMouseLeave: I,
        style: { display: "inline-block" },
        children: e
      }
    ),
    k && fe(
      /* @__PURE__ */ z(
        "div",
        {
          ref: f,
          className: `nice-popover nice-popover--${r} ${p || ""}`,
          style: {
            position: "fixed",
            top: R.top,
            left: R.left,
            zIndex: 1100
          },
          onMouseEnter: _,
          onMouseLeave: I,
          role: "tooltip",
          children: [
            x && /* @__PURE__ */ o("div", { className: "nice-popover__arrow" }),
            /* @__PURE__ */ o("div", { className: "nice-popover__content", children: n })
          ]
        }
      ),
      document.body
    )
  ] });
}, At = ({
  items: e,
  children: n,
  onOpen: r,
  onClose: i,
  className: h
}) => {
  const [d, m] = D(!1), [g, p] = D({ x: 0, y: 0 }), x = q(null), a = q(null);
  De(x, () => {
    d && (m(!1), i?.());
  });
  const M = b((N) => {
    N.preventDefault(), p({ x: N.clientX, y: N.clientY }), m(!0), r?.();
  }, [r]), C = b((N) => {
    !N.disabled && N.onClick && (N.onClick(), m(!1), i?.());
  }, [i]);
  X(() => {
    if (!d) return;
    const N = (s) => {
      s.key === "Escape" && (m(!1), i?.());
    };
    return document.addEventListener("keydown", N), () => document.removeEventListener("keydown", N);
  }, [d, i]);
  const f = (N) => /* @__PURE__ */ o("ul", { className: "nice-context-menu__list", role: "menu", children: N.map((s) => s.divider ? /* @__PURE__ */ o("li", { className: "nice-context-menu__divider", role: "separator" }, s.key) : /* @__PURE__ */ o("li", { role: "presentation", children: /* @__PURE__ */ z(
    "button",
    {
      type: "button",
      className: `nice-context-menu__item ${s.disabled ? "nice-context-menu__item--disabled" : ""} ${s.danger ? "nice-context-menu__item--danger" : ""}`,
      role: "menuitem",
      disabled: s.disabled,
      onClick: () => C(s),
      children: [
        s.icon && /* @__PURE__ */ o("span", { className: "nice-context-menu__icon", children: s.icon }),
        /* @__PURE__ */ o("span", { className: "nice-context-menu__label", children: s.label })
      ]
    }
  ) }, s.key)) });
  return /* @__PURE__ */ z(se, { children: [
    /* @__PURE__ */ o(
      "div",
      {
        ref: a,
        onContextMenu: M,
        style: { display: "contents" },
        children: n
      }
    ),
    d && fe(
      /* @__PURE__ */ o(
        "div",
        {
          ref: x,
          className: `nice-context-menu ${h || ""}`,
          style: {
            position: "fixed",
            left: g.x,
            top: g.y,
            zIndex: 1200
          },
          role: "menu",
          children: f(e)
        }
      ),
      document.body
    )
  ] });
}, Wt = ({
  visible: e,
  onClose: n,
  targetRef: r,
  position: i = "bottom",
  title: h,
  showArrow: d = !0,
  width: m,
  children: g,
  className: p,
  style: x,
  displayStyle: a
}) => {
  ft("tooltip", a);
  const M = q(null), [C, f] = D({ top: 0, left: 0 }), N = b(() => {
    const s = r.current, k = M.current;
    if (!s || !k) return;
    const c = s.getBoundingClientRect(), v = k.getBoundingClientRect();
    let _ = 0, I = 0;
    const R = 8;
    switch (i) {
      case "top":
        _ = c.top - v.height - R, I = c.left + (c.width - v.width) / 2;
        break;
      case "bottom":
        _ = c.bottom + R, I = c.left + (c.width - v.width) / 2;
        break;
      case "left":
        _ = c.top + (c.height - v.height) / 2, I = c.left - v.width - R;
        break;
      case "right":
        _ = c.top + (c.height - v.height) / 2, I = c.right + R;
        break;
    }
    f({ top: _ + window.scrollY, left: I + window.scrollX });
  }, [r, i]);
  return X(() => {
    if (e) {
      requestAnimationFrame(N);
      const s = (k) => {
        M.current && !M.current.contains(k.target) && r.current && !r.current.contains(k.target) && n();
      };
      return document.addEventListener("mousedown", s), () => document.removeEventListener("mousedown", s);
    }
  }, [e, N, n, r]), e ? /* @__PURE__ */ z(
    "div",
    {
      ref: M,
      className: `nice-popover nice-popover--${i} ${p || ""}`,
      style: { ...x, position: "absolute", top: C.top, left: C.left, width: m },
      children: [
        d && /* @__PURE__ */ o("div", { className: `nice-popover__arrow nice-popover__arrow--${i}` }),
        h && /* @__PURE__ */ o("div", { className: "nice-popover__title", children: h }),
        /* @__PURE__ */ o("div", { className: "nice-popover__content", children: g })
      ]
    }
  ) : null;
}, Ft = ({
  visible: e,
  message: n,
  container: r,
  showIndicator: i = !0,
  shading: h = !0,
  className: d,
  style: m
}) => {
  const { t: g } = be();
  if (!e) return null;
  const p = !!r?.current, x = /* @__PURE__ */ z("div", { className: `nice-loadpanel ${d || ""}`, style: m, children: [
    h && /* @__PURE__ */ o("div", { className: "nice-loadpanel__shade" }),
    /* @__PURE__ */ z("div", { className: "nice-loadpanel__box", children: [
      i && /* @__PURE__ */ o("div", { className: "nice-spinner nice-spinner--md" }),
      /* @__PURE__ */ o("span", { className: "nice-loadpanel__text", children: n || g("loading", "Loading...") })
    ] })
  ] });
  if (p && r.current) {
    const a = r.current;
    return a.style.position = a.style.position || "relative", x;
  }
  return x;
}, Ut = ({
  direction: e = "row",
  align: n,
  justify: r,
  wrap: i,
  gap: h,
  flex: d,
  children: m,
  className: g,
  style: p
}) => /* @__PURE__ */ o(
  "div",
  {
    className: `nice-box ${g || ""}`,
    style: {
      display: "flex",
      flexDirection: e,
      alignItems: n,
      justifyContent: r,
      flexWrap: i ? "wrap" : void 0,
      gap: h,
      flex: d,
      ...p
    },
    children: m
  }
), Gt = ({
  direction: e = "row",
  items: n,
  gap: r,
  className: i,
  style: h
}) => /* @__PURE__ */ o(
  "div",
  {
    className: `nice-responsivebox ${i || ""}`,
    style: { display: "flex", flexDirection: e, gap: r, ...h },
    children: n.map((d, m) => /* @__PURE__ */ o("div", { style: { flex: d.ratio ?? 1, flexBasis: d.baseSize, flexShrink: d.shrink ?? 1 }, children: d.children }, m))
  }
), Vt = ({
  width: e = 200,
  height: n = 200,
  minWidth: r = 50,
  minHeight: i = 50,
  maxWidth: h = 1 / 0,
  maxHeight: d = 1 / 0,
  handles: m = ["right", "bottom", "bottomRight"],
  onResize: g,
  children: p,
  className: x,
  style: a
}) => {
  const [M, C] = D({ width: e, height: n }), f = q(null), N = (c, v) => {
    v.preventDefault();
    const _ = v.clientX, I = v.clientY, R = M.width, O = M.height, t = (E) => {
      const T = E.clientX - _, P = E.clientY - I;
      let S = R, u = O;
      (c.includes("right") || c === "right") && (S = R + T), (c.includes("bottom") || c === "bottom") && (u = O + P), (c.includes("left") || c === "left") && (S = R - T), (c.includes("top") || c === "top") && (u = O - P), S = Math.max(r, Math.min(h, S)), u = Math.max(i, Math.min(d, u)), C({ width: S, height: u }), g?.({ width: S, height: u });
    }, l = () => {
      document.removeEventListener("pointermove", t), document.removeEventListener("pointerup", l);
    };
    document.addEventListener("pointermove", t), document.addEventListener("pointerup", l);
  }, s = (c) => {
    switch (c) {
      case "top":
      case "bottom":
        return "ns-resize";
      case "left":
      case "right":
        return "ew-resize";
      case "topLeft":
      case "bottomRight":
        return "nwse-resize";
      case "topRight":
      case "bottomLeft":
        return "nesw-resize";
      default:
        return "default";
    }
  }, k = (c) => {
    const v = { position: "absolute", zIndex: 1 }, _ = 8;
    return c === "right" ? { ...v, top: 0, right: -_ / 2, width: _, height: "100%", cursor: s(c) } : c === "bottom" ? { ...v, left: 0, bottom: -_ / 2, width: "100%", height: _, cursor: s(c) } : c === "left" ? { ...v, top: 0, left: -_ / 2, width: _, height: "100%", cursor: s(c) } : c === "top" ? { ...v, top: -_ / 2, left: 0, width: "100%", height: _, cursor: s(c) } : c === "bottomRight" ? { ...v, bottom: -_ / 2, right: -_ / 2, width: _ * 2, height: _ * 2, cursor: s(c) } : c === "bottomLeft" ? { ...v, bottom: -_ / 2, left: -_ / 2, width: _ * 2, height: _ * 2, cursor: s(c) } : c === "topRight" ? { ...v, top: -_ / 2, right: -_ / 2, width: _ * 2, height: _ * 2, cursor: s(c) } : c === "topLeft" ? { ...v, top: -_ / 2, left: -_ / 2, width: _ * 2, height: _ * 2, cursor: s(c) } : v;
  };
  return /* @__PURE__ */ z(
    "div",
    {
      ref: f,
      className: `nice-resizable ${x || ""}`,
      style: { ...a, width: M.width, height: M.height, position: "relative", overflow: "hidden" },
      children: [
        p,
        m.map((c) => /* @__PURE__ */ o("div", { style: k(c), onPointerDown: (v) => N(c, v) }, c))
      ]
    }
  );
}, jt = ({
  direction: e = "vertical",
  showScrollbar: n = "onInteraction",
  width: r,
  height: i,
  onScroll: h,
  children: d,
  className: m,
  style: g
}) => {
  const p = e === "horizontal" || e === "both" ? "auto" : "hidden", x = e === "vertical" || e === "both" ? "auto" : "hidden";
  return /* @__PURE__ */ o(
    "div",
    {
      className: `nice-scrollview ${n === "never" ? "nice-scrollview--hide-sb" : n === "always" ? "nice-scrollview--show-sb" : ""} ${m || ""}`,
      style: { ...g, width: r, height: i, overflowX: p, overflowY: x },
      onScroll: h,
      children: d
    }
  );
};
function ze(e, n) {
  if (!e) return { score: 1, indices: [] };
  const r = e.toLowerCase(), i = n.toLowerCase();
  let h = 0;
  const d = [];
  let m = 0, g = -1;
  for (let p = 0; p < i.length && h < r.length; p++)
    i[p] === r[h] && (d.push(p), g === p - 1 && (m += 3), (p === 0 || /[\s\-_/.]/.test(n[p - 1])) && (m += 5), n[p] === e[h] && (m += 1), m += 1, g = p, h++);
  return h < r.length ? null : (m -= d[0] * 0.1, { score: m, indices: d });
}
function vt(e, n) {
  if (n.length === 0) return [e];
  const r = [];
  let i = 0;
  const h = new Set(n);
  for (let d = 0; d < e.length; d++)
    h.has(d) && (i < d && r.push(e.slice(i, d)), r.push(
      gt.createElement("mark", { key: `m-${d}`, className: "nice-command-palette__match" }, e[d])
    ), i = d + 1);
  return i < e.length && r.push(e.slice(i)), r;
}
function bt(e, n) {
  switch (n.type) {
    case "REGISTER": {
      const r = new Map(e.commands);
      return r.set(n.command.id, n.command), { ...e, commands: r };
    }
    case "REGISTER_BATCH": {
      const r = new Map(e.commands);
      for (const i of n.commands) r.set(i.id, i);
      return { ...e, commands: r };
    }
    case "UNREGISTER": {
      const r = new Map(e.commands);
      return r.delete(n.id), { ...e, commands: r };
    }
    case "OPEN":
      return { ...e, isOpen: !0, query: "", selectedIndex: 0 };
    case "CLOSE":
      return { ...e, isOpen: !1, query: "", selectedIndex: 0 };
    case "SET_QUERY":
      return { ...e, query: n.query, selectedIndex: 0 };
    case "SET_SELECTED":
      return { ...e, selectedIndex: n.index };
    case "ADD_RECENT": {
      const r = e.recentIds.filter((i) => i !== n.id);
      return {
        ...e,
        recentIds: [n.id, ...r].slice(0, n.maxRecent)
      };
    }
    default:
      return e;
  }
}
const Xe = Ye(null);
function yt() {
  const e = Pe(Xe);
  if (!e)
    throw new Error("useCommandPalette must be used within NiceCommandPaletteProvider");
  return e;
}
const xt = ({
  children: e,
  commands: n,
  placeholder: r = "Type a command...",
  maxVisible: i = 10,
  maxRecent: h = 5,
  className: d,
  emptyText: m = "No commands found",
  closeOnAction: g = !0,
  onOpen: p,
  onClose: x
}) => {
  const [a, M] = wt(bt, {
    commands: new Map(n?.map((u) => [u.id, u]) ?? []),
    isOpen: !1,
    query: "",
    selectedIndex: 0,
    recentIds: []
  }), C = q(null), f = q(null), [N, s] = D(!1), k = b((u) => {
    M({ type: "REGISTER", command: u });
  }, []), c = b((u) => {
    M({ type: "UNREGISTER", id: u });
  }, []), v = b((u) => {
    M({ type: "REGISTER_BATCH", commands: u });
  }, []), _ = b(() => {
    M({ type: "OPEN" }), p?.();
  }, [p]), I = b(() => {
    M({ type: "CLOSE" }), x?.();
  }, [x]), R = b(() => {
    a.isOpen ? I() : _();
  }, [a.isOpen, I, _]), t = ve(() => {
    const u = Array.from(a.commands.values()).filter((w) => !w.hidden);
    if (!a.query.trim()) {
      const w = a.recentIds.map((Y) => a.commands.get(Y)).filter((Y) => !!Y && !Y.hidden), A = u.filter((Y) => !a.recentIds.includes(Y.id));
      return A.sort((Y, ne) => Y.label.localeCompare(ne.label)), [...w, ...A].map((Y) => ({
        command: Y,
        match: null,
        isRecent: a.recentIds.includes(Y.id)
      }));
    }
    return u.map((w) => {
      const A = ze(a.query, w.label), Y = w.description ? ze(a.query, w.description) : null, ne = w.keywords?.map((L) => ze(a.query, L)).filter(Boolean)[0] ?? null, ae = [A, Y, ne].filter(Boolean).sort((L, B) => (B?.score ?? 0) - (L?.score ?? 0))[0];
      return { command: w, match: ae, isRecent: !1 };
    }).filter((w) => w.match !== null).sort((w, A) => (A.match?.score ?? 0) - (w.match?.score ?? 0));
  }, [a.commands, a.query, a.recentIds]).slice(0, i), l = b(
    async (u) => {
      const y = a.commands.get(u);
      if (!(!y || y.disabled)) {
        s(!0);
        try {
          await y.action(), M({ type: "ADD_RECENT", id: u, maxRecent: h });
        } finally {
          s(!1), g && I();
        }
      }
    },
    [a.commands, h, g, I]
  );
  X(() => {
    const u = (y) => {
      (y.metaKey || y.ctrlKey) && y.key === "k" && (y.preventDefault(), R()), y.key === "Escape" && a.isOpen && (y.preventDefault(), I());
    };
    return document.addEventListener("keydown", u), () => document.removeEventListener("keydown", u);
  }, [R, a.isOpen, I]), X(() => {
    a.isOpen && requestAnimationFrame(() => C.current?.focus());
  }, [a.isOpen]);
  const E = b(
    (u) => {
      const y = t.length;
      if (y) {
        if (u.key === "ArrowDown")
          u.preventDefault(), M({ type: "SET_SELECTED", index: (a.selectedIndex + 1) % y });
        else if (u.key === "ArrowUp")
          u.preventDefault(), M({ type: "SET_SELECTED", index: (a.selectedIndex - 1 + y) % y });
        else if (u.key === "Enter") {
          u.preventDefault();
          const w = t[a.selectedIndex];
          w && l(w.command.id);
        }
      }
    },
    [t, a.selectedIndex, l]
  );
  X(() => {
    if (!f.current) return;
    f.current.children[a.selectedIndex]?.scrollIntoView({ block: "nearest" });
  }, [a.selectedIndex]);
  const T = ve(
    () => ({
      registerCommand: k,
      unregisterCommand: c,
      registerCommands: v,
      open: _,
      close: I,
      toggle: R,
      isOpen: a.isOpen,
      executeCommand: l
    }),
    [k, c, v, _, I, R, a.isOpen, l]
  ), P = ve(() => {
    const u = /* @__PURE__ */ new Map();
    for (const y of t) {
      const w = y.command.category ?? "General";
      u.has(w) || u.set(w, []), u.get(w).push(y);
    }
    return u;
  }, [t]);
  let S = 0;
  return /* @__PURE__ */ z(Xe.Provider, { value: T, children: [
    e,
    a.isOpen && /* @__PURE__ */ o("div", { className: `nice-command-palette__overlay ${d ?? ""}`, onClick: I, children: /* @__PURE__ */ z(
      "div",
      {
        className: "nice-command-palette",
        role: "dialog",
        "aria-label": "Command Palette",
        "aria-modal": "true",
        onClick: (u) => u.stopPropagation(),
        children: [
          /* @__PURE__ */ o("div", { className: "nice-command-palette__input-wrapper", children: /* @__PURE__ */ o(
            "input",
            {
              ref: C,
              className: "nice-command-palette__input",
              type: "text",
              placeholder: r,
              value: a.query,
              onChange: (u) => M({ type: "SET_QUERY", query: u.target.value }),
              onKeyDown: E,
              "aria-label": "Search commands",
              "aria-autocomplete": "list",
              "aria-controls": "nice-command-palette-list",
              "aria-activedescendant": t[a.selectedIndex] ? `nice-cmd-${t[a.selectedIndex].command.id}` : void 0
            }
          ) }),
          /* @__PURE__ */ z(
            "div",
            {
              ref: f,
              id: "nice-command-palette-list",
              className: "nice-command-palette__list",
              role: "listbox",
              children: [
                t.length === 0 && /* @__PURE__ */ o("div", { className: "nice-command-palette__empty", children: m }),
                Array.from(P.entries()).map(([u, y]) => /* @__PURE__ */ z("div", { className: "nice-command-palette__group", children: [
                  /* @__PURE__ */ o("div", { className: "nice-command-palette__category", children: u }),
                  y.map((w) => {
                    const A = S++, Y = A === a.selectedIndex;
                    return /* @__PURE__ */ z(
                      "div",
                      {
                        id: `nice-cmd-${w.command.id}`,
                        className: `nice-command-palette__item ${Y ? "nice-command-palette__item--selected" : ""} ${w.command.disabled ? "nice-command-palette__item--disabled" : ""}`,
                        role: "option",
                        "aria-selected": Y,
                        "aria-disabled": w.command.disabled,
                        onClick: () => !w.command.disabled && l(w.command.id),
                        onMouseEnter: () => M({ type: "SET_SELECTED", index: A }),
                        children: [
                          w.command.icon && /* @__PURE__ */ o("span", { className: "nice-command-palette__icon", children: w.command.icon }),
                          /* @__PURE__ */ z("div", { className: "nice-command-palette__label-group", children: [
                            /* @__PURE__ */ o("span", { className: "nice-command-palette__label", children: w.match && a.query ? vt(w.command.label, w.match.indices) : w.command.label }),
                            w.command.description && /* @__PURE__ */ o("span", { className: "nice-command-palette__description", children: w.command.description })
                          ] }),
                          w.command.shortcut && /* @__PURE__ */ o("kbd", { className: "nice-command-palette__shortcut", children: w.command.shortcut }),
                          w.isRecent && /* @__PURE__ */ o("span", { className: "nice-command-palette__recent-badge", children: "Recent" })
                        ]
                      },
                      w.command.id
                    );
                  })
                ] }, u))
              ]
            }
          ),
          N && /* @__PURE__ */ o("div", { className: "nice-command-palette__executing", children: "Executing..." })
        ]
      }
    ) })
  ] });
};
xt.displayName = "NiceCommandPaletteProvider";
function Qt(e) {
  const { registerCommands: n, unregisterCommand: r } = yt();
  X(() => (n(e), () => {
    for (const i of e)
      r(i.id);
  }), []);
}
const Nt = Te(({
  blocked: e,
  message: n,
  children: r,
  className: i,
  style: h,
  id: d
}, m) => {
  const g = Ce(d);
  return /* @__PURE__ */ z(
    "div",
    {
      ref: m,
      id: g,
      className: `nice-block-ui ${i || ""}`,
      style: { position: "relative", ...h },
      children: [
        r,
        e && /* @__PURE__ */ o("div", { className: "nice-block-ui__overlay", "aria-busy": "true", role: "alert", children: n && /* @__PURE__ */ o("div", { className: "nice-block-ui__message", children: n }) })
      ]
    }
  );
});
Nt.displayName = "NiceBlockUI";
const kt = Te(
  ({
    windows: e,
    onChange: n,
    onClose: r,
    onFocus: i,
    showTaskbar: h = !0,
    size: d = "md",
    className: m,
    style: g,
    id: p,
    ...x
  }, a) => {
    const M = Ce(p), { t: C } = be(), [f, N] = D(null), s = q(null), k = Math.max(1, ...e.map((t) => t.zIndex ?? 1)), c = b(
      (t, l) => {
        const E = e.map((T) => T.key === t ? { ...T, ...l } : T);
        n?.(E);
      },
      [e, n]
    ), v = b(
      (t) => {
        c(t, { zIndex: k + 1 }), i?.(t);
      },
      [c, k, i]
    ), _ = b(
      (t) => {
        r?.(t), n?.(e.filter((l) => l.key !== t));
      },
      [e, n, r]
    ), I = b(
      (t) => {
        const l = e.find((E) => E.key === t);
        l && c(t, { minimized: !l.minimized, maximized: !1 });
      },
      [e, c]
    ), R = b(
      (t) => {
        const l = e.find((E) => E.key === t);
        l && c(t, { maximized: !l.maximized, minimized: !1 });
      },
      [e, c]
    );
    X(() => {
      if (!f) return;
      const t = (E) => {
        const T = e.find((P) => P.key === f.key);
        if (T)
          if (f.mode === "move")
            c(f.key, {
              x: E.clientX - f.offsetX,
              y: E.clientY - f.offsetY
            });
          else {
            const S = s.current?.getBoundingClientRect(), u = S?.left ?? 0, y = S?.top ?? 0;
            c(f.key, {
              width: Math.max(200, E.clientX - u - T.x),
              height: Math.max(100, E.clientY - y - T.y)
            });
          }
      }, l = () => N(null);
      return document.addEventListener("mousemove", t), document.addEventListener("mouseup", l), () => {
        document.removeEventListener("mousemove", t), document.removeEventListener("mouseup", l);
      };
    }, [f, e, c]);
    const O = b(
      (t, l, E) => {
        l.preventDefault();
        const T = e.find((P) => P.key === t);
        T && (v(t), N({
          key: t,
          offsetX: E === "move" ? l.clientX - T.x : 0,
          offsetY: E === "move" ? l.clientY - T.y : 0,
          mode: E
        }));
      },
      [e, v]
    );
    return /* @__PURE__ */ z(
      "div",
      {
        ref: (t) => {
          s.current = t, typeof a == "function" ? a(t) : a && (a.current = t);
        },
        id: M,
        className: `nice-wm nice-wm--${d} ${m ?? ""}`,
        style: { ...g, position: "relative", overflow: "hidden" },
        ...x,
        children: [
          e.map((t) => {
            if (t.minimized) return null;
            const l = t.maximized, E = l ? { position: "absolute", top: 0, left: 0, width: "100%", height: "100%", zIndex: t.zIndex ?? 1 } : { position: "absolute", top: t.y, left: t.x, width: t.width, height: t.height, zIndex: t.zIndex ?? 1 };
            return /* @__PURE__ */ z(
              "div",
              {
                className: `nice-wm__window ${l ? "nice-wm__window--maximized" : ""}`,
                style: E,
                onMouseDown: () => v(t.key),
                role: "dialog",
                "aria-label": t.title,
                children: [
                  /* @__PURE__ */ z(
                    "div",
                    {
                      className: "nice-wm__titlebar",
                      onMouseDown: (T) => !l && O(t.key, T, "move"),
                      children: [
                        t.icon && /* @__PURE__ */ o("span", { className: "nice-wm__icon", children: t.icon }),
                        /* @__PURE__ */ o("span", { className: "nice-wm__title", children: t.title }),
                        /* @__PURE__ */ z("div", { className: "nice-wm__controls", children: [
                          (t.minimizable ?? !0) && /* @__PURE__ */ o("button", { type: "button", className: "nice-wm__ctrl-btn nice-wm__ctrl-btn--min", onClick: () => I(t.key), title: C("wm.minimize", "Minimize"), children: "─" }),
                          (t.maximizable ?? !0) && /* @__PURE__ */ o("button", { type: "button", className: "nice-wm__ctrl-btn nice-wm__ctrl-btn--max", onClick: () => R(t.key), title: C("wm.maximize", "Maximize"), children: l ? "❐" : "☐" }),
                          (t.closable ?? !0) && /* @__PURE__ */ o("button", { type: "button", className: "nice-wm__ctrl-btn nice-wm__ctrl-btn--close", onClick: () => _(t.key), title: C("wm.close", "Close"), children: "✕" })
                        ] })
                      ]
                    }
                  ),
                  /* @__PURE__ */ o("div", { className: "nice-wm__body", children: t.content }),
                  (t.resizable ?? !0) && !l && /* @__PURE__ */ o(
                    "div",
                    {
                      className: "nice-wm__resize-handle",
                      onMouseDown: (T) => O(t.key, T, "resize")
                    }
                  )
                ]
              },
              t.key
            );
          }),
          h && /* @__PURE__ */ o("div", { className: "nice-wm__taskbar", role: "toolbar", "aria-label": C("wm.taskbar", "Taskbar"), children: e.map((t) => /* @__PURE__ */ z(
            "button",
            {
              type: "button",
              className: `nice-wm__taskbar-btn ${t.minimized ? "nice-wm__taskbar-btn--minimized" : ""}`,
              onClick: () => {
                t.minimized && I(t.key), v(t.key);
              },
              children: [
                t.icon && /* @__PURE__ */ o("span", { className: "nice-wm__taskbar-icon", children: t.icon }),
                /* @__PURE__ */ o("span", { className: "nice-wm__taskbar-label", children: t.title })
              ]
            },
            t.key
          )) })
        ]
      }
    );
  }
);
kt.displayName = "NiceWindowManager";
function Et(e, n) {
  const r = document.querySelector(e);
  if (!r) return null;
  const i = r.getBoundingClientRect();
  return {
    top: i.top - n + window.scrollY,
    left: i.left - n + window.scrollX,
    width: i.width + n * 2,
    height: i.height + n * 2
  };
}
function Mt(e, n, r, i) {
  const d = { w: window.innerWidth, h: window.innerHeight + window.scrollY }, m = {
    top: { top: e.top - r - 12, left: e.left + e.width / 2 - n / 2 },
    bottom: { top: e.top + e.height + 12, left: e.left + e.width / 2 - n / 2 },
    left: { top: e.top + e.height / 2 - r / 2, left: e.left - n - 12 },
    right: { top: e.top + e.height / 2 - r / 2, left: e.left + e.width + 12 }
  };
  if (i && i !== "auto")
    return { ...m[i], actualPlacement: i };
  for (const g of ["bottom", "top", "right", "left"]) {
    const p = m[g];
    if (p.top >= 0 && p.left >= 0 && p.top + r <= d.h && p.left + n <= d.w)
      return { ...p, actualPlacement: g };
  }
  return { ...m.bottom, actualPlacement: "bottom" };
}
const Oe = ({
  steps: e,
  active: n,
  onFinish: r,
  onSkip: i,
  onStepChange: h,
  closeOnEscape: d = !0,
  closeOnOverlayClick: m = !1,
  showProgress: g = !0,
  showSkipButton: p = !0,
  labels: x,
  animationDuration: a = 300,
  overlayOpacity: M = 0.6,
  zIndex: C = 1e4
}) => {
  const [f, N] = D(0), [s, k] = D(null), [c, v] = D({ w: 340, h: 200 }), [_, I] = D(!0), R = q(null), O = q(-1), t = e[f], l = f === e.length - 1, E = f === 0, T = x?.next ?? "Next", P = x?.back ?? "Back", S = x?.finish ?? "Finish", u = x?.skip ?? "Skip", y = x?.stepOf ?? "of";
  X(() => {
    if (R.current) {
      const L = R.current.getBoundingClientRect();
      v({ w: L.width, h: L.height });
    }
  }, [f, n]), X(() => {
    if (!n || !t) return;
    const L = () => {
      const B = Et(t.target, t.highlightPadding ?? 8);
      k(B);
    };
    if (L(), t.scrollIntoView !== !1) {
      document.querySelector(t.target)?.scrollIntoView({ behavior: "smooth", block: "center" });
      const ye = setTimeout(L, 350);
      return () => clearTimeout(ye);
    }
  }, [n, t, f]), X(() => {
    !n || !t || O.current !== f && (O.current >= 0 && O.current < e.length && e[O.current]?.onLeave?.(), t.onEnter?.(), O.current = f);
  }, [n, t, f, e]), X(() => {
    if (!n || !t?.advanceOn) return;
    const L = document.querySelector(t.target);
    if (!L) return;
    const B = () => w();
    return L.addEventListener(t.advanceOn.event, B), () => L.removeEventListener(t.advanceOn.event, B);
  }, [n, t, f]), X(() => {
    if (!n) return;
    const L = (B) => {
      B.key === "Escape" && d ? i?.() : B.key === "ArrowRight" ? w() : B.key === "ArrowLeft" && A();
    };
    return document.addEventListener("keydown", L), () => document.removeEventListener("keydown", L);
  }, [n, f, d]), X(() => {
    I(!0);
    const L = setTimeout(() => I(!1), a);
    return () => clearTimeout(L);
  }, [f, a]);
  const w = b(() => {
    if (l)
      t?.onLeave?.(), r?.();
    else {
      const L = f + 1;
      N(L), h?.(L);
    }
  }, [f, l, r, h, t]), A = b(() => {
    if (!E) {
      const L = f - 1;
      N(L), h?.(L);
    }
  }, [f, E, h]), Y = ve(() => s ? Mt(s, c.w, c.h, t?.placement) : { top: window.innerHeight / 2, left: window.innerWidth / 2, actualPlacement: "bottom" }, [s, c, t?.placement]);
  if (!n || !t) return null;
  const ne = Math.max(document.documentElement.scrollWidth, window.innerWidth), ae = Math.max(document.documentElement.scrollHeight, window.innerHeight);
  return /* @__PURE__ */ z("div", { className: "nice-tutorial", style: { zIndex: C }, "aria-modal": "true", role: "dialog", "aria-label": "Tutorial", children: [
    /* @__PURE__ */ z(
      "svg",
      {
        className: "nice-tutorial__overlay",
        style: { position: "absolute", top: 0, left: 0, width: ne, height: ae, pointerEvents: "auto" },
        onClick: m ? i : void 0,
        children: [
          /* @__PURE__ */ o("defs", { children: /* @__PURE__ */ z("mask", { id: "nice-tutorial-mask", children: [
            /* @__PURE__ */ o("rect", { x: "0", y: "0", width: "100%", height: "100%", fill: "white" }),
            s && /* @__PURE__ */ o(
              "rect",
              {
                x: s.left,
                y: s.top,
                width: s.width,
                height: s.height,
                rx: "8",
                fill: "black",
                className: _ ? "nice-tutorial__spotlight--entering" : ""
              }
            )
          ] }) }),
          /* @__PURE__ */ o(
            "rect",
            {
              x: "0",
              y: "0",
              width: "100%",
              height: "100%",
              fill: `rgba(0,0,0,${M})`,
              mask: "url(#nice-tutorial-mask)"
            }
          )
        ]
      }
    ),
    s && /* @__PURE__ */ o(
      "div",
      {
        className: `nice-tutorial__highlight ${_ ? "nice-tutorial__highlight--entering" : ""}`,
        style: {
          position: "absolute",
          top: s.top,
          left: s.left,
          width: s.width,
          height: s.height,
          transition: `all ${a}ms ease`
        }
      }
    ),
    t.disableInteraction && s && /* @__PURE__ */ o(
      "div",
      {
        className: "nice-tutorial__blocker",
        style: {
          position: "absolute",
          top: s.top,
          left: s.left,
          width: s.width,
          height: s.height
        }
      }
    ),
    /* @__PURE__ */ z(
      "div",
      {
        ref: R,
        className: `nice-tutorial__tooltip nice-tutorial__tooltip--${Y.actualPlacement} ${_ ? "nice-tutorial__tooltip--entering" : ""}`,
        style: {
          position: "absolute",
          top: Y.top,
          left: Y.left,
          transition: `all ${a}ms ease`,
          maxWidth: 380,
          zIndex: C + 1
        },
        children: [
          t.showArrow !== !1 && /* @__PURE__ */ o("div", { className: `nice-tutorial__arrow nice-tutorial__arrow--${Y.actualPlacement}` }),
          /* @__PURE__ */ z("div", { className: "nice-tutorial__header", children: [
            /* @__PURE__ */ o("h4", { className: "nice-tutorial__title", children: t.title }),
            p && /* @__PURE__ */ o(
              "button",
              {
                type: "button",
                className: "nice-tutorial__close",
                onClick: i,
                "aria-label": u,
                children: "✕"
              }
            )
          ] }),
          /* @__PURE__ */ o("div", { className: "nice-tutorial__content", dangerouslySetInnerHTML: { __html: pt(t.content) } }),
          /* @__PURE__ */ z("div", { className: "nice-tutorial__footer", children: [
            g && /* @__PURE__ */ z("div", { className: "nice-tutorial__progress", children: [
              e.map((L, B) => /* @__PURE__ */ o(
                "span",
                {
                  className: `nice-tutorial__dot ${B === f ? "nice-tutorial__dot--active" : ""} ${B < f ? "nice-tutorial__dot--done" : ""}`
                },
                B
              )),
              /* @__PURE__ */ z("span", { className: "nice-tutorial__step-label", children: [
                f + 1,
                " ",
                y,
                " ",
                e.length
              ] })
            ] }),
            /* @__PURE__ */ z("div", { className: "nice-tutorial__actions", children: [
              p && !l && /* @__PURE__ */ o("button", { type: "button", className: "nice-tutorial__btn nice-tutorial__btn--skip", onClick: i, children: u }),
              !E && /* @__PURE__ */ o("button", { type: "button", className: "nice-tutorial__btn nice-tutorial__btn--back", onClick: A, children: P }),
              !t.waitForAction && /* @__PURE__ */ o("button", { type: "button", className: "nice-tutorial__btn nice-tutorial__btn--next", onClick: w, children: l ? S : T })
            ] })
          ] })
        ]
      }
    )
  ] });
};
Oe.displayName = "NiceTutorial";
const He = Ye({
  startTutorial: () => {
  },
  stopTutorial: () => {
  },
  isActive: !1,
  currentStep: 0,
  nextStep: () => {
  },
  prevStep: () => {
  },
  goToStep: () => {
  }
});
function Zt() {
  return Pe(He);
}
const zt = ({ children: e }) => {
  const [n, r] = D([]), [i, h] = D(!1), [d, m] = D(0), g = b((f) => {
    r(f), m(0), h(!0);
  }, []), p = b(() => {
    h(!1), m(0), r([]);
  }, []), x = b(() => {
    m((f) => Math.min(f + 1, n.length - 1));
  }, [n.length]), a = b(() => {
    m((f) => Math.max(f - 1, 0));
  }, []), M = b((f) => {
    m(Math.max(0, Math.min(f, n.length - 1)));
  }, [n.length]), C = {
    startTutorial: g,
    stopTutorial: p,
    isActive: i,
    currentStep: d,
    nextStep: x,
    prevStep: a,
    goToStep: M
  };
  return /* @__PURE__ */ z(He.Provider, { value: C, children: [
    e,
    i && n.length > 0 && /* @__PURE__ */ o(
      Oe,
      {
        steps: n,
        active: i,
        onFinish: p,
        onSkip: p,
        onStepChange: m
      }
    )
  ] });
};
zt.displayName = "NiceTutorialProvider";
function It(e, n, r, i, h) {
  const d = e <= h, m = e + h >= r, g = n <= h, p = n + h >= i;
  return g && d ? "top-left" : g && m ? "top-right" : p && d ? "bottom-left" : p && m ? "bottom-right" : d ? "left" : m ? "right" : g ? "top" : p ? "bottom" : "none";
}
function Ct(e) {
  switch (e) {
    case "left":
      return { left: 0, top: 0, width: "50%", height: "100%" };
    case "right":
      return { left: "50%", top: 0, width: "50%", height: "100%" };
    case "top":
      return { left: 0, top: 0, width: "100%", height: "50%" };
    case "bottom":
      return { left: 0, top: "50%", width: "100%", height: "50%" };
    case "top-left":
      return { left: 0, top: 0, width: "50%", height: "50%" };
    case "top-right":
      return { left: "50%", top: 0, width: "50%", height: "50%" };
    case "bottom-left":
      return { left: 0, top: "50%", width: "50%", height: "50%" };
    case "bottom-right":
      return { left: "50%", top: "50%", width: "50%", height: "50%" };
    default:
      return null;
  }
}
const Tt = Te(
  ({
    windowKey: e,
    title: n,
    icon: r,
    children: i,
    footer: h,
    x: d = 100,
    y: m = 100,
    width: g = 480,
    height: p = 360,
    minWidth: x = 200,
    minHeight: a = 120,
    maxWidth: M,
    maxHeight: C,
    zIndex: f = 1,
    closable: N = !0,
    minimizable: s = !0,
    maximizable: k = !0,
    fullscreenable: c = !1,
    pinnable: v = !1,
    resizable: _ = !0,
    draggable: I = !0,
    snappable: R = !0,
    snapThreshold: O = 20,
    minimized: t,
    maximized: l,
    fullscreen: E,
    pinned: T,
    focused: P,
    onClose: S,
    onMinimize: u,
    onMaximize: y,
    onFullscreen: w,
    onPin: A,
    onFocus: Y,
    onMove: ne,
    onResize: ae,
    onSnap: L,
    onTitleBarDoubleClick: B,
    size: ye = "md",
    statusBar: Re,
    titleBarActions: qe,
    className: Be,
    style: Ae,
    id: $e,
    accessMode: We,
    ...Fe
  }, Ue) => {
    const Ge = Ce($e), Ve = _t(We, $e), { t: le } = be();
    if (Ve === "hidden") return null;
    const [pe, re] = D({ x: d, y: m }), [_e, ge] = D({ width: g, height: p }), [je, Qe] = D(!1), [Ze, Je] = D(!1), [Ke, et] = D(!1), [tt, nt] = D(!1), [V, xe] = D("none"), it = t ?? je, G = l ?? Ze, U = E ?? Ke, de = T ?? tt, Ne = P ?? !0, ie = pe.x, oe = pe.y, Z = _e.width, J = _e.height, j = q(null), F = q(null), H = q(null), ot = b(() => {
      S?.(e);
    }, [e, S]), rt = b(() => {
      Qe(!0), u?.(e);
    }, [e, u]), ke = b(() => {
      const $ = !G;
      Je($), !$ && H.current ? (re({ x: H.current.x, y: H.current.y }), ge({ width: H.current.w, height: H.current.h }), H.current = null) : $ && (H.current = { x: ie, y: oe, w: Z, h: J }), xe("none"), y?.(e, $);
    }, [e, G, ie, oe, Z, J, y]), Ee = b(() => {
      const $ = !U;
      et($), $ ? H.current = { x: ie, y: oe, w: Z, h: J } : H.current && (re({ x: H.current.x, y: H.current.y }), ge({ width: H.current.w, height: H.current.h }), H.current = null), w?.(e, $);
    }, [e, U, ie, oe, Z, J, w]), ct = b(() => {
      const $ = !de;
      nt($), A?.(e, $);
    }, [e, de, A]), ue = b(() => {
      Y?.(e);
    }, [e, Y]), st = b(() => {
      B ? B(e) : k && ke();
    }, [e, k, ke, B]);
    X(() => {
      if (!j.current) return;
      const $ = (K) => {
        if (!j.current) return;
        const Q = K.clientX - j.current.startX + j.current.origX, me = K.clientY - j.current.startY + j.current.origY;
        re({ x: Q, y: me }), ne?.(e, { x: Q, y: me });
      }, W = (K) => {
        if (j.current) {
          if (R) {
            const Q = It(K.clientX, K.clientY, window.innerWidth, window.innerHeight, O);
            Q !== "none" && (H.current = { x: pe.x, y: pe.y, w: Z, h: J }, xe(Q), L?.(e, Q));
          }
          j.current = null;
        }
      };
      return document.addEventListener("mousemove", $), document.addEventListener("mouseup", W), () => {
        document.removeEventListener("mousemove", $), document.removeEventListener("mouseup", W);
      };
    });
    const at = b(
      ($) => {
        !I || G || U || ($.preventDefault(), V !== "none" && (H.current && (re({ x: H.current.x, y: H.current.y }), ge({ width: H.current.w, height: H.current.h })), xe("none")), ue(), j.current = { startX: $.clientX, startY: $.clientY, origX: ie, origY: oe });
      },
      [I, G, U, V, ie, oe, ue]
    );
    X(() => {
      if (!F.current) return;
      const $ = (K) => {
        if (!F.current) return;
        const Q = K.clientX - F.current.startX, me = K.clientY - F.current.startY, ce = F.current.handle;
        let ee = F.current.origW, te = F.current.origH;
        if (ce.includes("e") && (ee = F.current.origW + Q), ce.includes("w") && (ee = F.current.origW - Q), ce.includes("s") && (te = F.current.origH + me), ce.includes("n") && (te = F.current.origH - me), ee = Math.max(x, M ? Math.min(M, ee) : ee), te = Math.max(a, C ? Math.min(C, te) : te), ce.includes("w")) {
          const Me = _e.width - ee;
          re((he) => ({ ...he, x: he.x + Me }));
        }
        if (ce.includes("n")) {
          const Me = _e.height - te;
          re((he) => ({ ...he, y: he.y + Me }));
        }
        ge({ width: ee, height: te }), ae?.(e, { width: ee, height: te });
      }, W = () => {
        F.current = null;
      };
      return document.addEventListener("mousemove", $), document.addEventListener("mouseup", W), () => {
        document.removeEventListener("mousemove", $), document.removeEventListener("mouseup", W);
      };
    });
    const lt = b(
      ($, W) => {
        !_ || G || U || V !== "none" || (W.preventDefault(), W.stopPropagation(), ue(), F.current = { startX: W.clientX, startY: W.clientY, origW: Z, origH: J, handle: $ });
      },
      [_, G, U, V, Z, J, ue]
    );
    if (X(() => {
      if (!Ne) return;
      const $ = (W) => {
        W.key === "Escape" && U && Ee();
      };
      return document.addEventListener("keydown", $), () => document.removeEventListener("keydown", $);
    }, [Ne, U, Ee]), it) return null;
    const Se = V !== "none" ? Ct(V) : null, Le = G || U, dt = U ? { position: "fixed", top: 0, left: 0, width: "100vw", height: "100vh", zIndex: 999999 } : G ? { position: "absolute", top: 0, left: 0, width: "100%", height: "100%", zIndex: f } : Se ? { position: "absolute", ...Se, zIndex: f } : { position: "absolute", top: oe, left: ie, width: Z, height: J, zIndex: f }, ut = ["n", "e", "s", "w", "ne", "se", "sw", "nw"], mt = {
      n: "ns-resize",
      s: "ns-resize",
      e: "ew-resize",
      w: "ew-resize",
      ne: "nesw-resize",
      sw: "nesw-resize",
      nw: "nwse-resize",
      se: "nwse-resize"
    };
    return /* @__PURE__ */ z(
      "div",
      {
        ref: Ue,
        id: Ge,
        className: `nice-window nice-window--${ye} ${Ne ? "nice-window--focused" : ""} ${de ? "nice-window--pinned" : ""} ${Le ? "nice-window--maximized" : ""} ${V !== "none" ? `nice-window--snapped-${V}` : ""} ${Be ?? ""}`,
        style: { ...dt, ...Ae },
        onMouseDown: ue,
        role: "dialog",
        "aria-label": n,
        ...Fe,
        children: [
          /* @__PURE__ */ z(
            "div",
            {
              className: "nice-window__titlebar",
              onMouseDown: at,
              onDoubleClick: st,
              children: [
                r && /* @__PURE__ */ o("span", { className: "nice-window__icon", children: r }),
                /* @__PURE__ */ o("span", { className: "nice-window__title", children: n }),
                /* @__PURE__ */ z("div", { className: "nice-window__actions", children: [
                  qe,
                  v && /* @__PURE__ */ o(
                    "button",
                    {
                      type: "button",
                      className: `nice-window__action nice-window__action--pin ${de ? "nice-window__action--active" : ""}`,
                      onClick: ct,
                      title: le("window.pin", de ? "Unpin" : "Pin"),
                      children: "📌"
                    }
                  ),
                  s && /* @__PURE__ */ o(
                    "button",
                    {
                      type: "button",
                      className: "nice-window__action nice-window__action--minimize",
                      onClick: rt,
                      title: le("window.minimize", "Minimize"),
                      children: "─"
                    }
                  ),
                  k && /* @__PURE__ */ o(
                    "button",
                    {
                      type: "button",
                      className: "nice-window__action nice-window__action--maximize",
                      onClick: ke,
                      title: le("window.maximize", G ? "Restore" : "Maximize"),
                      children: G ? "❐" : "☐"
                    }
                  ),
                  c && /* @__PURE__ */ o(
                    "button",
                    {
                      type: "button",
                      className: "nice-window__action nice-window__action--fullscreen",
                      onClick: Ee,
                      title: le("window.fullscreen", U ? "Exit Full Screen" : "Full Screen"),
                      children: U ? "⇲" : "⇱"
                    }
                  ),
                  N && /* @__PURE__ */ o(
                    "button",
                    {
                      type: "button",
                      className: "nice-window__action nice-window__action--close",
                      onClick: ot,
                      title: le("window.close", "Close"),
                      children: "✕"
                    }
                  )
                ] })
              ]
            }
          ),
          /* @__PURE__ */ o("div", { className: "nice-window__body", children: i }),
          h && /* @__PURE__ */ o("div", { className: "nice-window__footer", children: h }),
          Re && /* @__PURE__ */ o("div", { className: "nice-window__statusbar", children: Re }),
          _ && !Le && V === "none" && /* @__PURE__ */ o(se, { children: ut.map(($) => /* @__PURE__ */ o(
            "div",
            {
              className: `nice-window__resize nice-window__resize--${$}`,
              style: { cursor: mt[$] },
              onMouseDown: (W) => lt($, W)
            },
            $
          )) })
        ]
      }
    );
  }
);
Tt.displayName = "NiceWindow";
export {
  Dt as N,
  Nt as a,
  qt as b,
  Ut as c,
  xt as d,
  At as e,
  Ht as f,
  Ft as g,
  Pt as h,
  Xt as i,
  Ot as j,
  Yt as k,
  Bt as l,
  Wt as m,
  Vt as n,
  Gt as o,
  jt as p,
  Oe as q,
  zt as r,
  Tt as s,
  kt as t,
  yt as u,
  Qt as v,
  ze as w,
  vt as x,
  Zt as y
};
