import { N as se, a as de, b as ue, c as he, d as fe, e as me, f as ve, g as ge, h as we, i as be, j as ye, k as pe, l as Ne, u as _e, m as ke } from "./NiceWindow-DeC83yfE.js";
import { jsxs as C, Fragment as K, jsx as a } from "react/jsx-runtime";
import { useRef as E, useState as P, useEffect as Y, useCallback as b, useContext as U } from "react";
import { createPortal as X } from "react-dom";
import { e as j, t as W, f as z, g as V, N as q } from "./core-Da43q-pO.js";
function O() {
  const e = U(q);
  return e?.portalTarget ? e.portalTarget : typeof document < "u" ? document.body : null;
}
const Z = ({
  open: e,
  onClose: o,
  children: m,
  title: r,
  size: v = "md",
  closeOnBackdropClick: l = !0,
  closeOnEscape: s = !0,
  disableFocusTrap: d = !1,
  disableBodyScroll: x = !0,
  zIndex: _ = 1e3,
  className: k,
  style: M
}) => {
  const y = E(null);
  j(y, e && !d);
  const p = O();
  Y(() => {
    if (!x && e) {
      const t = document.body.style.overflow;
      return document.body.style.overflow = "hidden", () => {
        document.body.style.overflow = t;
      };
    }
  }, [e, x]), Y(() => {
    if (!s || !e)
      return;
    const t = (g) => {
      g.key === "Escape" && (g.preventDefault(), o());
    };
    return document.addEventListener("keydown", t), () => document.removeEventListener("keydown", t);
  }, [s, e, o]);
  const u = b(
    (t) => {
      l && t.target === t.currentTarget && o();
    },
    [l, o]
  );
  if (!e)
    return null;
  const c = {
    sm: "nice-modal--sm",
    md: "nice-modal--md",
    lg: "nice-modal--lg",
    xl: "nice-modal--xl",
    full: "nice-modal--full"
  }[v];
  return X(
    /* @__PURE__ */ a(
      "div",
      {
        className: "nice-modal__overlay",
        style: { zIndex: _ },
        onClick: u,
        role: "presentation",
        children: /* @__PURE__ */ a(
          "div",
          {
            ref: y,
            className: `nice-modal ${c} ${k || ""}`,
            role: "dialog",
            "aria-modal": "true",
            "aria-label": r,
            style: M,
            tabIndex: -1,
            children: m
          }
        )
      }
    ),
    p
  );
}, ee = ({
  children: e,
  showClose: o = !0,
  onClose: m,
  className: r
}) => /* @__PURE__ */ C("div", { className: `nice-modal__header ${r || ""}`, children: [
  /* @__PURE__ */ a("div", { className: "nice-modal__title", children: e }),
  o && m && /* @__PURE__ */ a("button", { type: "button", className: "nice-modal__close", onClick: m, "aria-label": "Close", children: /* @__PURE__ */ a(
    "svg",
    {
      width: "20",
      height: "20",
      viewBox: "0 0 20 20",
      fill: "none",
      stroke: "currentColor",
      strokeWidth: "2",
      children: /* @__PURE__ */ a("path", { d: "M4 4l12 12M4 16L16 4" })
    }
  ) })
] }), te = ({ children: e, className: o }) => /* @__PURE__ */ a("div", { className: `nice-modal__body ${o || ""}`, children: e }), ne = ({ children: e, className: o }) => /* @__PURE__ */ a("div", { className: `nice-modal__footer ${o || ""}`, children: e }), re = ({
  open: e,
  onClose: o,
  children: m,
  position: r = "right",
  size: v = 320,
  title: l,
  closeOnBackdropClick: s = !0,
  closeOnEscape: d = !0,
  swipeToClose: x = !0,
  zIndex: _ = 1e3,
  className: k,
  style: M
}) => {
  const y = E(null), [p, u] = P(!1), [c, t] = P(0);
  j(y, e);
  const g = O();
  Y(() => {
    if (!d || !e)
      return;
    const n = (N) => {
      N.key === "Escape" && (N.preventDefault(), o());
    };
    return document.addEventListener("keydown", n), () => document.removeEventListener("keydown", n);
  }, [d, e, o]);
  const h = b(
    (n) => {
      let N = 0;
      switch (r) {
        case "left":
          N = Math.min(0, n.deltaX);
          break;
        case "right":
          N = Math.max(0, n.deltaX);
          break;
        case "top":
          N = Math.min(0, n.deltaY);
          break;
        case "bottom":
          N = Math.max(0, n.deltaY);
          break;
      }
      t(N);
    },
    [r]
  ), H = b(
    (n) => {
      let R = !1;
      switch (r) {
        case "left":
          R = n.deltaX < -100;
          break;
        case "right":
          R = n.deltaX > 100;
          break;
        case "top":
          R = n.deltaY < -100;
          break;
        case "bottom":
          R = n.deltaY > 100;
          break;
      }
      R && (W("light"), o()), t(0), u(!1);
    },
    [r, o]
  ), { ref: D } = V({
    enabled: x && e,
    onPanStart: () => u(!0),
    onPan: h,
    onPanEnd: H
  }), L = b(
    (n) => {
      s && n.target === n.currentTarget && o();
    },
    [s, o]
  );
  if (!e)
    return null;
  const I = r === "left" || r === "right", S = I ? { width: typeof v == "number" ? `${v}px` : v } : { height: typeof v == "number" ? `${v}px` : v }, i = () => {
    if (p)
      return I ? `translateX(${c}px)` : `translateY(${c}px)`;
  };
  return X(
    /* @__PURE__ */ C(K, { children: [
      /* @__PURE__ */ a(
        "div",
        {
          className: `nice-drawer__overlay ${e ? "nice-drawer__overlay--visible" : ""}`,
          style: { zIndex: _ },
          onClick: L
        }
      ),
      /* @__PURE__ */ a(
        "div",
        {
          ref: (n) => {
            y.current = n, D.current = n;
          },
          className: `nice-drawer nice-drawer--${r} ${e ? "nice-drawer--open" : ""} ${k || ""}`,
          style: {
            ...S,
            zIndex: _ + 1,
            transform: i(),
            transition: p ? "none" : void 0,
            ...M
          },
          role: "dialog",
          "aria-modal": "true",
          "aria-label": l,
          tabIndex: -1,
          children: m
        }
      )
    ] }),
    g
  );
}, oe = ({
  open: e,
  onClose: o,
  children: m,
  title: r,
  showHandle: v = !0,
  snapPoints: l = [0.5, 0.9],
  initialSnap: s = 0,
  expandable: d = !0,
  closeOnBackdropClick: x = !0,
  closeOnEscape: _ = !0,
  hapticFeedback: k = !0,
  zIndex: M = 1e3,
  className: y,
  style: p
}) => {
  const u = E(null), c = E(null), [t, g] = P(s), [h, H] = P(!1), [D, L] = P(0), I = E(0);
  Y(() => {
    e && (g(s), L(0));
  }, [e, s]), j(u, e);
  const S = O();
  Y(() => {
    if (!_ || !e)
      return;
    const f = (w) => {
      w.key === "Escape" && (w.preventDefault(), o());
    };
    return document.addEventListener("keydown", f), () => document.removeEventListener("keydown", f);
  }, [_, e, o]), Y(() => {
    if (e) {
      const f = document.body.style.overflow;
      return document.body.style.overflow = "hidden", () => {
        document.body.style.overflow = f;
      };
    }
  }, [e]);
  const i = b((f) => {
    const w = f.target.closest(".nice-bottom-sheet__handle"), B = c.current, A = !B || B.scrollTop <= 0;
    !w && !A || (H(!0), I.current = f.touches[0].clientY);
  }, []), n = b(
    (f) => {
      if (!h)
        return;
      const w = f.touches[0].clientY - I.current;
      (w > 0 || t < l.length - 1) && L(w);
    },
    [h, t, l.length]
  ), N = b(() => {
    if (!h)
      return;
    const f = window.innerHeight;
    l[t] * f;
    const w = -D, B = f * 0.15;
    w > B && d && t < l.length - 1 ? (g(t + 1), k && W("selection")) : w < -B && (t > 0 ? (g(t - 1), k && W("selection")) : (k && W("light"), o())), H(!1), L(0);
  }, [h, D, t, l, d, k, o]), R = b(() => {
    x && o();
  }, [x, o]);
  if (!e)
    return null;
  const T = l[t] * 100, $ = h ? D : 0;
  return X(
    /* @__PURE__ */ C(K, { children: [
      /* @__PURE__ */ a(
        "div",
        {
          className: `nice-bottom-sheet__overlay ${e ? "nice-bottom-sheet__overlay--visible" : ""}`,
          style: { zIndex: M },
          onClick: R
        }
      ),
      /* @__PURE__ */ C(
        "div",
        {
          ref: u,
          className: `nice-bottom-sheet ${e ? "nice-bottom-sheet--open" : ""} ${y || ""}`,
          style: {
            zIndex: M + 1,
            height: `${T}vh`,
            transform: `translateY(${Math.max(0, $)}px)`,
            transition: h ? "none" : "transform 0.3s ease-out, height 0.3s ease-out",
            ...p
          },
          role: "dialog",
          "aria-modal": "true",
          "aria-label": r,
          tabIndex: -1,
          onTouchStart: i,
          onTouchMove: n,
          onTouchEnd: N,
          children: [
            v && /* @__PURE__ */ a("div", { className: "nice-bottom-sheet__handle", "aria-hidden": "true" }),
            r && /* @__PURE__ */ a("div", { className: "nice-bottom-sheet__title", children: r }),
            /* @__PURE__ */ a("div", { ref: c, className: "nice-bottom-sheet__content", children: m })
          ]
        }
      )
    ] }),
    S
  );
}, ae = ({
  trigger: e,
  children: o,
  placement: m = "bottom",
  triggerMode: r = "click",
  open: v,
  onOpenChange: l,
  hoverDelay: s = 200,
  offset: d = 8,
  className: x,
  showArrow: _ = !0
}) => {
  const [k, M] = P(!1), y = E(null), p = E(null), u = E(null), c = O(), t = v !== void 0, g = t ? v : k, h = b(
    (i) => {
      t || M(i), l?.(i);
    },
    [t, l]
  );
  z(p, () => {
    r !== "manual" && g && h(!1);
  });
  const H = b(() => {
    r === "click" && h(!g);
  }, [r, g, h]), D = b(() => {
    r === "hover" && (u.current && window.clearTimeout(u.current), u.current = window.setTimeout(() => h(!0), s));
  }, [r, s, h]), L = b(() => {
    r === "hover" && (u.current && window.clearTimeout(u.current), u.current = window.setTimeout(() => h(!1), s));
  }, [r, s, h]), [I, S] = P({ top: 0, left: 0 });
  return Y(() => {
    if (!g || !y.current || !p.current)
      return;
    const i = y.current.getBoundingClientRect(), n = p.current.getBoundingClientRect(), N = window.innerWidth, R = window.innerHeight;
    let T = 0, $ = 0;
    const [f, w = "center"] = m.split("-");
    switch (f) {
      case "top":
        T = i.top - n.height - d, $ = i.left + (i.width - n.width) / 2;
        break;
      case "bottom":
        T = i.bottom + d, $ = i.left + (i.width - n.width) / 2;
        break;
      case "left":
        T = i.top + (i.height - n.height) / 2, $ = i.left - n.width - d;
        break;
      case "right":
        T = i.top + (i.height - n.height) / 2, $ = i.right + d;
        break;
    }
    f === "top" || f === "bottom" ? (w === "start" && ($ = i.left), w === "end" && ($ = i.right - n.width)) : (w === "start" && (T = i.top), w === "end" && (T = i.bottom - n.height)), $ = Math.max(8, Math.min(N - n.width - 8, $)), T = Math.max(8, Math.min(R - n.height - 8, T)), S({ top: T, left: $ });
  }, [g, m, d]), /* @__PURE__ */ C(K, { children: [
    /* @__PURE__ */ a(
      "div",
      {
        ref: y,
        className: "nice-popover__trigger",
        onClick: H,
        onMouseEnter: D,
        onMouseLeave: L,
        style: { display: "inline-block" },
        children: e
      }
    ),
    g && X(
      /* @__PURE__ */ C(
        "div",
        {
          ref: p,
          className: `nice-popover nice-popover--${m} ${x || ""}`,
          style: {
            position: "fixed",
            top: I.top,
            left: I.left,
            zIndex: 1100
          },
          onMouseEnter: D,
          onMouseLeave: L,
          role: "tooltip",
          children: [
            _ && /* @__PURE__ */ a("div", { className: "nice-popover__arrow" }),
            /* @__PURE__ */ a("div", { className: "nice-popover__content", children: o })
          ]
        }
      ),
      c
    )
  ] });
}, ie = ({
  items: e,
  children: o,
  onOpen: m,
  onClose: r,
  className: v
}) => {
  const [l, s] = P(!1), [d, x] = P({ x: 0, y: 0 }), _ = E(null), k = E(null), M = O();
  z(_, () => {
    l && (s(!1), r?.());
  });
  const y = b(
    (c) => {
      c.preventDefault(), x({ x: c.clientX, y: c.clientY }), s(!0), m?.();
    },
    [m]
  ), p = b(
    (c) => {
      !c.disabled && c.onClick && (c.onClick(), s(!1), r?.());
    },
    [r]
  );
  Y(() => {
    if (!l)
      return;
    const c = (t) => {
      t.key === "Escape" && (s(!1), r?.());
    };
    return document.addEventListener("keydown", c), () => document.removeEventListener("keydown", c);
  }, [l, r]);
  const u = (c) => /* @__PURE__ */ a("ul", { className: "nice-context-menu__list", role: "menu", children: c.map((t) => t.divider ? /* @__PURE__ */ a("li", { className: "nice-context-menu__divider", role: "separator" }, t.key) : /* @__PURE__ */ a("li", { role: "presentation", children: /* @__PURE__ */ C(
    "button",
    {
      type: "button",
      className: `nice-context-menu__item ${t.disabled ? "nice-context-menu__item--disabled" : ""} ${t.danger ? "nice-context-menu__item--danger" : ""}`,
      role: "menuitem",
      disabled: t.disabled,
      onClick: () => p(t),
      children: [
        t.icon && /* @__PURE__ */ a("span", { className: "nice-context-menu__icon", children: t.icon }),
        /* @__PURE__ */ a("span", { className: "nice-context-menu__label", children: t.label })
      ]
    }
  ) }, t.key)) });
  return /* @__PURE__ */ C(K, { children: [
    /* @__PURE__ */ a("div", { ref: k, onContextMenu: y, style: { display: "contents" }, children: o }),
    l && X(
      /* @__PURE__ */ a(
        "div",
        {
          ref: _,
          className: `nice-context-menu ${v || ""}`,
          style: {
            position: "fixed",
            left: d.x,
            top: d.y,
            zIndex: 1200
          },
          role: "menu",
          children: u(e)
        }
      ),
      M
    )
  ] });
};
export {
  se as NiceActionSheet,
  de as NiceBlockUI,
  oe as NiceBottomSheet,
  ue as NiceBox,
  he as NiceCommandPaletteProvider,
  ie as NiceContextMenu,
  re as NiceDrawer,
  fe as NiceLoadPanel,
  Z as NiceModal,
  te as NiceModalBody,
  ne as NiceModalFooter,
  ee as NiceModalHeader,
  ae as NiceOverlayPopover,
  me as NicePopover,
  ve as NiceResizable,
  ge as NiceResponsiveBox,
  we as NiceScrollView,
  be as NiceTutorial,
  ye as NiceTutorialProvider,
  pe as NiceWindow,
  Ne as NiceWindowManager,
  _e as useCommandPalette,
  ke as useRegisterCommands
};
