import { defineAsyncComponent as I } from "vue";
import { C as s, E as N, l as p, m as K, e as x, h as F, n as B, f as W, _ as j, o as Y, p as G, T as Q, j as q, q as z, r as X, g as J } from "./forms-BpbQYyEQ.es.js";
import { TopPopupWorker as a } from "../popup/worker.js";
import { T as Z, _ as tt } from "./dialogs.vue_vue_type_script_setup_true_lang-D8WYUfXI.es.js";
import { isVisible as l } from "../utils/dom.js";
class et {
  static isInited = !1;
  /**
   * Добавить глобальные обработчики
   *
   * Добавляются на страницу один раз и навсегда
   */
  static init() {
    this.isInited || (this.isInited = !0, document.addEventListener("mouseover", (e) => {
      !(e.target instanceof HTMLElement) || !e.target.dataset?.topPopupOpenByHover || e.target.click();
    }), document.addEventListener("scroll", () => {
      s.state.isMobile || s.state.isMobileUA || a.getAll().forEach((e) => a.close(e));
    }), N.addOnReize((e) => {
      s.state.isMobile && e.topEvent.widthDiff && a.getAll().forEach((o) => a.close(o));
    }), document.addEventListener("click", this.onclick, { capture: !0 }));
  }
  /**
   * Глобальный обработчик кликов
   *
   * Обрабатывает клики на открытие Popup
   */
  static async onclick(e) {
    if (!(e.target instanceof HTMLElement) || e.target.dataset.topPopupDisabled)
      return;
    let o;
    switch (!0) {
      case !!e.target.dataset?.topPopup:
        o = e.target;
        break;
      case !!e.target.parentElement?.dataset.topPopup:
        o = e.target.parentElement;
        break;
      case !!e.target.parentElement?.parentElement?.dataset.topPopup:
        o = e.target.parentElement?.parentElement;
        break;
    }
    if (o && !o.dataset.topPopupDisabled) {
      if (o.dataset.topPopupOpened) {
        const n = a.getPopupFromOpener(o);
        n?.openerIsInput || n?.close();
        return;
      }
      e.preventDefault(), await a.openByOpener(o);
    }
  }
}
let g;
const ot = {
  mounted: async (t, e) => {
    g || (g = (await import("../utils/dom.js")).storage);
    const o = e.arg, n = e.value;
    g(t, o, n);
  }
};
let b, f = [], w;
const nt = async () => {
  const { isVisible: t } = await import("../utils/dom.js");
  if (f = f.filter(t), !f.length) return;
  f[0].focus(), f = [];
}, L = async (t) => {
  b || (b = await import("../utils/lodash.js")), w || (w = b.debounce(nt, 30)), f.push(t), w();
}, it = {
  mounted: function(t, e) {
    t.__TOP_V_FOCUS_VALUE = e.value ?? !0, (e.value ?? !0) && L(t);
  },
  updated: function(t, e) {
    e.modifiers.onupdate && t.__TOP_V_FOCUS_VALUE !== (e.value ?? !0) && (t.__TOP_V_FOCUS_VALUE = e.value ?? !0, (e.value ?? !0) && L(t));
  }
};
let m, E;
const C = (t) => (typeof t == "boolean" || (t ? t = { ...t } : t = {}, t.behavior ??= "smooth", t.block ??= "nearest", t.inline ??= "nearest"), t);
let _, S;
const st = async () => {
  if (!_) return;
  const t = await O(_);
  t.isVisible && _.scrollIntoView(t.scrollIntoViewOptions);
}, V = async (t) => {
  E || (E = await import("../utils/lodash.js")), S || (S = E.debounce(st, 30)), _ = t, S();
}, O = async (t, e) => {
  m || (m = await import("../utils/dom.js"));
  let o = m.storage(t, "v-top-scrollIntoView");
  return o || (o = {
    isVisible: l(t),
    scrollIntoViewOptions: C(e)
  }, m.storage(t, "v-top-scrollIntoView", o)), o;
}, rt = {
  async mounted(t, e) {
    await O(t, e.value), e.modifiers.immediate && V(t);
  },
  async updated(t, e) {
    const o = await O(t, e.value);
    o.scrollIntoViewOptions = C(e.value);
    const n = l(t);
    n && o.isVisible !== n && V(t), o.isVisible = n;
  }
};
let u;
const ct = {
  async mounted(t) {
    u || (u = await import("../utils/scroll.js")), u.connectScrollShadow(t);
  },
  async unmounted(t) {
    u || (u = await import("../utils/scroll.js")), u.unconnectScrollShadow(t);
  }
}, v = /* @__PURE__ */ new Map();
let U;
const T = /* @__PURE__ */ new Map();
let $ = !1;
const at = {
  ctrl: p() ? "⌘" : "Ctrl",
  alt: p() ? "⌥" : "Alt",
  shift: p() ? "⇧" : "Shift"
}, lt = (t) => {
  let e = t;
  return t.includes("Key") && (e = t.replace("Key", "")), t.includes("Digit") && (e = t.replace("Digit", "")), t === "Escape" && (e = "Esc"), e;
}, R = (t, e) => {
  const o = lt(t);
  if (!e) return o;
  const { ctrl: n, alt: i, shift: r } = at, c = [];
  return e.ctrl && c.push(n), e.alt && c.push(i), e.shift && c.push(r), c.push(o), c.join(p() ? "" : "+");
}, H = (t, e, o) => {
  const n = R(e, o);
  if (t.__TOP_V_SHORTCUT_VALUE) {
    console.warn(`Element already has shortcut "${t.__TOP_V_SHORTCUT_VALUE}"`);
    return;
  }
  if (T.has(n)) {
    console.warn(`Shortcut "${n}" is taken`);
    return;
  }
  T.set(n, t), t.title = t.title ? `${t.title} (${n})` : n, t.__TOP_V_SHORTCUT_VALUE = n;
}, M = (t) => {
  const e = t.__TOP_V_SHORTCUT_VALUE;
  e && (T.delete(e), delete t.__TOP_V_SHORTCUT_VALUE, t.title === e && t.removeAttribute("title"), t.title.includes(` (${e})`) && (t.title = t.title.replace(` (${e})`, "")));
}, ut = () => {
  for (const [t] of v)
    !l(t) && t.__TOP_V_SHORTCUT_VALUE && M(t);
  for (const [t, e] of v)
    l(t) && !t.__TOP_V_SHORTCUT_VALUE && H(t, e.value, e.modifiers);
  v.clear();
}, ft = async (t, e, o) => {
  if (!U) {
    const { debounce: n } = await import("../utils/lodash.js");
    U = n(ut, 30);
  }
  v.set(t, { value: e, modifiers: o }), U();
}, P = () => {
  $ || ($ = !0, document.addEventListener("keydown", (t) => {
    if (!(t.target instanceof HTMLElement) || ["INPUT", "TEXTAREA"].includes(t.target.tagName) || t.target.isContentEditable) return;
    const e = {
      ctrl: p() ? t.metaKey : t.ctrlKey,
      alt: t.altKey,
      shift: t.shiftKey
    }, o = R(t.code, e), n = T.get(o);
    n && (n.disabled || !l(n) || (t.preventDefault(), n.click()));
  }));
}, pt = {
  mounted: function(t, e) {
    const { value: o, modifiers: n } = e;
    !o || !l(t) || (P(), H(t, o, n));
  },
  updated: function(t, e) {
    if (!!t.__TOP_V_SHORTCUT_VALUE === l(t)) return;
    const { value: o, modifiers: n } = e;
    o && (P(), ft(t, o, n));
  },
  unmounted: function(t) {
    M(t);
  }
};
let y;
const mt = {
  mounted(t, e, o) {
    const n = e.value || "top-sticky";
    y = new IntersectionObserver((i) => {
      let r = i[0].intersectionRatio < 1;
      r && e.modifiers.bottom && i[0].intersectionRect.y === 0 && (r = !1), t.classList.toggle(n, r);
    }, {
      threshold: [1]
    }), y.observe(t);
  },
  unmounted(t, e, o) {
    y?.disconnect();
  }
};
let k = !1, A;
const h = /* @__PURE__ */ new Map(), dt = (t, e) => {
  const { distance: o, percent: n } = t.directiveSwipUpOptions, i = t.getBoundingClientRect().top, r = e * n / 100 / o, c = (e - i) / r;
  c <= o ? t.style.transform = `translateY(${o - c}px)` : t.style.transform = "translateY(0px)";
}, _t = (t) => {
  let e = window.innerHeight;
  window.addEventListener("scroll", () => {
    h.forEach((o) => dt(o, e));
  }, { passive: !0 }), A = new IntersectionObserver((o) => {
    e = window.innerHeight, o.forEach((n) => {
      const i = n.target;
      if (n.intersectionRatio < 0.1 ? h.delete(i) : h.set(i, i), n.intersectionRatio === 0) {
        const { distance: r } = i.directiveSwipUpOptions;
        i.style.transform = `translateY(${r}px)`;
      }
    });
  }, {
    threshold: 0.1
  });
}, vt = {
  mounted(t, e, o) {
    s.state.isMobileUA || (t.directiveSwipUpOptions = {
      distance: e.value?.distance ?? 100,
      // количество px на которые блок изначально смещен вниз,
      percent: e.value?.percent ?? 30
      // процент высоты экрана поднявшись на который блок закончит подплытие
    }, k || (_t(), k = !0), A.observe(t));
  },
  unmounted(t, e, o) {
    h.delete(t), A?.unobserve(t);
  }
}, d = (t) => {
  if (!s.$?.ui?.tooltip) {
    console.info("Для работы v-top-tooltip требуется глобальная загрузка jQuery UI Tooltip");
    return;
  }
  return s.$(t);
}, D = (t, e) => {
  const o = {
    ...t.value ?? {}
  };
  return o.content ??= e.getAttribute("ui-tooltip-title") ?? e.getAttribute("title") ?? "", o.content = String(o.content).replace(/([^<>])\r?\n([^<>])/g, "$1<br>$2"), o.position ??= {
    my: "bottom-18px",
    at: "top center",
    collision: "flipfit"
  }, o;
}, ht = {
  mounted(t, e) {
    d(t)?.tooltip(D(e, t));
  },
  updated(t, e) {
    const o = D(e, t), n = d(t)?.tooltip("instance");
    if (!n) {
      d(t)?.tooltip(o);
      return;
    }
    n.options = {
      ...n.options,
      ...o
    };
  },
  unmounted(t) {
    d(t)?.tooltip("destroy");
  }
}, Tt = I(() => import("./notice-Ckc8r96E.es.js"));
window.vd = console.log;
const Ut = {
  install: (t, e) => {
    t.config.globalProperties.$core = s, t.config.globalProperties.$vd = console.log;
    for (const o in e)
      s.state[o] = e[o];
    e.widthForMobile && (s.widthForMobile = e.widthForMobile), e.themeName && (s.themeName = e.themeName), s._setState(), e.topPopupOptions && (a.options = e.topPopupOptions), et.init(), Z.init(e.topDialogOptions), t.directive("top-data", ot), t.directive("top-focus", it), t.directive("top-scroll-into-view", rt), t.directive("top-scroll-shadow", ct), t.directive("top-shortcut", pt), t.directive("top-sticky", mt), t.directive("top-swim-up", vt), t.directive("top-tooltip", ht), t.component("TopAvatar", K), t.component("TopButton", x), t.component("TopCheckbox", F), t.component("TopControlLabel", B), t.component("TopHint", W), t.component("TopInput", j), t.component("TopInputDate", Y), t.component("TopInputRange", G), t.component("TopLoadbar", Q), t.component("TopRadio", q), t.component("TopSelect", z), t.component("TopSwitcher", X), t.component("TopTextarea", J), t.component("TopNotice", Tt), t.component("TopDialogs", tt);
  }
};
export {
  Ut as c
};
//# sourceMappingURL=core-DoIr-EAf.es.js.map
