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