import { defineAsyncComponent as D } from "vue";
import { C as r, E as C, l as p, m as R, e as H, h as I, n as M, f as N, _ as K, o as x, p as F, T as B, j as W, q as j, r as Y, g as G } from "./forms-BAUgA7Ct.es.js";
import { TopPopupWorker as a } from "../popup/worker.js";
import { T as q, _ as z } from "./dialogs.vue_vue_type_script_setup_true_lang-DMhcuiHP.es.js";
import { isVisible as U } from "../utils/dom.js";
class Q {
  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));
    }), C.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 v;
const X = {
  mounted: async (t, e) => {
    v || (v = (await import("../utils/dom.js")).storage);
    const o = e.arg, n = e.value;
    v(t, o, n);
  }
};
let h, u = [], g;
const J = async () => {
  const { isVisible: t } = await import("../utils/dom.js");
  if (u = u.filter(t), !u.length) return;
  u[0].focus(), u = [];
}, O = async (t) => {
  h || (h = await import("../utils/lodash.js")), g || (g = h.debounce(J, 30)), u.push(t), g();
}, Z = {
  mounted: function(t, e) {
    t.__TOP_V_FOCUS_VALUE = e.value ?? !0, (e.value ?? !0) && O(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) && O(t));
  }
};
let f, T;
const P = (t) => (typeof t == "boolean" || (t ? t = { ...t } : t = {}, t.behavior ??= "smooth", t.block ??= "nearest", t.inline ??= "nearest"), t);
let m, w;
const tt = async () => {
  if (!m) return;
  const t = await y(m);
  t.isVisible && m.scrollIntoView(t.scrollIntoViewOptions);
}, L = async (t) => {
  T || (T = await import("../utils/lodash.js")), w || (w = T.debounce(tt, 30)), m = t, w();
}, y = async (t, e) => {
  f || (f = await import("../utils/dom.js"));
  let o = f.storage(t, "v-top-scrollIntoView");
  return o || (o = {
    isVisible: U(t),
    scrollIntoViewOptions: P(e)
  }, f.storage(t, "v-top-scrollIntoView", o)), o;
}, et = {
  async mounted(t, e) {
    await y(t, e.value), e.modifiers.immediate && L(t);
  },
  async updated(t, e) {
    const o = await y(t, e.value);
    o.scrollIntoViewOptions = P(e.value);
    const n = U(t);
    n && o.isVisible !== n && L(t), o.isVisible = n;
  }
};
let l;
const ot = {
  async mounted(t) {
    l || (l = await import("../utils/scroll.js")), l.connectScrollShadow(t);
  },
  async unmounted(t) {
    l || (l = await import("../utils/scroll.js")), l.unconnectScrollShadow(t);
  }
}, _ = /* @__PURE__ */ new Map();
let $ = !1;
const nt = {
  ctrl: p() ? "⌘" : "Ctrl",
  alt: p() ? "⌥" : "Alt",
  shift: p() ? "⇧" : "Shift"
}, it = (t) => {
  let e = t;
  return t.includes("Key") && (e = t.replace("Key", "")), t.includes("Digit") && (e = t.replace("Digit", "")), t === "Escape" && (e = "Esc"), e;
}, V = (t, e) => {
  const o = it(t);
  if (!e) return o;
  const { ctrl: n, alt: i, shift: s } = nt, c = [];
  return e.ctrl && c.push(n), e.alt && c.push(i), e.shift && c.push(s), c.push(o), c.join(p() ? "" : "+");
}, st = (t, e, o) => {
  const n = V(e, o);
  if (t.__TOP_V_SHORTCUT_VALUE) {
    console.warn(`Element already has shortcut "${t.__TOP_V_SHORTCUT_VALUE}"`);
    return;
  }
  if (_.has(n)) {
    console.warn(`Shortcut "${n}" is taken`);
    return;
  }
  _.set(n, t), t.title = t.title ? `${t.title} (${n})` : n, t.__TOP_V_SHORTCUT_VALUE = n;
}, rt = (t) => {
  const e = t.__TOP_V_SHORTCUT_VALUE;
  e && _.delete(e);
}, ct = () => {
  $ || ($ = !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 = V(t.code, e), n = _.get(o);
    n && !n.disabled && U(n) && (t.preventDefault(), n.click());
  }));
}, at = {
  mounted: function(t, e) {
    const { value: o, modifiers: n } = e;
    o && (ct(), st(t, o, n));
  },
  unmounted(t) {
    rt(t);
  }
};
let b;
const lt = {
  mounted(t, e, o) {
    const n = e.value || "top-sticky";
    b = 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]
    }), b.observe(t);
  },
  unmounted(t, e, o) {
    b?.disconnect();
  }
};
let A = !1, S;
const d = /* @__PURE__ */ new Map(), ut = (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)";
}, pt = (t) => {
  let e = window.innerHeight;
  window.addEventListener("scroll", () => {
    d.forEach((o) => ut(o, e));
  }, { passive: !0 }), S = new IntersectionObserver((o) => {
    e = window.innerHeight, o.forEach((n) => {
      const i = n.target;
      if (n.intersectionRatio < 0.1 ? d.delete(i) : d.set(i, i), n.intersectionRatio === 0) {
        const { distance: s } = i.directiveSwipUpOptions;
        i.style.transform = `translateY(${s}px)`;
      }
    });
  }, {
    threshold: 0.1
  });
}, ft = {
  mounted(t, e, o) {
    r.state.isMobileUA || (t.directiveSwipUpOptions = {
      distance: e.value?.distance ?? 100,
      // количество px на которые блок изначально смещен вниз,
      percent: e.value?.percent ?? 30
      // процент высоты экрана поднявшись на который блок закончит подплытие
    }, A || (pt(), A = !0), S.observe(t));
  },
  unmounted(t, e, o) {
    d.delete(t), S?.unobserve(t);
  }
}, E = (t) => {
  if (!r.$?.ui?.tooltip) {
    console.info("Для работы v-top-tooltip требуется глобальная загрузка jQuery UI Tooltip");
    return;
  }
  return r.$(t);
}, k = (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;
}, mt = {
  mounted(t, e, o) {
    E(t)?.tooltip(k(e, o));
  },
  updated(t, e, o, n) {
    const i = k(e, o), s = E(t)?.tooltip("instance");
    s && (s.options = {
      ...s.options,
      ...i
    });
  },
  unmounted(t, e, o) {
    E(t)?.tooltip("destroy");
  }
}, dt = D(() => import("./notice-CGgc2m0q.es.js"));
window.vd = console.log;
const wt = {
  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), Q.init(), q.init(e.topDialogOptions), t.directive("top-data", X), t.directive("top-focus", Z), t.directive("top-scroll-into-view", et), t.directive("top-scroll-shadow", ot), t.directive("top-shortcut", at), t.directive("top-sticky", lt), t.directive("top-swim-up", ft), t.directive("top-tooltip", mt), t.component("TopAvatar", R), t.component("TopButton", H), t.component("TopCheckbox", I), t.component("TopControlLabel", M), t.component("TopHint", N), t.component("TopInput", K), t.component("TopInputDate", x), t.component("TopInputRange", F), t.component("TopLoadbar", B), t.component("TopRadio", W), t.component("TopSelect", j), t.component("TopSwitcher", Y), t.component("TopTextarea", G), t.component("TopNotice", dt), t.component("TopDialogs", z);
  }
};
export {
  wt as c
};
//# sourceMappingURL=core-BE_-rKvW.es.js.map
