import C from "./locale.js";
import { defineComponent as y, computed as X, openBlock as Y, createBlock as x, mergeProps as D, createSlots as P, renderList as N, unref as $, withCtx as _, createVNode as k, h as I, render as H } from "vue";
import { omit as B } from "es-toolkit";
import F from "./useDialog.js";
import q from "./CustomRender.js";
import A from "./Dialog.js";
import { M as R } from "./MenusPlugin-Bk6UW6o9.js";
import G from "./ModalsPlugin.js";
import U from "./ToastsPlugin.js";
import { overridePersistentStorage as V } from "./storage.js";
import { persistentStorage as ht } from "./storage.js";
import { S as mt, a as dt } from "./misc-CHQs-G03.js";
import { a as pt, S as Tt, b as bt } from "./statusLevels-D8EgtE_L.js";
function L(r) {
  return r.type.indexOf("mouse") !== -1 ? r.clientX : r.touches[0].clientX;
}
function M(r) {
  return r.type.indexOf("mouse") !== -1 ? r.clientY : r.touches[0].clientY;
}
var z = (function() {
  var r = !1;
  try {
    var o = Object.defineProperty({}, "passive", {
      get: function() {
        r = !0;
      }
    });
    window.addEventListener("test", null, o);
  } catch {
  }
  return r;
})(), J = {
  install: function(r, o) {
    var n = Object.assign({}, {
      disableClick: !1,
      tapTolerance: 10,
      // px
      swipeTolerance: 30,
      // px
      touchHoldTolerance: 400,
      // ms
      longTapTimeInterval: 400,
      // ms
      touchClass: "",
      dragFrequency: 100,
      // ms
      rollOverFrequency: 100,
      // ms
      namespace: "touch"
    }, o);
    function i(e) {
      var t = this.$$touchObj, s = e.type.indexOf("touch") >= 0, m = e.type.indexOf("mouse") >= 0, d = this;
      s && (t.lastTouchStartTime = e.timeStamp), !(m && t.lastTouchStartTime && e.timeStamp - t.lastTouchStartTime < 350) && (t.touchStarted || (w(this), t.touchStarted = !0, t.touchMoved = !1, t.swipeOutBounded = !1, t.startX = L(e), t.startY = M(e), t.currentX = 0, t.currentY = 0, t.touchStartTime = e.timeStamp, t.hasSwipe = c(this, "swipe") || c(this, "swipe.left") || c(this, "swipe.right") || c(this, "swipe.top") || c(this, "swipe.bottom"), c(this, "hold") && (t.touchHoldTimer = setTimeout(function() {
        t.touchHoldTimer = null, T(e, d, "hold");
      }, t.options.touchHoldTolerance)), T(e, this, "press")));
    }
    function v(e) {
      var t = this.$$touchObj, s = L(e), m = M(e), d = t.currentX != s || t.currentY != m;
      if (t.currentX = s, t.currentY = m, t.touchMoved) {
        if (t.hasSwipe && !t.swipeOutBounded) {
          var u = t.options.swipeTolerance;
          t.swipeOutBounded = Math.abs(t.startX - t.currentX) > u && Math.abs(t.startY - t.currentY) > u;
        }
      } else {
        var l = t.options.tapTolerance;
        t.touchMoved = Math.abs(t.startX - t.currentX) > l || Math.abs(t.startY - t.currentY) > l, t.touchMoved && (O(t), T(e, this, "drag.once"));
      }
      if (c(this, "rollover") && d) {
        var a = e.timeStamp, E = t.options.rollOverFrequency;
        (t.touchRollTime == null || a > t.touchRollTime + E) && (t.touchRollTime = a, T(e, this, "rollover"));
      }
      if (c(this, "drag") && t.touchStarted && t.touchMoved && d) {
        var a = e.timeStamp, E = t.options.dragFrequency;
        (t.touchDragTime == null || a > t.touchDragTime + E) && (t.touchDragTime = a, T(e, this, "drag"));
      }
    }
    function p() {
      var e = this.$$touchObj;
      O(e), S(this), e.touchStarted = e.touchMoved = !1, e.startX = e.startY = 0;
    }
    function h(e) {
      var t = this.$$touchObj, s = e.type.indexOf("touch") >= 0, m = e.type.indexOf("mouse") >= 0;
      s && (t.lastTouchEndTime = e.timeStamp);
      var d = s && !t.touchHoldTimer;
      if (O(t), t.touchStarted = !1, S(this), !(m && t.lastTouchEndTime && e.timeStamp - t.lastTouchEndTime < 350))
        if (T(e, this, "release"), t.touchMoved) {
          if (t.hasSwipe && !t.swipeOutBounded) {
            var l = t.options.swipeTolerance, u, a = Math.abs(t.startY - t.currentY), E = Math.abs(t.startX - t.currentX);
            (a > l || E > l) && (a > E ? u = t.startY > t.currentY ? "top" : "bottom" : u = t.startX > t.currentX ? "left" : "right", c(this, "swipe." + u) ? T(e, this, "swipe." + u, u) : T(e, this, "swipe", u));
          }
        } else if (c(this, "longtap") && e.timeStamp - t.touchStartTime > t.options.longTapTimeInterval)
          e.cancelable && e.preventDefault(), T(e, this, "longtap");
        else if (c(this, "hold") && d) {
          e.cancelable && e.preventDefault();
          return;
        } else
          T(e, this, "tap");
    }
    function f() {
      w(this);
    }
    function b() {
      S(this);
    }
    function c(e, t) {
      var s = e.$$touchObj.callbacks[t];
      return s != null && s.length > 0;
    }
    function T(e, t, s, m) {
      var d = t.$$touchObj, l = d.callbacks[s];
      if (l == null || l.length === 0)
        return null;
      for (var u = 0; u < l.length; u++) {
        var a = l[u];
        a.modifiers.stop && e.stopPropagation(), a.modifiers.prevent && e.preventDefault(), !(a.modifiers.self && e.target !== e.currentTarget) && typeof a.value == "function" && (m ? a.value(m, e) : a.value(e));
      }
    }
    function w(e) {
      var t = e.$$touchObj.options.touchClass;
      t && e.classList.add(t);
    }
    function S(e) {
      var t = e.$$touchObj.options.touchClass;
      t && e.classList.remove(t);
    }
    function O(e) {
      e && e.touchHoldTimer && (clearTimeout(e.touchHoldTimer), e.touchHoldTimer = null);
    }
    function g(e, t) {
      var s = e.$$touchObj || {
        // an object contains all callbacks registered,
        // key is event name, value is an array
        callbacks: {},
        // prevent bind twice, set to true when event bound
        hasBindTouchEvents: !1,
        // default options, would be override by v-touch-options
        options: n
      };
      return t && (s.options = Object.assign({}, s.options, t)), e.$$touchObj = s, e.$$touchObj;
    }
    r.directive(n.namespace, {
      beforeMount: function(e, t) {
        var s = g(e), m = z ? { passive: !0 } : !1, d = t.arg || "tap";
        switch (d) {
          case "swipe":
            var l = t.modifiers;
            if (l.left || l.right || l.top || l.bottom) {
              for (var u in t.modifiers)
                if (["left", "right", "top", "bottom"].indexOf(u) >= 0) {
                  var a = "swipe." + u;
                  s.callbacks[a] = s.callbacks[a] || [], s.callbacks[a].push(t);
                }
            } else
              s.callbacks.swipe = s.callbacks.swipe || [], s.callbacks.swipe.push(t);
            break;
          case "press":
          case "drag":
            t.modifiers.disablePassive && (m = !1);
          default:
            s.callbacks[d] = s.callbacks[d] || [], s.callbacks[d].push(t);
        }
        s.hasBindTouchEvents || (e.addEventListener("touchstart", i, m), e.addEventListener("touchmove", v, m), e.addEventListener("touchcancel", p), e.addEventListener("touchend", h), s.options.disableClick || (e.addEventListener("mousedown", i), e.addEventListener("mousemove", v), e.addEventListener("mouseup", h), e.addEventListener("mouseenter", f), e.addEventListener("mouseleave", b)), s.hasBindTouchEvents = !0);
      },
      unmounted: function(e) {
        O(e.$$touchObj), e.removeEventListener("touchstart", i), e.removeEventListener("touchmove", v), e.removeEventListener("touchcancel", p), e.removeEventListener("touchend", h), e.$$touchObj && !e.$$touchObj.options.disableClick && (e.removeEventListener("mousedown", i), e.removeEventListener("mousemove", v), e.removeEventListener("mouseup", h), e.removeEventListener("mouseenter", f), e.removeEventListener("mouseleave", b)), delete e.$$touchObj;
      }
    }), r.directive(`${n.namespace}-class`, {
      beforeMount: function(e, t) {
        g(e, {
          touchClass: t.value
        });
      }
    }), r.directive(`${n.namespace}-options`, {
      beforeMount: function(e, t) {
        g(e, t.value);
      }
    });
  }
};
const K = /* @__PURE__ */ y({
  __name: "Dialogs",
  setup(r) {
    const o = F(), n = X(() => o.active ? B(o.active, ["deferred", "onConfirm", "onCancel", "slots"]) : null);
    function i() {
      var p, h, f;
      (p = o.active) != null && p.onCancel && o.active.onCancel(), (f = (h = o.active) == null ? void 0 : h.deferred) == null || f.resolve({
        isCanceled: !0
      }), o.close();
    }
    async function v() {
      var p, h, f;
      (p = o.active) != null && p.onConfirm && await o.active.onConfirm(), (f = (h = o.active) == null ? void 0 : h.deferred) == null || f.resolve({
        isConfirmed: !0
      }), o.close();
    }
    return (p, h) => {
      var f;
      return Y(), x(A, D({
        open: !!n.value
      }, n.value, {
        onConfirm: v,
        onCancel: i
      }), P({ _: 2 }, [
        N((f = $(o).active) == null ? void 0 : f.slots, (b, c) => ({
          name: c,
          fn: _(() => [
            k(q, { render: b }, null, 8, ["render"])
          ])
        }))
      ]), 1040, ["open"]);
    };
  }
}), j = "stash-dialogs-mount-node", Q = {
  install(r, o) {
    const n = (o == null ? void 0 : o.mountNodeId) || j;
    let i = document.getElementById(n);
    i || (i = document.createElement("div"), i.id = n, i.dataset.test = j, document.body.appendChild(i)), o != null && o.mountNodeClass && !i.classList.contains(o.mountNodeClass) && i.classList.add(o.mountNodeClass);
    const v = k(I(K));
    v.appContext = r._context, H(v, i);
  }
}, ut = {
  install(r, {
    i18n: o = void 0,
    storage: n = void 0,
    staticPath: i = "/static",
    images: v = {
      provider: "static"
    },
    googleMapsApiKey: p = void 0,
    menus: h,
    modals: f,
    toasts: b,
    dialogs: c
  } = {}) {
    r.use(J, {}), o && (C.use(o.locale), C.i18n(o && o.t)), n && V(n), r.provide("stashOptions", {
      i18n: o,
      images: v,
      storage: n,
      staticPath: i,
      googleMapsApiKey: p
    }), h !== !1 && r.use(R, h), f !== !1 && r.use(G, f), b !== !1 && r.use(U, b), c !== !1 && r.use(Q, c);
  }
};
export {
  mt as SpacingDensity,
  dt as StashImageProvider,
  pt as StatusColors,
  Tt as StatusIcons,
  bt as StatusSeverities,
  ut as default,
  V as overridePersistentStorage,
  ht as persistentStorage
};
//# sourceMappingURL=index.js.map
