import { u as I, C as d } from "./forms-BpbQYyEQ.es.js";
import e from "../utils/dom.js";
import { TopPopupWorker as n } from "../popup/worker.js";
class P {
  static componentName = "Top";
  componentName;
  // имя класса компонента
  className;
  // имя css класса компонента
  uid;
  // уникальный id компонента
  el;
  // элемент, связанный с компонентом
  options = {};
  // параметры компонента
  unmountEls = [];
  unmountEvents = [];
  // переопредлять нельзя
  // если компонент инициирован, необходимо сразу его вернуть и выполнить reInit() вместо mount()
  // используется init вместо constructor, так как super constructor выполняется до Object.defineProperty() параметров класса
  init(t, p, i) {
    if (!p)
      throw t + ": el is undefined";
    const o = P.getComponent(p, t);
    if (o)
      return o.reInit(i), o;
    this.componentName = t, this.className = "top" + t[0].toUpperCase() + t.substring(1), this.uid = this.componentName + (Math.random() + "").replace(".", ""), this._setComponent(p), this.el = p, this.el.classList.add(this.className), this.options = Object.assign(this.options, i), this.mount();
  }
  // получить инициированный компонент
  static getComponent(t, p) {
    return e.storage(t, "#" + p);
  }
  // устанвоить компонент
  _setComponent(t) {
    e.storage(t, "#" + this.componentName, this);
  }
  // функция подключения компонента
  mount() {
    throw "Please, add method mount() to component: " + this.componentName;
  }
  // функция отключения компонента
  unmount() {
    e.storage(this.el, "#" + this.componentName, null), this.unmountEls.forEach((t) => {
      t.remove();
    }), this.unmountEls = [], this.unmountEvents.forEach((t) => {
      t.el.removeEventListener(t.type, t.listener, t.options);
    }), this.unmountEvents = [];
  }
  // указание новые элементы, которые должны будут удалиться после unmount
  registerElForUnmount(t) {
    this.unmountEls.push(t);
  }
  // указание новые события, которые должны будут удалиться после unmount
  addEventListenerWithUnmount(t, p, i, o) {
    t.addEventListener(p, i, o), this.registerEventForUnmount(t, p, i, o);
  }
  // указание новые события, которые должны будут удалиться после unmount
  registerEventForUnmount(t, p, i, o) {
    const s = {
      el: t,
      type: p,
      listener: i,
      options: o
    };
    this.unmountEvents.push(s);
  }
  // функция перенастройки уже подключенного компонента
  reInit(t) {
    throw "Please, add method reInit() to component: " + this.componentName;
  }
  // удалить элементы из DOM, но не из памяти
  static detach(t) {
    if (t instanceof NodeList)
      t.forEach((p) => p.parentElement?.removeChild(p));
    else {
      const p = t;
      p.parentElement?.removeChild(p);
    }
  }
}
class L {
  static isInited = !1;
  /**
   * Добавить глобальные обработчики
   *
   * Добавляются на страницу один раз и навсегда
   */
  static init() {
    this.isInited || (this.isInited = !0, document.addEventListener("click", this.onclickCapture, { capture: !0 }), document.addEventListener("click", this.onclick), document.addEventListener("keydown", this.onkeydown));
  }
  /**
   * Глобальный обработчик захватов кликов
   *
   * Обрабатывает захватов клики внутри Popup
   */
  static onclickCapture(t) {
    if (!(!(t.target instanceof HTMLElement) || !t.target.closest(".top-popup-wrapper"))) {
      if (t.target.matches("[data-top-popup]")) {
        const i = t.target.closest("ul"), o = t.target.closest("a, .a");
        i && i.querySelector("a.top-active, .a.top-active")?.classList.remove("top-active"), o && o.classList.add("top-active"), t.stopPropagation();
        return;
      }
      if (t.target.matches(".top-popup-wrapper")) {
        const i = t.target;
        n.close(i, !0), t.stopPropagation();
        return;
      }
    }
  }
  /**
   * Глобальный обработчик кликов
   *
   * Обрабатывает клики внутри Popup
   */
  static onclick(t) {
    if (!(t.target instanceof HTMLElement)) return;
    const p = t.target.closest(".closer, a, .a, .top-button");
    if (p) {
      const i = t.target.closest(".top-popup-wrapper");
      if (!i || p.matches(".top-popup-noCloser"))
        return;
      p.getAttribute("href") === "." && t.preventDefault(), n.close(i, !0);
    }
  }
  /**
   * Глобальный обработчик нажатия кнопки на клавиатуре
   */
  static onkeydown(t) {
    if (!(t.target instanceof HTMLElement)) return;
    let p = t.target.closest(".top-popup-wrapper");
    if (p || (p = n.getPopupFromOpener(t.target)?.elPopup ?? null), !p)
      return;
    const i = p.querySelector("ul.top-popup_content");
    switch (t.key) {
      case "Escape":
        n.close(p, !0);
        break;
      case "Enter":
        if (!i) {
          if (e.querySelectorVisible(p, ".preloader"))
            break;
          const u = e.querySelectorVisible(p, ".top-popup_footer .go, .top-popup_footer [data-action]");
          if (u instanceof HTMLElement) {
            u.click();
            break;
          }
          let f = e.querySelectorVisibleLast(p, ".top-popup_footer .top-button:focus");
          f || (f = e.querySelectorVisibleLast(p, ".top-popup_footer .top-button")), f instanceof HTMLElement && f.click();
          break;
        }
        const o = e.querySelectorVisible(p, "li > a.top-active");
        o && o.getAttribute("href") && (t.preventDefault(), location.href = o.getAttribute("href"));
        const s = p.querySelector("li > .top-active");
        s instanceof HTMLElement && s.click();
        break;
      // управление стрелками
      case "ArrowUp":
      case "ArrowRight":
      case "ArrowDown":
      case "ArrowLeft":
        if (!i)
          break;
        if (t.key === "ArrowRight" || t.key === "ArrowLeft") {
          if (e.querySelectorVisible(
            p,
            "ul.top-popup_content > li:not(.top-popup_liNoSelectable) > .top-active > .top-popup_listMore"
          ))
            t.preventDefault();
          else if (t.target.tagName === "INPUT")
            break;
        } else
          t.preventDefault();
        const a = p.querySelector("ul.top-popup_content > li:not(.top-popup_liNoSelectable) > .top-active")?.parentElement;
        if (t.key === "ArrowRight" && a) {
          const u = a.querySelector(".top-active > .top-popup_listMore");
          if (u instanceof HTMLElement)
            return u.click();
        }
        const h = e.querySelectorAllVisible(p, "ul.top-popup_content > li:not(.top-popup_liNoSelectable)"), c = h.length;
        if (!c)
          return;
        let r = -1;
        if (a && (r = h.indexOf(a)), t.key === "ArrowUp" || t.key === "ArrowLeft" ? r-- : r++, t.key === "ArrowLeft" && r === -1)
          return t.target.matches("input") ? void 0 : n.close(p, !0);
        if (t.key === "ArrowRight" && r === c)
          return;
        r < 0 && (r = c - 1), r > c - 1 && (r = 0), p.querySelectorAll("ul.top-popup_content > li > .top-active").forEach((u) => u.classList.remove("top-active")), h[r].querySelector(":scope > a, :scope > .a")?.classList.add("top-active"), n.scrollToActive(p);
        break;
    }
  }
}
const E = ":root{--top-popup-z-index: 200000;--top-popup-transition-delay: .1s;--top-popup-offset: var(--top-padding-2);--top-popup-background-color: var(--color-layout-front-1);--top-popup-background-color-hover: var(--color-layout-front-3);--top-popup-background-color-active: var(--color-layout-front-4);--top-popup-border-color: var(--color-line-2-opacity);--top-popup-title-background-color: var(--color-layer-1);--top-popup-content-padding: calc(var(--top-popup-list-padding) + var(--top-popup-listItem-padding));--top-popup-list-padding: var(--top-padding-2);--top-popup-listItem-radius: var(--top-radius-2);--top-popup-listItem-padding: var(--top-padding-2)}.top-popup-front{position:relative}.top-popup-wrapper{--top-popup-height: 0px;--top-popup-right-bounding: 0px;--top-popup-bottom-bounding: 0px;--top-popup-top: 0px;--top-popup-right: calc(100vw - var(--top-popup-right-bounding));--top-popup-bottom: calc(var(--100vh) - var(--top-popup-bottom-bounding));--top-popup-left: 0px;--top-popup-margin: -10px;text-align:initial;white-space:normal;word-break:normal;position:absolute;z-index:200000;outline:none}.top-popup-wrapper:not(.top-popup-wrapper-shown){overflow:hidden}.top-popupPanel{cursor:default;box-shadow:var(--top-shadow-b);border-radius:14px;background:var(--top-popup-background-color);position:absolute;overflow:hidden;display:flex;flex-direction:column}.top-popup-wrapper>*{opacity:0;transition:opacity var(--top-popup-transition-delay) linear,transform var(--top-popup-transition-delay) linear;pointer-events:auto}.top-popup-wrapper-shown:not(.top-popup-wrapper-closed)>*{opacity:1;transform:translate(0)!important}.top-popup_header,.top-popup_content,.top-popup_footer{font-size:14px}.top-popup_header,.top-popup_footer{display:flex;align-items:center;justify-content:space-between}.top-popup_header{color:var(--color-text-1);border-bottom:1px solid var(--top-popup-border-color);padding:var(--top-padding-3);font-weight:600}.top-popup_header>*{font-weight:400}.top-popup_header>.a{cursor:pointer}.top-popup_header>.a:hover{color:var(--color-text-primary)}.top-popup_headerButton{width:60px}.top-popup_widget{padding:var(--top-padding-2)}.top-popup_content{margin:0;flex-grow:1;overflow-y:auto;display:flex;flex-direction:column;gap:var(--top-gap-4);-webkit-overflow-scrolling:touch}div.top-popup_content{color:var(--color-text-1);padding:var(--top-popup-content-padding)}div.top-popup_content>*{flex-shrink:0}div.top-popup_content>.top-button{margin:0}div.top-popup_content .top-unwrap{--top-unwrap-x: var(--top-popup-content-padding)}ul.top-popup_content{color:var(--color-text-1);padding:var(--top-popup-list-padding);gap:2px}ul.top-popup_content .top-unwrap{--top-unwrap-x: var(--top-popup-list-padding)}.top-popup_listItem{border-radius:var(--top-popup-listItem-radius);padding:var(--top-popup-listItem-padding);line-height:1!important}ul.top-popup_content li{margin:0;list-style:none;display:flex;align-items:center;position:relative}ul.top-popup_content li>*{flex-grow:1}ul.top-popup_content li>a:not(.top-button),ul.top-popup_content li>.a{cursor:pointer;box-sizing:border-box;border-radius:var(--top-popup-listItem-radius);background:var(--top-popup-background-color);padding:var(--top-popup-listItem-padding);color:var(--color-text-1)!important;font-size:14px;font-weight:400!important;text-decoration:none!important;font-style:normal;line-height:1!important;display:flex;flex:1 1 100%;align-items:center;transition:background-color .1s ease-in-out}.top-popup-wrapper-no_animate ul.top-popup_content li>a:not(.top-button),.top-popup-wrapper-no_animate ul.top-popup_content li>.a{transition:none}ul.top-popup_content li>a:not(.top-button):hover,ul.top-popup_content li>.a:hover{background:var(--top-popup-background-color-hover)}ul.top-popup_content li>a:not(.top-button).top-active,ul.top-popup_content li>.a.top-active{--top-icon-color: var(--color-text-primary) !important;background:var(--top-popup-background-color-active)}.top-popup_liastItem-withActions{width:240px;max-width:100%}.top-popup_listItemActionsLabel{flex-grow:1}.top-popup_listItemActions{margin-left:auto;flex-grow:0;display:flex}.top-popup_listItemActions>[data-top-icon]{--top-icon-size: 20px;--top-icon-color: var(--color-text-4)}.top-popup_listItemActions>[data-top-icon]:before{line-height:0}.top-popup_listItemActions>[data-top-icon]:hover,.top-popup_listItemActions>[data-top-icon].top-active{--top-icon-color: var(--color-text-3)}.top-popup_content+.top-popup_content{padding-top:0}.top-popup_listItem-title{background:var(--color-layer-1);color:var(--color-text-1);font-size:12px}.top-popup_listItem-formControls{padding-top:0;padding-bottom:0;display:flex;flex-direction:column}.top-popup_listItem-delimiter{border-radius:3px;background:var(--top-popup-border-color);height:1px;padding:0;margin:4px}.top-popup_listMore{font-size:20px;margin:calc(0px - var(--top-popup-listItem-padding)) calc(0px - var(--top-popup-listItem-padding) / 2) calc(0px - var(--top-popup-listItem-padding)) 0}.top-popup_listMore.top-button{margin:0}ul.top-popup_content li>.a.top-popup_listMore{text-align:center;flex-basis:10px}ul.top-popup_content li>.a.top-popup_listMore:before{color:var(--color-text-2)}ul.top-popup_content li>*>.top-popup_listMore{margin-left:auto;color:var(--color-layer-4);font-size:14px}ul.top-popup_content li>*>i.top-popup_listMore:hover,ul.top-popup_content li>*>i.top-popup_listMore.top-active{color:var(--color-text-primary)}ul.top-popup_content li>*>i.top-popup_listMore:before{transform:rotate(90deg);display:block}ul.top-popup_content li a.close{background:none!important}.top-popup_content>[data-top-icon]:before{--top-icon-size: 20px}ul.top-popup_content li>[data-top-icon]{--top-icon-color: var(--color-text-2);--top-icon-size: 20px;--top-icon-width: 20px}ul.top-popup_content li>[data-top-icon]:not(.top-button):before{height:1rem;margin-right:8px;transition:color .1s}ul.top-popup_content li:hover>[data-top-icon]:not(.top-button){--top-icon-color: var(--color-text-2)}.top-popup_footer{padding:var(--top-padding-3);border-top:1px solid var(--top-popup-border-color);display:flex;gap:var(--top-gap-2);justify-content:flex-end}.top-popup_footerSupportLink{margin-right:auto}.top-popup>[data-widget]{padding:0 var(--top-popup-list-padding)}.top-popup>[data-widget]+hr{margin:0 var(--top-popup-list-padding)}.top-popup .placeholder{border:1px solid #E0D9D9!important;border-right:none!important;border-left:none!important;background:#f9f9f9!important;margin:-1px 0;z-index:1;position:relative}.top-popup-wrapper.simple_list>.top-popup{min-width:0;white-space:nowrap}.top-popup_content .top-column{display:flex;flex-direction:column;gap:4px}.top-popup li .check_all,.top-popup li .clear_all{cursor:pointer;color:var(--color-text-primary);padding:8px;display:inline-block}.top-popup li .check_all:hover,.top-popup li .clear_all:hover{text-decoration:underline}.top-popup li .clear_all{display:none}.top-popup_content table{margin:-9px 0}.top-popup_content table td,.top-popup_content table th{padding:9px var(--top-popup-listItem-padding) 9px 0;vertical-align:top}.top-popup_content table th{width:40%;font-weight:600;white-space:nowrap}ul.top-popup_content .a>[type=checkbox],ul.top-popup_content .a>[type=radio]{margin:-8px 0 -8px auto}ul.top-popup_content a>[class*=icon],ul.top-popup_content i.a>[class*=icon]{transition:.1s}.top-popup .buttons{border-radius:0 0 4px 4px;border-top:1px solid #BDC3C7;background:#ecf0f1;padding:10px 15px;margin:10px -15px -10px;white-space:nowrap}.top-popup_footer [class*=btn]:not(.btn-transparent){min-width:100px;padding:5px 14px;margin-left:10px}.top-popup_footer [class*=btn]:first-child{margin-left:0}.top-popup_footer .btn.full_width{margin:0;flex-grow:1}", k = ":root{--top-popup-list-padding: 0px;--top-popup-listItem-radius: 0px;--top-popup-listItem-padding: var(--top-padding-4)}.top-popup-wrapper{--top-popup-footer-offset: 25px;width:auto!important;height:auto!important;position:fixed;top:0!important;right:0!important;left:0!important;overflow:hidden;transition:background .3s}.top-popup-wrapper-shown:not(.top-popup-wrapper-closed){background:#00000080;-webkit-backdrop-filter:blur(1px);backdrop-filter:blur(1px)}.top-popup-wrapper-shown:not(.top-popup-wrapper-closed)>.top-popup{opacity:1!important}.top-popup{border-radius:8px 8px 0 0;width:auto!important;max-height:calc(100% - var(--header-height, 0px) - var(--toolbar-height, 0px) - 12px);margin:0!important;top:auto!important;right:0!important;bottom:var(--toolbar-height, 0px)!important;left:0!important;display:flex;flex-direction:column;transform:translateY(80%);transition:opacity .3s,transform .3s}.top-popup-wrapper.p-from-top{--top-popup-footer-offset: 0px;top:var(--header-height, 0px)!important}.with_dialog .top-popup-wrapper.p-from-top{top:50px!important}.top-popup-wrapper.p-from-top>.top-popup{border-radius:0 0 8px 8px;max-height:calc(100% - 24px);top:0!important;bottom:auto!important;transform:translateY(calc(-100% - 24px))}.top-popup_widget:not(.p-from-top){order:10}ul.top-popup_content{gap:0}ul.top-popup_content li:not(:last-child){border-bottom:1px solid var(--top-popup-border-color)}.top-popup-wrapper.top-style_alt>.top-popup>ul>li{border-bottom:none}.top-popup_footer{flex-direction:column-reverse}.top-popup_footer>.top-button{--top-forms-base-height: var(--top-forms-base-height_l);width:100%}ul.top-popup_content .top-popup_listItem-title{--top-popup-padding-v: 12px}ul.top-popup_content .top-popup_listItem-delimiter{background:var(--color-line-1-opacity);height:4px;margin:0}ul.top-popup_content li:first-child>.top-popup_listItem-delimiter{border-top:1px solid var(--top-popup-border-color)}", S = ".top-popup-wrapper{pointer-events:none}.top-popup{min-width:250px;max-width:calc(100vw - var(--top-popup-left) - 16px);max-height:calc(var(--top-popup-bottom) + var(--top-popup-height))}.top-popup-wrapper.p0>*{transform:translateY(-8px)}.top-popup-wrapper.p1>*{transform:translateY(8px)}.top-popup-wrapper.p2>*{transform:translate(8px)}.top-popup-wrapper.p3>*{transform:translateY(8px)}.top-popup-wrapper.p4>*{transform:translate(-8px)}.top-popup-wrapper.p0>.top-popup{top:-16px;left:-8px}.top-popup-wrapper.p1>.top-popup{bottom:calc(100% + 8px)}.top-popup-wrapper.p2>.top-popup{left:calc(100% + 8px)}.top-popup-wrapper.p3>.top-popup{top:calc(100% + 8px)}.top-popup-wrapper.p4>.top-popup{right:calc(100% + 8px)}.top-popup-wrapper.p2>.top-popup,.top-popup-wrapper.p4>.top-popup{margin-top:var(--top-popup-margin)}.top-popup-wrapper.p2.invert-y>.top-popup,.top-popup-wrapper.p4.invert-y>.top-popup{margin-bottom:var(--top-popup-margin)}.top-popup-wrapper.p1.with_notch>.top-popup{margin-bottom:5px}.top-popup-wrapper.p2.with_notch>.top-popup{margin-left:5px}.top-popup-wrapper.p3.with_notch>.top-popup{margin-top:5px}.top-popup-wrapper.p4.with_notch>.top-popup{margin-right:5px}.top-popup-wrapper.invert-x>.top-popup{right:0}.top-popup-wrapper.invert-y>.top-popup{bottom:0}.top-popup-wrapper.p1>.top-popup{max-height:calc(var(--top-popup-top) - var(--header-height, 0px) - 16px)}.top-popup-wrapper.p3>.top-popup{max-height:calc(var(--top-popup-bottom) - 16px)}.top-popup-wrapper.p2>.top-popup{max-width:calc(var(--top-popup-right) - 16px)}.top-popup-wrapper.p4>.top-popup{max-width:calc(var(--top-popup-left) - 16px)}.top-popup-wrapper.invert-x>.top-popup{max-width:calc(100vw - var(--top-popup-right) - 16px)}.top-popup-wrapper.invert-y>.top-popup{max-height:calc(100vh - var(--top-popup-bottom) - 16px)}.top-popup-wrapper>.notch{border:7.4px solid transparent;position:absolute;display:block}.top-popup-wrapper.p1>.notch{border-bottom:0;border-top:7.4px solid var(--color-layout-front-1);margin:0 0 7.4px -7.4px;bottom:100%;left:50%}.top-popup-wrapper.p2>.notch{border-left:0;border-right:7.4px solid var(--color-layout-front-1);margin:0 0 -7.4px 7.4px;bottom:50%;left:100%}.top-popup-wrapper.p3>.notch{border-top:0;border-bottom:7.4px solid var(--color-layout-front-1);margin:7.4px 0 0 -7.4px;top:100%;left:50%}.top-popup-wrapper.p4>.notch{border-right:0;border-left:7.4px solid var(--color-layout-front-1);margin:0 7.4px -7.4px 0;bottom:50%;right:100%}.top-popup-wrapper.p1>.notch-border{border-top-color:#0000000d;margin-bottom:6px}.top-popup-wrapper.p2>.notch-border{border-right-color:#0000000d;margin-left:6px}.top-popup-wrapper.p3>.notch-border{border-bottom-color:#0000000d;margin-top:6px}.top-popup-wrapper.p4>.notch-border{border-left-color:#0000000d;margin-right:6px}.top-popup-wrapper.p1.with_notch>.top-popup,.top-popup-wrapper.p3.with_notch>.top-popup{margin-left:-16px!important}.top-popup-wrapper.p1.with_notch>.notch,.top-popup-wrapper.p3.with_notch>.notch{margin-left:-8px!important}.top-popup-wrapper.p1.with_notch.invert-x,.top-popup-wrapper.p3.with_notch.invert-x{margin-left:3px!important}.top-popup-wrapper.p1.with_notch.invert-x>.notch,.top-popup-wrapper.p3.with_notch.invert-x>.notch{margin-left:-9px!important}ul.top-popup_content li>*>i.top-popup_listMore{visibility:hidden;transition:none}ul.top-popup_content li:hover>*>i.top-popup_listMore,ul.top-popup_content li>*.top-active>i.top-popup_listMore,ul.top-popup_content li>*>i.top-popup_listMore.top-active{visibility:visible}.top-popup_listItemActions{display:none}.top-popup_listItem.top-active>.top-popup_listItemActions,.top-popup_listItem:hover>.top-popup_listItemActions{display:flex}";
d.insertStyleToPage(E);
d.insertStyleToPage(k, "m");
d.insertStyleToPage(S, "pc");
class b extends P {
  static componentName = "TopPopup";
  // элемент, вызвавший открытие Popup
  elActiveByDefault;
  // элемент уже имеет класс top-active перед открытием окна
  elPopup;
  // Popup .top-popup-wrapper
  elPopupInner;
  // контентная часть Popup  .top-popup
  elPopupHeader;
  elPopupWidget;
  elPopupBody;
  elPopupFooter;
  elFront;
  /**
   * Для openerIsInput фокусировка срабатывает при входе в поле ввода
   *
   * Фокусировка на сам Popup не производится
   *
   * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/combobox_role
   */
  openerIsInput = !1;
  popupParent;
  $;
  // только если есть jQuery
  elStartPosition;
  // используется для useOriginal
  shift = {
    top: 0,
    left: 0
  };
  isClosed = !1;
  // флаг того, что меню закрыто
  isFirstClick = !0;
  type;
  // selector или html
  options = {
    popup: "",
    // selector, text
    p: 0,
    // положение меню (0 - над элементом, 1 - сверху, 2 - справа, 3 - снизу, 4 слева)
    notch: !1,
    // отображать ли клювик
    class: "",
    // класс, добавляемый меню
    posBy: "left",
    // способ привязки позиционирования меню (left/right - левый/правый край родителя, fixed - по документу)
    frontSelector: "",
    invertX: !1,
    // базовая ордината - правая граница элемента, а не левая
    openByHover: !1,
    // открывать при наведении
    useOriginal: !1,
    // использовать оригинальный шаблон, без клонирвоания (для сохранения состояния меню)
    transitionDuration: 100,
    // значение прописано в css
    isFullScreen: !1
  };
  events = {};
  /**
   * Создать Popup
   * @param el - элемент, открывающий меню
   * @param options
   */
  constructor(t, p) {
    super(), this.init(b.componentName, t, p);
  }
  async mount() {
    if (!(this.el instanceof HTMLElement)) return;
    const t = this.vueGetComponent();
    if (this.el.closest(".top-popup-wrapper") && (this.popupParent = n.getPopup(this.el.closest(".top-popup-wrapper"))), await this.mountJQuery(), e.css(this.el, "position") !== "absolute" && (this.el.style.position = "relative"), this.el.dataset.topPopupOpened = "opened", this.elActiveByDefault = this.el.classList.contains("top-active"), this.el.classList.add("top-active"), this.openerIsInput = this.el.classList.contains("top-input"), this.el.classList.contains("top-input-project_name") && (this.openerIsInput = !1), this.openerIsInput) {
      const o = this.el.querySelector("input");
      o && !o.__popupOnBlur && (o.__popupOnBlur = !0, o.addEventListener("blur", (s) => {
        n.getPopupFromOpener(this.el)?.close();
      }));
    }
    if (t)
      this.type = "vue", this.options.popup = "", this.elPopup = e.genEl("div", {}, this.options.popup);
    else if (this.options.popup?.match(/^[#.]/))
      this.type = "selector", this.elPopup = document.querySelector(`${this.options.popup}.template`) || void 0;
    else {
      if (this.type = "html", this.options.useOriginal)
        throw "Option useOriginal not allowed for text templates";
      this.elPopup = e.genEl("div", {}, this.options.popup ?? "");
    }
    if (this.type !== "html" && !t || t?.opened) {
      if (!t || t?.opened) {
        let o;
        if (t?.opened ? o = t.popup.elPopup : o = document.querySelector(`${this.options.popup}.top-popup-wrapper-shown`) || void 0, o) {
          this.elPopup = o, this.el.dataset.topPopupOpened = "", this.elActiveByDefault || this.el.classList.remove("top-active"), n.close(this.elPopup), setTimeout(() => this.mount(), this.options.transitionDuration);
          return;
        }
      }
      this.elPopup || (this.elPopup = document.querySelector(`${this.options.popup}:not(.top-popup-wrapper)`) || void 0);
    }
    if (!this.elPopup)
      return;
    for (this.options.useOriginal ? (this.elStartPosition = this.elPopup.closest(".top-popup-el-start-position"), this.elStartPosition || (this.elStartPosition = e.wrap(this.elPopup, "i"), this.elStartPosition.classList.add("top-popup-el-start-position", "hidden"))) : (this.elPopup = this.elPopup.cloneNode(!0), this.type === "selector" && !this.elPopup.matches(".template") && (this.elPopup.classList.remove("hidden"), this.elPopup.querySelector(":scope > .top-popup_content") || this.elPopup.classList.add("top-popup_content"), this.elPopup = e.wrap(this.elPopup, "div")), this.type === "html" && (this.elPopup.querySelector(":scope > .top-popup_content") || (this.elPopup.classList.add("top-popup_content"), this.elPopup = e.wrap(this.elPopup, "div"))), (this.type === "selector" && !this.elPopup.matches(".template") || this.type === "html" || this.type === "vue") && (e.querySelectorAllArray(this.elPopup, "[data-top-popup]").forEach((o) => {
      o instanceof HTMLElement && (o.dataset.topPopupPosBy = "fixed");
    }), e.querySelectorAllArray(this.elPopup, ".top-popup-wrapper").forEach((o) => o.remove()))), n.decoratorBeforeOpen(this), t && (this.options.class = t.classRef.value, t.transitionDurationRef.value !== void 0 && (this.options.transitionDuration = t.transitionDurationRef.value, this.elPopup instanceof HTMLElement && this.elPopup.style.setProperty(
      "--top-popup-transition-delay",
      this.options.transitionDuration + "ms"
    ))), this.elPopupInner = document.createElement("div"), this.elPopupInner.classList.add("top-popupPanel", "top-popup"); this.elPopup.firstChild; )
      this.elPopupInner.appendChild(this.elPopup.firstChild);
    if (this.elPopup.append(this.elPopupInner), this.elPopup.classList.add("top-popup-wrapper"), this.options.class) {
      const o = this.options.class.split(" ");
      this.elPopup.classList.add(...o);
    }
    this.options.notch && (this.elPopup.classList.add("with_notch"), this.elPopup.insertAdjacentHTML("beforeend", '<i class="notch notch-border"></i><i class="notch"></i>')), await this.vueOpen(), this.elPopupHeader = this.elPopupInner.querySelector(".top-popup_header"), this.elPopupWidget = this.elPopupInner.querySelector(".top-popup_widget"), this.elPopupBody = this.elPopupInner.querySelector(".top-popup_content"), this.elPopupFooter = this.elPopupInner.querySelector(".top-popup_footer");
    const p = !!this.elPopup.querySelector('[data-widget="search"]');
    if (this.options.isFullScreen && !p) {
      const o = I();
      !this.elPopupHeader && o.Common.Close && (this.elPopupHeader = e.genEl("i", { class: "top-popup_header" }), this.elPopupInner.prepend(this.elPopupHeader), this.elPopupHeader.prepend(e.genEl("i", { class: "a closer" }, o.Common.Close)), this.elPopupHeader.append(e.genEl("i", { class: "top-popup_headerButton" })));
    }
    e.storage(this.elPopup, b.componentName, this), this.options.frontSelector && (this.elFront = document.querySelector(this.options.frontSelector)), this.elFront || (this.elFront = this.el.closest(".top-popup-front")), this.elFront || (this.elFront = document.body), this.elPopup instanceof HTMLElement && (this.elPopup.style.width = this.el.offsetWidth + "px", this.elPopup.style.height = this.el.offsetHeight + "px", this.elPopup.style.top = this.el.offsetTop + "px", this.elPopup.style.right = parseInt(this.el.style.right || "0") + "px", this.elPopup.style.bottom = parseInt(this.el.style.bottom || "0") + "px"), this.el.parentElement?.insertBefore(this.elPopup, this.el), this.elPopup.classList.remove("template"), this.options.invertX && this.elPopup.classList.add("invert-x");
    let i = !!this.el.closest(".modal-header");
    i || (i = !!this.el.closest("#top_panel")), i || (i = !!this.el.closest("#secondmenu")), i && this.elPopup.classList.add("p-from-top"), setTimeout(() => this.elPopup?.classList.add("top-popup-wrapper-shown")), this.elFront && !this.elFront.matches("body") && (this.elFront.append(this.elPopup), this.shift.top = e.offset(this.el).top - this.el.offsetTop - e.offset(this.elFront).top, this.shift.left = e.offset(this.el).left - this.el.offsetLeft - e.offset(this.elFront).left, this.shift.top -= parseInt(this.el.style["margin-top"] || 0), this.shift.left -= parseInt(this.el.style["margin-left"] || 0), this.elPopup instanceof HTMLElement && (this.elPopup.style.top = parseInt(this.elPopup.style.top || "0") + this.shift.top + "px", this.elPopup.style.left = parseInt(this.elPopup.style.left || "0") + this.shift.left + "px")), this.$ && d.$ && this.$.trigger("aftershow.top-menu-popup", [d.$(this.elPopup)]), this.recalcPosition(), this.elPopup.setAttribute("tabindex", "0"), this.focus(), n.decoratorAfterOpen(this), this.mountEvents();
  }
  async mountJQuery() {
    d.$ && (this.$ = d.$(this.el));
  }
  /**
   * Выполнить фокусировку на нужный элемент после открытия окна
   */
  focus() {
    let t;
    this.elPopup && (t = e.querySelectorVisible(this.elPopup, ".top-popup-autofocus"), t || (t = e.querySelectorVisible(this.elPopup, ":read-write, select:not(:disabled)")), t || (t = e.querySelectorVisible(this.elPopup, ".top-popup_footer .top-button")), t || (t = this.elPopup), this.openerIsInput || (t instanceof HTMLElement && t.focus({ preventScroll: !0 }), setTimeout(() => {
      t instanceof HTMLElement && t.focus({ preventScroll: !0 });
    }, this.options.transitionDuration)));
  }
  mountEvents() {
    this.addEventListenerWithUnmount(document, "mousedown", (t) => this.onMousedown(t)), this.openerIsInput ? this.onFocusCloseOthers() : this.elPopup && this.elPopupInner && (this.addEventListenerWithUnmount(this.elPopup, "focus", (t) => this.onFocus(t)), this.options.openByHover && (this.addEventListenerWithUnmount(this.elPopup, "mouseleave", (t) => this.onMouseleave(t)), this.addEventListenerWithUnmount(this.elPopupInner, "mouseleave", (t) => this.onMouseleave(t)))), this.options.isFullScreen && this.elPopupBody && this.addEventListenerWithUnmount(this.elPopupBody, "touchmove", (t) => this.onTouchmove(t));
  }
  /**
   * Обработка клика вне окна
   */
  onMousedown(t) {
    if (!this.elPopup || !(t.target instanceof Element) || !this.isFirstClick || (this.isFirstClick = !1, setTimeout(() => this.isFirstClick = !0), t instanceof MouseEvent && t.button !== 0))
      return;
    let p = e.querySelectorVisibleLast(document.body, ":scope > .top-popup-wrapper");
    if (p && p !== this.elPopup || t.target.closest(".top-popup-front") && (p = e.querySelectorVisibleLast(t.target.closest(".top-popup-front"), ":scope > .top-popup-wrapper"), p && p !== this.elPopup))
      return;
    if (t.target.closest(`[data-top-popup-id="${this.options.id}"]`)) {
      t.preventDefault();
      return;
    }
    let i = t.target.closest("input, select, textarea, button, [tabindex]");
    i === this.elPopup && (i = null);
    const o = !i;
    o && this.openerIsInput && t.preventDefault(), !this.elPopup.contains(t.target) && (this.elPopup.closest(".ui-dialog") && !t.target.closest(".ui-dialog") || n.decoratorIsIgnoreOuterClick(t) || n.close(this.elPopup, o));
  }
  /**
   * Произошла фокусировка на этот popup
   */
  onFocus(t) {
    t.target instanceof Element && t.target.matches("input") || this.onFocusCloseOthers();
  }
  /**
   * Закрыть другие Popup при фокусе на элемент формы в текущем
   */
  onFocusCloseOthers() {
    if (this.isClosed)
      return;
    n.getAllVisible().forEach((p) => {
      this.elPopup?.contains(p) || this.popupParent?.elPopup === p || this.popupParent?.popupParent?.elPopup === p || n.close(p);
    });
  }
  /**
   * Закрыть Popup при отведении мыши
   */
  onMouseleave(t) {
    setTimeout(() => {
      this.elPopupInner && this.elPopupInner.matches(":hover") || !this.elPopup || n.close(this.elPopup);
    }, 100);
  }
  /**
   * Контроль положения Popup при fixed позиционировании
   */
  onResize() {
    this.elPopup && this.elPopup.parentElement !== document.body && document.body.append(this.elPopup), this.elPopup instanceof HTMLElement && (this.elPopup.style.top = e.offset(this.el).top + "px", this.elPopup.style.left = e.offset(this.el).left + "px");
  }
  unmount() {
    super.unmount(), this.el instanceof HTMLElement && (this.el.dataset.topPopupOpened = ""), this.elActiveByDefault || this.el.classList.remove("top-active");
    let t = this.el.getAttribute("style");
    t && (t = t.replace(/position:[^;]*;?/g, ""), this.el.setAttribute("style", t));
  }
  // контроль за положением Popup, чтобы оно не вылезало за пределы документа
  recalcPosition(t) {
    if (!(this.elPopup instanceof HTMLElement)) return;
    let p = t ?? this.options.p, i;
    if (this.el instanceof HTMLElement)
      switch (this.elPopup.style.height = this.el.offsetHeight + "px", this.elPopup.classList.remove("p0", "p1", "p2", "p3", "p4"), this.elPopup.classList.add("p" + p), this.options.posBy) {
        case "left":
          i = this.el.offsetLeft + parseInt(this.el.style["margin-left"] || "0"), i += this.shift.left, this.elPopup.style.left = i + "px";
          break;
        case "right":
          if (!(this.el.offsetParent instanceof HTMLElement)) break;
          i = this.el.offsetLeft + parseInt(this.el.style["margin-left"] || "0"), this.elPopup.style.right = this.el.offsetParent.offsetWidth - this.el.offsetWidth - i + "px";
          break;
        case "fixed":
          this.addEventListenerWithUnmount(window, "resize", () => this.onResize()), this.onResize();
          break;
        default:
          this.options.posBy?.append(this.elPopup);
      }
    const o = this.elPopup.getBoundingClientRect();
    this.elPopup.style.setProperty("--top-popup-height", this.elPopup.offsetHeight + "px"), this.elPopup.style.setProperty("--top-popup-right-bounding", o.right + "px"), this.elPopup.style.setProperty("--top-popup-bottom-bounding", o.bottom + "px"), this.elPopup.style.setProperty("--top-popup-top", o.top + "px"), this.elPopup.style.setProperty("--top-popup-left", o.left + "px"), this.elPopupInner instanceof HTMLElement && (this.elPopupInner.style.maxWidth = "unset", this.elPopupInner.style.maxHeight = "unset");
    const s = {
      top: !1,
      right: !1,
      bottom: !1,
      left: !1
    }, a = {
      top: !1,
      right: !1,
      bottom: !1,
      left: !1
    };
    let h = o.left > window.innerWidth / 2, c = o.top > window.innerHeight / 2;
    p === 4 && (h = !h), p === 1 && (c = !c);
    const r = this.elPopupInner?.getBoundingClientRect();
    let u, f;
    const m = e.cssNumber(this.elPopup, "--top-popup-offset"), v = this.el.offsetHeight, y = this.el.offsetWidth;
    r && (u = window.innerWidth - r.right, f = window.innerHeight - r.bottom, r.top < m && (s.top = !0, r.top < m * 2 - r.height + v && (a.top = !0)), u < m && (s.right = !0, u < m * 2 - r.width + y && (a.right = !0)), f < m && (s.bottom = !0, f < m * 2 - r.height + v && (a.bottom = !0)), r.left < m && (s.left = !0, r.left < m * 2 - r.width + v && (a.left = !0)));
    const _ = (g, l) => {
      if (g === "x") {
        if (!s.right && !s.left || (l === 1 || l === 3) && !a.right && !a.left && h)
          return l;
        s.right && (l === 0 || l === 2) && h && (l = 4), s.left && (l === 0 || l === 4) && h && (l = 2);
      }
      if (g === "y") {
        if (!s.top && !s.bottom || (l === 2 || l === 4) && !a.top && !a.bottom && c)
          return l;
        s.top && (l === 0 || l === 1) && c && (l = 3), s.bottom && c && (l = 1);
      }
      return l;
    };
    let w = ["x", "y"];
    (p === 0 || p === 1 || p === 3) && (w = ["y", "x"]);
    let x = p ?? 0;
    w.forEach((g) => {
      x = _(g, x);
    }), p = x, s.bottom && (p === 2 || p === 4) && c && this.elPopup.classList.add("invert-y"), s.right && (p === 0 || p === 1 || p === 3) && this.elPopup.classList.add("invert-x"), this.elPopup.classList.remove("p0", "p1", "p2", "p3", "p4"), this.elPopup.classList.add("p" + p), this.elPopupInner instanceof HTMLElement && (this.elPopupInner.style.maxWidth = "", this.elPopupInner.style.maxHeight = ""), n.scrollToActive(this.elPopup);
  }
  onTouchmove(t) {
    if (t.currentTarget instanceof HTMLElement && t.target instanceof HTMLElement) {
      if (t.currentTarget.scrollWidth > t.currentTarget.offsetWidth || t.target.parentElement?.scrollWidth && t.target.parentElement?.offsetWidth && t.target.parentElement.scrollWidth > t.target.parentElement?.offsetWidth)
        return;
      t.currentTarget.matches(".has_scroll") || t.preventDefault();
    }
  }
  close() {
    this.isClosed || (this.isClosed = !0, this.$ && d.$ && this.elPopup && this.$.trigger("afterclose.top-menu-popup", [d.$(this.elPopup)]), !n.noClose && (this.unmount(), this.elPopup?.classList.add("top-popup-wrapper-closed"), setTimeout(() => {
      if (this.vueClose(), !this.elPopup) return;
      this.options.useOriginal ? (this.elPopup.removeAttribute("style"), this.elPopup.classList.remove("top-popup-wrapper-shown", "top-popup-wrapper-closed"), this.elPopup.classList.add("template"), this.elStartPosition?.append(this.elPopup), this.elPopup.querySelector("div.top-popup_content.top-column")?.classList.remove("top-column"), this.elPopup.querySelector(".notch-border")?.remove(), this.elPopup.querySelector(".notch")?.remove(), this.elPopupInner?.replaceWith(...this.elPopupInner.childNodes), e.storageClear(this.elPopup)) : (e.storageClear(this.elPopup), this.elPopup.remove(), delete this.elPopup);
      const t = n.getAllVisible(), p = t.length && t[t.length - 1];
      p ? n.getPopup(p).focus() : document.documentElement.classList.remove("with_popup");
    }, this.options.transitionDuration)));
  }
  async vueOpen() {
    await this.vueGetComponent()?.onOpen(this);
  }
  vueClose() {
    this.vueGetComponent()?.onClose(this);
  }
  // получить vueConnectors компонента Popup
  vueGetComponent() {
    if (this.el instanceof HTMLElement && this.options.id) return n.vueConnectors.get(this.options.id);
  }
}
L.init();
export {
  b as TopLibPopup
};
//# sourceMappingURL=popup-DpyyE2Cs.es.js.map
