import { defineAsyncComponent as I } from "vue";
import { C as r, E as N, l as f, 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", () => {
      r.state.isMobile || r.state.isMobileUA || a.getAll().forEach((e) => a.close(e));
    }), N.addOnReize((e) => {
      r.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 T;
const ot = {
  mounted: async (t, e) => {
    T || (T = (await import("../utils/dom.js")).storage);
    const o = e.arg, n = e.value;
    T(t, o, n);
  }
};
let g, p = [], b;
const nt = async () => {
  const { isVisible: t } = await import("../utils/dom.js");
  if (p = p.filter(t), !p.length) return;
  p[0].focus(), p = [];
}, V = async (t) => {
  g || (g = await import("../utils/lodash.js")), b || (b = g.debounce(nt, 30)), p.push(t), b();
}, it = {
  mounted: function(t, e) {
    t.__TOP_V_FOCUS_VALUE = e.value ?? !0, (e.value ?? !0) && V(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) && V(t));
  }
};
let d, w;
const C = (t) => (typeof t == "boolean" || (t ? t = { ...t } : t = {}, t.behavior ??= "smooth", t.block ??= "nearest", t.inline ??= "nearest"), t);
let m, E;
const st = async () => {
  if (!m) return;
  const t = await O(m);
  t.isVisible && m.scrollIntoView(t.scrollIntoViewOptions);
}, A = async (t) => {
  w || (w = await import("../utils/lodash.js")), E || (E = w.debounce(st, 30)), m = t, E();
}, O = async (t, e) => {
  d || (d = await import("../utils/dom.js"));
  let o = d.storage(t, "v-top-scrollIntoView");
  return o || (o = {
    isVisible: l(t),
    scrollIntoViewOptions: C(e)
  }, d.storage(t, "v-top-scrollIntoView", o)), o;
}, rt = {
  async mounted(t, e) {
    await O(t, e.value), e.modifiers.immediate && A(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 && A(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);
  }
}, _ = /* @__PURE__ */ new Map();
let S;
const h = /* @__PURE__ */ new Map();
let $ = !1;
const at = {
  ctrl: f() ? "⌘" : "Ctrl",
  alt: f() ? "⌥" : "Alt",
  shift: f() ? "⇧" : "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: s } = at, c = [];
  return e.ctrl && c.push(n), e.alt && c.push(i), e.shift && c.push(s), c.push(o), c.join(f() ? "" : "+");
}, 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 (h.has(n)) {
    console.warn(`Shortcut "${n}" is taken`);
    return;
  }
  h.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 && (h.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 _)
    !l(t) && t.__TOP_V_SHORTCUT_VALUE && M(t);
  for (const [t, e] of _)
    l(t) && !t.__TOP_V_SHORTCUT_VALUE && H(t, e.value, e.modifiers);
  _.clear();
}, pt = async (t, e, o) => {
  if (!S) {
    const { debounce: n } = await import("../utils/lodash.js");
    S = n(ut, 30);
  }
  _.set(t, { value: e, modifiers: o }), S();
}, P = () => {
  $ || ($ = !0, document.addEventListener("keydown", (t) => {
    if (!(t.target instanceof HTMLElement) || ["INPUT", "TEXTAREA"].includes(t.target.tagName) || t.target.isContentEditable) return;
    const e = {
      ctrl: f() ? t.metaKey : t.ctrlKey,
      alt: t.altKey,
      shift: t.shiftKey
    }, o = R(t.code, e), n = h.get(o);
    n && (n.disabled || !l(n) || (t.preventDefault(), n.click()));
  }));
}, ft = {
  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(), pt(t, o, n));
  },
  unmounted: function(t) {
    M(t);
  }
};
let U;
const dt = {
  mounted(t, e, o) {
    const n = e.value || "top-sticky";
    U = new IntersectionObserver((i) => {
      let s = i[0].intersectionRatio < 1;
      s && e.modifiers.bottom && i[0].intersectionRect.y === 0 && (s = !1), t.classList.toggle(n, s);
    }, {
      threshold: [1]
    }), U.observe(t);
  },
  unmounted(t, e, o) {
    U?.disconnect();
  }
};
let k = !1, L;
const v = /* @__PURE__ */ new Map(), mt = (t, e) => {
  const { distance: o, percent: n } = t.directiveSwipUpOptions, i = t.getBoundingClientRect().top, s = e * n / 100 / o, c = (e - i) / s;
  c <= o ? t.style.transform = `translateY(${o - c}px)` : t.style.transform = "translateY(0px)";
}, _t = (t) => {
  let e = window.innerHeight;
  window.addEventListener("scroll", () => {
    v.forEach((o) => mt(o, e));
  }, { passive: !0 }), L = new IntersectionObserver((o) => {
    e = window.innerHeight, o.forEach((n) => {
      const i = n.target;
      if (n.intersectionRatio < 0.1 ? v.delete(i) : v.set(i, i), n.intersectionRatio === 0) {
        const { distance: s } = i.directiveSwipUpOptions;
        i.style.transform = `translateY(${s}px)`;
      }
    });
  }, {
    threshold: 0.1
  });
}, vt = {
  mounted(t, e, o) {
    r.state.isMobileUA || (t.directiveSwipUpOptions = {
      distance: e.value?.distance ?? 100,
      // количество px на которые блок изначально смещен вниз,
      percent: e.value?.percent ?? 30
      // процент высоты экрана поднявшись на который блок закончит подплытие
    }, k || (_t(), k = !0), L.observe(t));
  },
  unmounted(t, e, o) {
    v.delete(t), L?.unobserve(t);
  }
}, y = (t) => {
  if (!r.$?.ui?.tooltip) {
    console.info("Для работы v-top-tooltip требуется глобальная загрузка jQuery UI Tooltip");
    return;
  }
  return r.$(t);
}, D = (t, e) => {
  const o = t.value ?? {};
  return o.content ??= e.props?.title, o.content = String(o.content).replace(/([^<>])\r?\n([^<>])/g, "$1<br>$2"), o.position ??= {
    my: "bottom-18px",
    at: "top center"
  }, o;
}, ht = {
  mounted(t, e, o) {
    y(t)?.tooltip(D(e, o));
  },
  updated(t, e, o, n) {
    const i = D(e, o), s = y(t)?.tooltip("instance");
    s && (s.options = {
      ...s.options,
      ...i
    });
  },
  unmounted(t, e, o) {
    y(t)?.tooltip("destroy");
  }
}, Tt = I(() => import("./notice-Ckc8r96E.es.js"));
window.vd = console.log;
const Ut = {
  install: (t, e) => {
    t.config.globalProperties.$core = r, t.config.globalProperties.$vd = console.log;
    for (const o in e)
      r.state[o] = e[o];
    e.widthForMobile && (r.widthForMobile = e.widthForMobile), e.themeName && (r.themeName = e.themeName), r._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", ft), t.directive("top-sticky", dt), 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-Baaq63Be.es.js.map
