
		import { Core as _autoloadCSSCore } from '../core/app.js';
		const fileNames = ['../assets/project.css'].map(fileName => import.meta.resolve(fileName));
		_autoloadCSSCore.insertCSSLinkToPage(fileNames, true);
	
import { defineComponent as R, mergeModels as _, useModel as b, computed as P, createElementBlock as T, openBlock as h, createBlock as j, unref as v, withCtx as A, Fragment as D, renderList as me, normalizeClass as ae, createElementVNode as U, toDisplayString as w, createVNode as O, createTextVNode as q, toValue as Be, ref as M, watch as G, createCommentVNode as E, reactive as Oe, resolveComponent as Ue, shallowRef as Ne, onMounted as Qe, withModifiers as H, isRef as we, mergeProps as De, withKeys as $e, nextTick as Xe, resolveDirective as Ze, withDirectives as et, resolveDynamicComponent as tt, renderSlot as ot, createSlots as at } from "vue";
import { u as B, C as X, e as te, q as Se, d as lt } from "../.chunks/forms-BpbQYyEQ.es.js";
import { _ as ke, b as Te, a as nt } from "../.chunks/popupHint.vue_vue_type_style_index_0_lang-if4Qli-k.es.js";
import { a as rt, _ as je, b as Fe, c as qe, I as pe } from "../.chunks/policy.vue_vue_type_style_index_0_lang-BFldQm5e.es.js";
import { u as it } from "../.chunks/utils-MzIaxkRQ.es.js";
import { getSearcherGIcon as dt, getLangLabel as st, getDeviceGIcon as ut } from "../utils/searchers.js";
import "../.chunks/core-DoIr-EAf.es.js";
import "../.chunks/dialogs.vue_vue_type_script_setup_true_lang-D8WYUfXI.es.js";
import { g as ie, a as ne } from "../.chunks/field-CyyFzM-Y.es.js";
import { validUrl as ct } from "../utils/check.js";
import { ellipsis as ft } from "../utils/string.js";
import { invertKeyboardLayout as gt } from "../utils/keyboard.js";
import { storage as Z } from "../utils/dom.js";
import { TopPopupWorker as mt } from "../popup/worker.js";
const vt = { class: "top-competitorSelector" }, pt = { class: "top-ellipsis1" }, To = /* @__PURE__ */ R({
  __name: "competitorSelector",
  props: /* @__PURE__ */ _({
    modelValue: {},
    items: {},
    showSelectAllItem: { type: Boolean, default: !0 }
  }, {
    modelValue: {},
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(e) {
    const t = e, o = b(e, "modelValue"), a = P(() => {
      if (t.showSelectAllItem)
        return {
          icon: "",
          title: B().Common.Select_all,
          value: "all",
          content: ""
        };
    });
    return (n, l) => (h(), T("div", vt, [
      v(X).state.isMobile ? (h(), j(ke, { key: 0 }, {
        opener: A(() => [
          O(te, {
            class: "top-competitorSelector_opener",
            color: "theme",
            icon: "",
            icon2: ""
          }, {
            default: A(() => [
              q(w(e.items.find((r) => r.value === o.value?.[0])?.content), 1)
            ]),
            _: 1
          })
        ]),
        contentList: A(() => [
          (h(!0), T(D, null, me(e.items, (r) => (h(), j(Te, {
            class: ae({
              "top-active": o.value?.includes(r.value)
            }),
            "data-top-icon": r.icon,
            title: r.title,
            onClick: () => o.value = [r.value]
          }, {
            default: A(() => [
              U("span", pt, w(r.content), 1)
            ]),
            _: 2
          }, 1032, ["class", "data-top-icon", "title", "onClick"]))), 256))
        ]),
        _: 1
      })) : (h(), j(rt, {
        key: 1,
        modelValue: o.value,
        "onUpdate:modelValue": l[0] || (l[0] = (r) => o.value = r),
        items: e.items,
        isMultiple: !0,
        styling: "bar",
        canBeEmptyMultiple: !1,
        selectAllItem: a.value
      }, null, 8, ["modelValue", "items", "selectAllItem"]))
    ]));
  }
}), jo = (e, t) => P(() => Be(e).filter((n) => n.on >= 0 || n.id === t).map((n) => ({
  value: n.id,
  title: n.url + ` [${n.id}]`,
  icon: n.id === Be(t) ? "" : "",
  content: n.name
}))), N = -1, S = -2, de = -1, ht = {
  0: "Yandex",
  1: "Google",
  4: "YouTube",
  5: "Bing",
  7: "Seznam",
  8: "AppStore",
  9: "GoogleStore",
  20: "Yandex.com",
  21: "Yandex.com.tr"
}, be = {
  key: S,
  name: "--",
  index: S
}, We = {
  key: S,
  name: "--",
  regions: [be],
  regionByIndex: /* @__PURE__ */ new Map([[S, be]])
}, se = {
  key: S,
  name: "Autoselect",
  index: S
}, he = {
  key: S,
  name: "Autoselect",
  regions: [se],
  regionByIndex: /* @__PURE__ */ new Map([[S, se]])
}, Pe = {
  countryCode: "00",
  depth: 1,
  device: 0,
  key: de,
  index: de,
  lang: "ru",
  name: "Without region"
}, yt = () => (se.name = B().Common.Autoselect, se), St = () => (yt(), he.name = B().Common.Autoselect, console.log(he), he), It = () => (Pe.name = B().Keywords.Without_region, Pe), He = (e = !1, t = !1, o = []) => {
  let a;
  return e ? a = xt(o) : a = Je(o), t && a.set(S, St()), a.size || a.set(S, We), a;
}, Je = (e, t = !0, o = [], a = !1) => {
  const n = /* @__PURE__ */ new Map();
  return e.forEach((l) => {
    if (!l.enabled || a && typeof l.key == "number" && l.key > 1) return;
    const r = { ...l };
    r.regionByIndex = /* @__PURE__ */ new Map(), l.regions && l.regions.forEach((d) => {
      if (t && !d.enabled) return;
      const c = { ...d };
      r.regionByIndex.set(c.index, c);
    }), !r.regionByIndex.size && o.length, // режим вывода ПС без регионов
    (!l.regions || // есть включенные регионы
    r.regionByIndex.size || // запрошен вывод конкретных ПС
    o.length) && n.set(r.key, r);
  }), o.forEach((l) => {
    if (n.has(l)) return;
    const r = {
      key: l,
      name: ht[l],
      regions: [],
      regionByIndex: /* @__PURE__ */ new Map()
    };
    n.set(r.key, r);
  }), n;
}, xt = (e) => {
  const t = Je(e, !1, [0, 1], !0);
  if (t.has(2)) {
    const o = t.get(2);
    o && (o.regionByIndex = /* @__PURE__ */ new Map());
  }
  return t.forEach((o) => {
    if (!o.regionByIndex) return;
    const a = { ...It() };
    o.regionByIndex.set(a.index, a);
  }), t;
}, Ct = (e, t, o = []) => {
  const a = He(e, !1, o);
  let n;
  return a.forEach((l) => {
    if (!(t.searcher_key !== void 0 && t.searcher_key != l.key) && l.regions && (l.regions.forEach((r) => {
      if (!n && !(t.key !== void 0 && t.key != r.key) && !(t.index !== void 0 && t.index != r.index) && !(!e && (t.lang !== void 0 && t.lang != r.lang || t.device !== void 0 && t.device != r.device)))
        return r.searcher_key = l.key, n = r, !1;
    }), n))
      return !1;
  }), n;
}, kt = it(() => import("../.chunks/dialog_regionSelectorRegions-D7x41iZu.es.js")), Tt = (e, t) => {
  const o = B(), a = M(t.value.keys().next().value ?? S), n = P(() => {
    const l = /* @__PURE__ */ new Map();
    if (t.value.forEach((r) => {
      let d = {
        value: r.key,
        title: r.name
      };
      e.addSearcherIcon && (d.icon = dt(r.key)), l.set(r.key, d);
    }), e.addCompare && !l.has(S)) {
      const r = {
        value: "",
        title: "--------------------",
        disabled: !0
      };
      l.set(r.value, r);
      const d = {
        value: N,
        title: o.Common.Compare
      };
      l.set(d.value, d);
    }
    return l;
  });
  return {
    searcherKey: a,
    optionBySearcherKey: n
  };
}, jt = (e, t) => {
  const o = B(), a = M(S);
  e.modelValue.length === 1 && (a.value = e.modelValue[0]), a.value === S && (e.forFrequency ? a.value = t.value?.regionByIndex.values().next().value?.key ?? S : a.value = t.value?.regionByIndex.keys().next().value ?? S);
  const n = P(() => {
    const l = /* @__PURE__ */ new Map();
    return t.value.regionByIndex?.forEach((r) => {
      let d = r.name;
      if (e.forFrequency) {
        const C = {
          value: r.key,
          title: d
        };
        l.has(r.key) || l.set(r.key, C);
        return;
      }
      r.device && (d += " (" + o.Common["Device_" + r.device] + ")");
      const c = st(t.value.key || 0, r.lang ?? "");
      c && (d += " / " + c);
      const f = {
        value: r.index,
        title: d,
        icon: r.device ? ut(r.device) : void 0
      };
      l.set(r.index, f);
    }), l;
  });
  return G(n, (l, r) => {
    if (e.onlySearcher || a.value !== void 0 && l.get(a.value))
      return;
    let d = l.keys().next().value;
    if (a.value === S || d === S) {
      a.value = d;
      return;
    }
    let c = r?.get(a.value)?.title || "", f = -1;
    for (const [C, i] of l.entries()) {
      const g = i.title;
      if (typeof g != "string" || typeof C == "string")
        break;
      if (g === c) {
        d = C;
        break;
      }
      const s = new RegExp(` \\((${o.Common.Device_1}|${o.Common.Device_2})\\)`);
      let u = c, m = 3;
      g.indexOf(u) === -1 && (u = c.replace(/^[^a-zа-я]/i, "").replace(s, ""), m--), g.indexOf(u) === -1 && (u = c.replace(/ \/.*/, ""), m--), g.indexOf(u) === -1 && (u = c.replace(/ \/.*/, ""), u = u.replace(/^[^a-zа-я]/i, "").replace(s, ""), m--), g.indexOf(u) !== -1 && (m <= f || (f = m, d = C));
    }
    a.value = d;
  }), {
    regionIndex: a,
    optionByRegionIndex: n
  };
}, At = (e, t, o) => {
  const a = M([]), n = () => {
    if (e.onlySearcher && t.value) {
      a.value = Array.from(t.value.keys());
      return;
    }
    let r = [];
    if (e.modelValue.length > 1)
      r = [...e.modelValue];
    else
      try {
        r = JSON.parse(
          localStorage.getItem("ui:project:regionSelector" + e.projectId + ":regionsIndexes")
        ) ?? [];
      } catch {
      }
    r.length && (r = r.filter((d) => o.value.has(d))), r.length || (r = Array.from(o.value)), a.value = [...r];
  }, l = () => {
    a.value.length ? localStorage.setItem("ui:project:regionSelector:" + e.projectId + ":regionsIndexes", JSON.stringify(a.value)) : localStorage.removeItem("ui:project:regionSelector:" + e.projectId + ":regionsIndexes");
  };
  return G(a, () => {
    l();
  }), e.addCompare && n(), {
    regionsIndexes: a
  };
}, Bt = (e) => {
  const t = P(() => He(e.forFrequency, e.autoRegion, e.searchers)), o = P(() => t.value.get(n.searcherKey.value) || We), a = P(() => {
    const i = /* @__PURE__ */ new Set();
    return t.value.forEach((g) => {
      g.regionByIndex.forEach((s) => {
        s.index !== de && s.index !== S && i.add(s.index);
      });
    }), i;
  }), n = Tt(e, t), l = jt(e, o), r = At(e, t, a);
  G(t, () => {
    if (e.onlySearcher ? r.regionsIndexes.value = Array.from(t.value.keys()) : r.regionsIndexes.value = r.regionsIndexes.value.filter((g) => a.value.has(g)), n.searcherKey.value === N) return;
    let i = t.value.keys().next().value;
    t.value.forEach((g) => {
      if (e.onlySearcher && g.key === n.searcherKey.value) {
        i = n.searcherKey.value;
        return;
      }
      if (l.regionIndex.value && g.regionByIndex?.has(l.regionIndex.value) && (i = g.key), !e.onlySearcher) {
        let s;
        i !== void 0 && (s = t.value.get(i)?.regionByIndex);
        const u = t.value.get(g.key)?.regionByIndex;
        s?.has(S) && !u?.has(S) && (i = g.key);
      }
    }), i !== void 0 && (n.searcherKey.value = i), l.regionIndex.value !== void 0 && !o.value?.regionByIndex?.has(l.regionIndex.value) && (l.regionIndex.value = o.value?.regions?.keys().next().value);
  }, { immediate: !0 });
  const d = () => {
    if (!(n.searcherKey.value === N || n.searcherKey.value === S))
      return n.searcherKey.value;
  }, c = () => {
    if (e.onlySearcher || l.regionIndex.value === S) return;
    let i = l.regionIndex.value;
    if (e.forFrequency) {
      const g = l.regionIndex.value;
      i = Ct(e.forFrequency, { searcher_key: d(), key: g }, e.searchers)?.index;
    }
    return i;
  }, f = () => {
    const i = d();
    if (i !== void 0)
      return t.value.get(i);
  };
  return {
    selectSearcher: n,
    selectRegion: l,
    compare: r,
    searcherByKey: t,
    allRegionsIndexes: a,
    getSearcher: f,
    getRegion: () => {
      const i = c();
      if (i !== void 0)
        return f()?.regionByIndex?.get(i);
    }
  };
}, Ao = /* @__PURE__ */ R({
  __name: "regionSelector",
  props: /* @__PURE__ */ _({
    projectId: {},
    searchers: { default: () => [] },
    modelValue: {},
    modelValueSingle: {},
    addCompare: { type: Boolean },
    forFrequency: { type: Boolean },
    autoRegion: { type: Boolean },
    onlySearcher: { type: Boolean },
    addChanger: { type: Boolean, default: !0 },
    addSearcherIcon: { type: Boolean, default: !0 },
    addRegionIcon: { type: Boolean, default: !0 }
  }, {
    modelValue: { required: !0 },
    modelModifiers: {},
    modelValueSingle: {},
    modelValueSingleModifiers: {}
  }),
  emits: ["update:modelValue", "update:modelValueSingle"],
  setup(e, { expose: t }) {
    const o = e, a = b(e, "modelValue"), n = b(e, "modelValueSingle"), {
      selectSearcher: l,
      selectRegion: r,
      compare: d,
      searcherByKey: c,
      allRegionsIndexes: f,
      getSearcher: C,
      getRegion: i
    } = Bt(o), g = () => {
      const s = [];
      c.value.forEach((u) => {
        u.enabled && u.regions.forEach((m) => {
          m.enabled && s.push(m);
        });
      }), kt.open("regions", {
        regions: s,
        regionsIndexes: d.regionsIndexes.value,
        "@update:regionsIndexes": (u) => d.regionsIndexes.value = u
      });
    };
    return G([r.regionIndex, l.searcherKey, d.regionsIndexes], () => {
      if (l.searcherKey.value === N && d.regionsIndexes.value.length) {
        if (JSON.stringify(a.value) === JSON.stringify(d.regionsIndexes.value))
          return;
        a.value = [...d.regionsIndexes.value];
      } else
        o.onlySearcher ? (a.value = [l.searcherKey.value], l.searcherKey.value === S && !o.autoRegion && (a.value.length = 0)) : (a.value = [r.regionIndex.value], r.regionIndex.value === S && !o.autoRegion && (a.value.length = 0));
      !o.onlySearcher && !f.value.size && (l.searcherKey.value = S);
    }), n.value && G(n, () => {
      n.value && (a.value = [n.value]);
    }, { immediate: !0 }), G(a, () => {
      if (a.value[0] && (n.value = a.value[0]), o.onlySearcher) {
        if (!a.value.length || a.value.length === 1 && !c.value.has(a.value[0]) || a.value.length === 1 && a.value[0] === S && !o.autoRegion) {
          let s = c.value.keys().next().value;
          s === S && !o.autoRegion && (s = void 0, n.value = S), s !== void 0 ? a.value = [s] : a.value.length = 0;
          return;
        }
        if (a.value.length > 1 && JSON.stringify(a.value) !== JSON.stringify(d.regionsIndexes.value)) {
          a.value = [...d.regionsIndexes.value];
          return;
        }
      } else {
        let s = [...new Set(a.value)], u = c.value.values().next().value?.regionByIndex?.keys().next().value;
        if (o.forFrequency && (u = c.value.values().next().value?.regionByIndex?.values().next().value?.key), u === S && !o.autoRegion && (u = void 0, n.value = S), !s.length)
          u !== void 0 && s.push(u);
        else if (s.length === 1) {
          let m = f.value;
          o.forFrequency && (m = /* @__PURE__ */ new Set(), c.value.forEach((W) => {
            W.regionByIndex.forEach((I) => {
              I.index !== de && I.index !== S && m.add(I.key);
            });
          })), m.has(s[0]) || (s = [], u !== void 0 && s.push(u));
        } else
          s = s.filter((m) => f.value.has(m)), !s.length && u !== void 0 && s.push(u);
        if (JSON.stringify(a.value) !== JSON.stringify(s)) {
          a.value = s;
          return;
        }
      }
      if (!(a.value.length === 1 && a.value[0] === (o.onlySearcher ? l.searcherKey.value : r.regionIndex.value)))
        if (o.onlySearcher) {
          if (a.value.length === 1) {
            l.searcherKey.value = a.value[0];
            return;
          }
          l.searcherKey.value = N;
          return;
        } else {
          if (!a.value.length)
            return;
          if (a.value.length === 1 && l.searcherKey.value !== N) {
            r.regionIndex.value = a.value[0];
            let s;
            for (const u of c.value.values()) {
              for (const m of u.regionByIndex.values())
                if ((o.forFrequency ? m.key : m.index) === r.regionIndex.value) {
                  s = u.key;
                  break;
                }
              if (s !== void 0)
                break;
            }
            s !== void 0 && (l.searcherKey.value = s);
          } else
            l.searcherKey.value = N, d.regionsIndexes.value = [...a.value];
        }
    }, { immediate: !0 }), t({
      getSearcher: C,
      getRegion: i
    }), (s, u) => (h(), T("div", {
      class: ae({
        "top-selectorRegion": !0,
        "top-selectorRegion-onlySearcher": e.onlySearcher
      })
    }, [
      O(Se, {
        options: v(l).optionBySearcherKey.value,
        modelValue: v(l).searcherKey.value,
        "onUpdate:modelValue": u[0] || (u[0] = (m) => v(l).searcherKey.value = m),
        name: "searcher_key",
        addChanger: e.addChanger
      }, null, 8, ["options", "modelValue", "addChanger"]),
      !e.onlySearcher && v(l).searcherKey.value !== v(N) ? (h(), j(Se, {
        key: 0,
        class: "top-select-region",
        options: v(r).optionByRegionIndex.value,
        modelValue: v(r).regionIndex.value,
        "onUpdate:modelValue": u[1] || (u[1] = (m) => v(r).regionIndex.value = m),
        name: e.forFrequency ? "region_key" : "region_index",
        addChanger: e.addChanger,
        "data-top-icon": e.addRegionIcon ? "" : void 0
      }, null, 8, ["options", "modelValue", "name", "addChanger", "data-top-icon"])) : E("", !0),
      e.addCompare && !e.onlySearcher && v(l).searcherKey.value === v(N) ? (h(), j(te, {
        key: 1,
        name: "compare",
        onClick: g,
        "data-count-compare-regions-indexes": v(d).regionsIndexes.value.length
      }, {
        default: A(() => [
          q(w(s.$i18n.Common.Selected_regions), 1)
        ]),
        _: 1
      }, 8, ["data-count-compare-regions-indexes"])) : E("", !0)
    ], 2));
  }
}), F = {
  id: 0,
  name: "/",
  path: "/"
};
function wt(e) {
  return e ? B()?.Common.All_folders : "/ (" + B()?.Keywords.Root_folder + ")";
}
const Ae = (e, t, o = /* @__PURE__ */ new Map(), a = { id: "root" }, n = 0) => (a.childsIds = [], a.id && (a.countAllGroupsActive = a.count_groups_active), e[a.id] && e[a.id].forEach((l) => {
  l = { ...l }, a.childsIds.push(l.id), l.id === 0 && (l.name = wt(t));
  const r = n > 1 ? "-".repeat(n - 1) + " " : "";
  r && !l.name.startsWith(r) && (l.name = r + l.name), o.set(l.id, l), Ae(e, t, o, l, n + 1), a.childsIds = a.childsIds.concat(l.childsIds), a.id && l.count_groups_active && (a.countAllGroupsActive += l.count_groups_active);
}), o), $t = (e, t) => e.gen(`/get/${t}/folders/`, ["id", "parent_id", "name", "path"]).changeParams({ orders: ["ord_path"], limit: 100 });
function Ie(e, t, o) {
  const a = Object.keys(e), n = a.map((l) => e[l]);
  return G(n, (l, r, d) => {
    const c = {};
    l.forEach((f, C) => {
      if (!Object.is(f, r[C])) {
        const i = a[C];
        c[i] = {
          old: r[C],
          new: f
        };
      }
    }), Object.keys(c).length && t(c, d);
  }, o);
}
const bt = /* @__PURE__ */ R({
  __name: "folders",
  props: /* @__PURE__ */ _({
    folderId: {},
    folder: {},
    folders: {},
    projectId: {},
    canSelectAll: { type: Boolean },
    addChanger: { type: Boolean },
    addIcon: { type: Boolean, default: !0 },
    client: {},
    service: {}
  }, {
    folderId: { required: !0 },
    folderIdModifiers: {},
    folder: { default: F },
    folderModifiers: {}
  }),
  emits: ["update:folderId", "update:folder"],
  setup(e) {
    const t = e, o = b(e, "folderId"), a = b(e, "folder"), n = t.client && !t.folders ? $t(t.client, t.service) : void 0, l = M(null);
    G(() => t.projectId, () => {
      n?.changeParams({
        project_id: t.projectId
      }), n?.setOptions({
        checkFingerprint: "TopGroupSelectorFolders:" + t.projectId
      }), l.value?.resetCache();
    }, { immediate: !0 });
    const r = P(() => Ae(t.folders ?? { root: [F] }, t.canSelectAll));
    return Ie({
      modelFolder: a,
      modelFolderId: o
    }, async (d) => {
      if (o.value === a.value.id)
        return;
      if (d.modelFolder && !d.modelFolderId) {
        o.value = a.value.id;
        return;
      }
      let c = r.value.get(t.folderId);
      c || (c = F), a.value = c, o.value = c.id;
    }, { immediate: !0 }), (d, c) => (h(), j(je, {
      class: "top-groupSelector_folder",
      modelValue: a.value,
      "onUpdate:modelValue": c[0] || (c[0] = (f) => a.value = f),
      items: e.folders ? [...r.value.values()] : void 0,
      "search-type": "inline",
      icon: e.addIcon ? "" : void 0,
      api: e.folders ? void 0 : v(n),
      apiSetSearchParams: (...f) => v(Fe)(...f, "name"),
      addChanger: e.addChanger,
      useCache: ""
    }, null, 8, ["modelValue", "items", "icon", "api", "apiSetSearchParams", "addChanger"]));
  }
}), ue = {
  id: -1,
  name: "--",
  folder_id: F.id,
  folder_path: F.path
}, ce = {
  id: qe,
  name: "All groups",
  folder_id: F.id,
  folder_path: F.path
}, ee = () => (ce.name = B()?.Common.All_groups, ce), ze = () => (ce.name = B()?.Keywords.Choose_group, ce), Pt = (e, t, o) => (e = [...e], t !== void 0 && (e = e.filter((a) => a.on == Number(t))), o && o.id && o.childsIds && (e = e.filter((a) => a.folder_id === o.id || o.childsIds.includes(a.folder_id))), e), Ee = (e, t) => e.gen(`/get/${t}/groups/`, ["id", "name", "folder_id", "folder_path"]).changeParams({ folder_id_depth: !0, limit: 100 }), Et = (e, t) => e.gen(`/add/${t}/groups/`), Mt = { class: "top-groupSelector_groupItem" }, Vt = {
  key: 0,
  class: "top-comment"
}, _t = {
  key: 1,
  class: "top-groupSelector_groupItemFolderPath"
}, Gt = /* @__PURE__ */ R({
  __name: "groups",
  props: /* @__PURE__ */ _({
    groupId: {},
    group: {},
    projectId: {},
    folder: {},
    groups: {},
    on: { type: Boolean, default: void 0 },
    canAdd: { type: [String, Boolean] },
    canSelectAll: { type: [Boolean, String] },
    autoselect: { default: "first" },
    addChanger: { type: Boolean, default: !0 },
    showPath: { type: Boolean },
    addIcon: { type: Boolean, default: !0 },
    client: {},
    service: {}
  }, {
    groupId: { required: !0 },
    groupIdModifiers: {},
    group: { required: !0 },
    groupModifiers: {}
  }),
  emits: /* @__PURE__ */ _(["addGroup"], ["update:groupId", "update:group"]),
  setup(e, { emit: t }) {
    const o = e, a = t, n = b(e, "groupId"), l = b(e, "group"), r = o.client && !o.groups ? Ee(o.client, o.service) : void 0, d = o.client ? Et(o.client, o.service) : void 0, c = M(null), f = M(void 0), C = ie("folder_id", "EQUALS", [o.folder?.id ?? 0]);
    r?.changeParams({
      project_id: o.projectId,
      folder_id_depth: !0,
      filters: [
        C
      ]
    }), o.on !== void 0 && r?.params.filters?.push(ie("on", "EQUALS", [Number(o.on)]));
    const i = (s) => {
      l.value = s, n.value = s.id;
    };
    Ie({
      projectId: () => o.projectId,
      folderId: () => o.folder?.id,
      canSelectAll: () => o.canSelectAll
    }, (s) => {
      if (s.projectId && (r?.changeParams({
        project_id: o.projectId
      }), r?.setOptions({
        checkFingerprint: "TopGroupSelectorGroups:" + o.projectId
      })), s.folderId && (C.values = [
        o.folder?.id ?? 0
      ], o.groups && (f.value = Pt(o.groups, o.on, o.folder))), c.value?.resetCache(), (s.folderId?.old !== void 0 || s.canSelectAll?.old !== void 0) && n.value !== pe) {
        let u;
        o.autoselect === "first" && (u = f.value?.[0], o.canSelectAll && (u = Oe(ee()))), (o.autoselect === "placeholder" || !u) && (u = ze()), i(u);
      }
    }, { immediate: !0 }), Ie({
      modelGroup: l,
      modelGroupId: n
    }, async (s) => {
      if (n.value !== l.value.id) {
        if (s.modelGroup && !s.modelGroupId) {
          n.value = l.value.id;
          return;
        }
        if (!(o.canAdd && n.value === pe)) {
          if (o.groups) {
            let u = f.value?.find((m) => m.id === n.value);
            if (!u && o.canSelectAll && (u = ee()), u)
              i(u);
            else {
              const m = f.value?.[0];
              m && !n.value ? i(m) : i(ue);
            }
          }
          if (o.client && !o.groups && (n.value || n.value === qe && !o.canSelectAll)) {
            const u = Ee(o.client, o.service).changeParams({
              project_id: o.projectId,
              id: n.value,
              filters: [
                C
              ]
            });
            u?.setOptions({
              checkFingerprint: "TopGroupSelectorFindGroup:" + o.projectId
            });
            const m = await u.call();
            if (!m.errors?.length && !m.result) return;
            !m.errors && m.result[0] ? i(m.result[0]) : i(ue);
          }
        }
      }
    }, { immediate: !0 });
    const g = async (s) => {
      if (o.canAdd !== "api" || !d) return;
      const u = l.value, m = await d.changeParams({
        project_id: o.projectId,
        names: [s.name],
        to_id: o.folder?.id ?? F.id,
        to_type: "in_folder_last"
      }).call();
      m.result ? (i(m.result), a("addGroup", m.result)) : i(u), c.value?.resetCache(!0);
    };
    return (s, u) => (h(), j(je, {
      ref_key: "refSelector",
      ref: c,
      class: "top-groupSelector_group",
      modelValue: l.value,
      "onUpdate:modelValue": u[0] || (u[0] = (m) => l.value = m),
      items: f.value ?? e.groups,
      searchType: "inline",
      icon: e.addIcon ? "" : void 0,
      api: e.groups ? void 0 : v(r),
      apiSetSearchParams: (...m) => v(Fe)(...m, "name"),
      appendSearchToResult: !!e.canAdd,
      useAllItem: e.canSelectAll ? v(ee)().name : !1,
      addChanger: e.addChanger,
      useCache: "",
      onAppendItem: g
    }, {
      item: A(({ item: m }) => [
        U("div", Mt, [
          m.id === v(pe) ? (h(), T("div", Vt, w(s.$i18n.Common.Add) + ": ", 1)) : E("", !0),
          U("span", null, w(m.name), 1),
          m.folder_path && e.showPath ? (h(), T("span", _t, w(m.folder_path), 1)) : E("", !0)
        ])
      ]),
      _: 1
    }, 8, ["modelValue", "items", "icon", "api", "apiSetSearchParams", "appendSearchToResult", "useAllItem", "addChanger"]));
  }
}), Lt = { class: "top-groupSelector" }, Bo = /* @__PURE__ */ R({
  __name: "groupSelector",
  props: /* @__PURE__ */ _({
    folderId: {},
    folder: {},
    groupId: {},
    group: {},
    projectId: {},
    folders: {},
    groups: {},
    on: { type: Boolean, default: void 0 },
    canSelectAllGroups: { type: Boolean },
    canAddGroup: {},
    autoselect: { default: "first" },
    addChanger: { type: Boolean, default: !0 },
    showFolders: { type: Boolean, default: !0 },
    showGroups: { type: Boolean, default: !0 },
    addIcon: { type: Boolean, default: !0 },
    client: {},
    service: { default: "keywords_2" }
  }, {
    folderId: { required: !0 },
    folderIdModifiers: {},
    folder: {},
    folderModifiers: {},
    groupId: { required: !0 },
    groupIdModifiers: {},
    group: { default: ue },
    groupModifiers: {}
  }),
  emits: /* @__PURE__ */ _(["update:groups"], ["update:folderId", "update:folder", "update:groupId", "update:group"]),
  setup(e, { emit: t }) {
    const o = e, a = b(e, "folderId"), n = b(e, "folder"), l = b(e, "groupId"), r = b(e, "group"), d = t, c = Ae(o.folders ?? { root: [F] }, o.canSelectAllGroups);
    n.value = c.get(a.value);
    let f = o.groups?.find((i) => i.id === l.value);
    l.value || (f = o.groups?.[0]), o.canSelectAllGroups && !f && (f = ee()), o.canSelectAllGroups && !f && (f = ee()), (o.autoselect === "placeholder" || !f) && (f = ze()), f ??= ue, r.value = f;
    const C = (i) => {
      let g;
      o.groups && i && (g = [...o.groups, i]), d("update:groups", g);
    };
    return (i, g) => (h(), T("div", Lt, [
      e.showFolders ? (h(), j(bt, {
        key: 0,
        folderId: a.value,
        "onUpdate:folderId": g[0] || (g[0] = (s) => a.value = s),
        folder: n.value,
        "onUpdate:folder": g[1] || (g[1] = (s) => n.value = s),
        projectId: e.projectId,
        folders: e.folders,
        canSelectAll: e.canSelectAllGroups,
        addChanger: e.addChanger,
        addIcon: e.addIcon,
        client: e.client,
        service: e.service
      }, null, 8, ["folderId", "folder", "projectId", "folders", "canSelectAll", "addChanger", "addIcon", "client", "service"])) : E("", !0),
      e.showGroups ? (h(), j(Gt, {
        key: 1,
        groupId: l.value,
        "onUpdate:groupId": g[2] || (g[2] = (s) => l.value = s),
        group: r.value,
        "onUpdate:group": g[3] || (g[3] = (s) => r.value = s),
        projectId: e.projectId,
        folder: n.value,
        groups: e.groups,
        on: e.on,
        canAdd: e.canAddGroup,
        canSelectAll: e.canSelectAllGroups,
        autoselect: e.autoselect,
        addChanger: e.addChanger,
        showPath: e.showFolders && !!e.folders?.[0],
        addIcon: e.addIcon,
        client: e.client,
        service: e.service,
        onAddGroup: C
      }, null, 8, ["groupId", "group", "projectId", "folder", "groups", "on", "canAdd", "canSelectAll", "autoselect", "addChanger", "showPath", "addIcon", "client", "service"])) : E("", !0)
    ]));
  }
}), Rt = { class: "top-projectSelectorSubmenu_item" }, Kt = ["href", "title", "data-top-icon", "data-right"], Ot = { class: "top-projectSelectorSubmenu_item" }, Ut = ["href"], Nt = /* @__PURE__ */ R({
  __name: "submenu",
  props: {
    id: {},
    right: {},
    url: {}
  },
  setup(e) {
    const t = e, o = B(), a = [
      {
        href: `/project/keywords/${t.id}/`,
        title: o.Common.Menu_phrases,
        icon: "",
        right: "2"
      },
      {
        href: `/project/dynamics/${t.id}/`,
        title: o.Common.Menu_dynamics,
        icon: "",
        right: "1"
      },
      {
        href: `/project/snapshots/${t.id}/`,
        title: o.Common.Menu_snapshots,
        icon: "",
        right: "1"
      },
      {
        href: `/project/competitors/${t.id}/`,
        title: o.Common.Menu_competitors,
        icon: "",
        right: "1"
      },
      {
        href: `/project/analytics/${t.id}/`,
        title: o.Common.Menu_analytics,
        icon: "",
        right: "5"
      },
      {
        href: `/project/broker/${t.id}/`,
        title: o.Common.Menu_broker,
        icon: "",
        right: "6"
      },
      {
        href: `/project/audit/${t.id}/sitemap/`,
        title: o.Audit.Sitemap_gen,
        icon: "",
        right: "8"
      },
      {
        href: `/project/audit/${t.id}/audit/`,
        title: o.Common.Menu_audit,
        icon: "",
        right: "8"
      },
      {
        href: `/project/audit/${t.id}/indexing/`,
        title: o.Audit.Indexing,
        icon: "",
        right: "8"
      },
      {
        href: `/project/audit/${t.id}/watcher/`,
        title: o.Audit.Watcher,
        icon: "",
        right: "9"
      },
      {
        href: `/project/settings/${t.id}/`,
        title: o.Common.Menu_settings,
        icon: "",
        right: "2"
      }
    ], n = P(() => t.right.includes("0") ? a.filter((l) => t.right[l.right] === "1") : a);
    return (l, r) => {
      const d = Ue("TopButton");
      return h(), j(v(ke), {
        class: "top-projectSelectorSubmenu",
        notch: !1,
        pos: "2"
      }, {
        opener: A(() => [
          O(d, {
            class: "top-projectSelectorSubmenu_opener",
            "data-top-icon": "",
            color: "theme"
          })
        ]),
        contentList: A(() => [
          (h(!0), T(D, null, me(n.value, (c) => (h(), T("li", Rt, [
            U("a", {
              href: c.href,
              title: c.title,
              "data-top-icon": c.icon,
              "data-right": c.right
            }, null, 8, Kt)
          ]))), 256)),
          U("li", Ot, [
            U("a", {
              href: e.url,
              "data-top-icon": "",
              target: "_blank"
            }, null, 8, Ut)
          ])
        ]),
        _: 1
      });
    };
  }
}), ye = (e) => ({
  id: null,
  name: e,
  listItemProps: {
    type: "title"
  }
}), xe = {
  scheduledUpdate: !1,
  manualUpdate: !1,
  guestProjects: !1
}, Dt = (e, t) => {
  const o = [], a = {
    scheduledUpdate: ye(B().Projects.Scheduled_update),
    manualUpdate: ye(B().Projects.Manual_update),
    guestProjects: ye(B().Projects.Guest_projects)
  }, n = t ? {
    scheduledUpdate: !1,
    manualUpdate: !1,
    guestProjects: !1
  } : xe;
  for (const l of e)
    !n.scheduledUpdate && l.right?.startsWith("1") && l.on > 0 && (o.push(a.scheduledUpdate), n.scheduledUpdate = !0), !n.manualUpdate && l.right?.startsWith("1") && l.on === 0 && (o.push(a.manualUpdate), n.manualUpdate = !0), !n.guestProjects && l.right?.startsWith("0") && l.on >= 0 && (o.push(a.guestProjects), n.guestProjects = !0), o.push(l);
  return o;
}, Ft = (e) => e.map((t) => ({
  ...t,
  listItemProps: {
    attrs: { title: t.name }
  }
})), qt = (e, t, o) => {
  if (!e || e.length === 0) return [];
  t && Object.keys(xe).forEach((n) => xe[n] = !1);
  const a = Ft(e);
  return Dt(a, o);
}, Wt = (e) => {
  if (!e) return "";
  let t = e;
  return t = t.replace(/historyView=[^&]*/, ""), t = t.replace(/competitorsIds=[^&]*/, ""), t = t.replace(/searchersKeys=[^&]*/, ""), t = t.replace(/regionIndex=[^&]*/, ""), t = t.replace(/regionsIndexes=[^&]*/, ""), t = t.replace(/folderId=[^&]*/, ""), t = t.replace(/groupId=[^&]*/, ""), t = t.replace(/tags=[^&]*/, ""), window.mo?.getHash && !window.mo.getHash("dataSort").toString().includes("0000-00-00") && (t = t.replace(/dataSort=[^&]*/, "")), t = t.replace(/%22historyView%22:[^,]*,/, ""), t = t.replace(/%22competitorsIds%22:\[[^\]]*],/, ""), t = t.replace(/%22searchersKeys%22:\[[^\]]*],/, ""), t = t.replace(/%22regionIndex%22:[^,]*,/, ""), t = t.replace(/%22regionsIndexes%22:\[[^\]]*],/, ""), t = t.replace(/%22folderId%22:[^,]*,/, ""), t = t.replace(/%22groupId%22:[^,]*,/, ""), t = t.replace(/%22tagsIds%22:\[[^\]]*],/, ""), /%22dataSort%22:\{[^}]*0000-00-00[^}]*}/.test(t) || (t = t.replace(/%22dataSort%22:\{[^}]*},/, "")), t;
}, Ht = (e) => {
  const t = location.pathname.split("/");
  let o = "project/dynamics/", a = "";
  t[1] == "project" && (o = t[1] + "/" + t[2] + "/"), ["watcher", "indexing", "sitemap", "audit", "direct", "adwords"].includes(t[4]) && (a = t[4] + "/");
  let n = "/" + o + e + "/" + a;
  const l = Wt(location.hash);
  return n += l, n;
}, Me = (e) => {
  let t = e.startsWith("http") ? e : "http://" + e;
  return t = t.replace(/"/g, "%22"), t;
}, Jt = (e, t) => {
  let o = e.params.filters ?? [];
  o = o.filter((r) => r.name !== "GEN_SEARCH_STRING()");
  const a = gt(t), n = t.replace(/([[^$.|?*+()])/g, "\\$1"), l = a.replace(/([[^$.|?*+()])/g, "\\$1");
  t && o.push(ie("GEN_SEARCH_STRING()", "REGEXP", [`(${n}|${l})`])), e.changeParams({ filters: o });
}, Ve = (e, t, o) => {
  const a = e.gen("/get/projects_2/projects/", ["id", "user_id", "name", "url", "on", "right"]);
  return a.params = {
    ...o,
    filters: [
      ie("on", "GREATER_THAN_EQUALS", [0])
    ],
    orders: [
      ne("user_id", "DESC", [t]),
      ne("on", "DESC"),
      ne("favorite", "DESC"),
      ne("id", "DESC")
    ]
  }, a.options.onApiLoaded = (n, l, r) => {
    const d = l.data.filters.length === 1 && l.data.offset === 0 || l.data.limit === 1e3, c = l.data.limit === 100 && l.data.filters.length > 1 ? !0 : void 0;
    n.result = qt(n.result, d, c), r?.(n, l);
  }, a;
}, zt = (e) => e.gen("/add/projects_2/projects/"), fe = "ui_project_selector_total:", Yt = 1440 * 60 * 1e3, V = Ne(), Ye = M(0), Q = M(null), _e = (e, t) => {
  localStorage.setItem(
    fe + e,
    JSON.stringify({ projectsTotal: t, expiresAt: Date.now() + Yt })
  );
}, Qt = (e) => {
  const t = localStorage.getItem(fe + e);
  if (!t) return;
  const { projectsTotal: o, expiresAt: a } = JSON.parse(t);
  if (Date.now() > a) {
    localStorage.removeItem(fe + e);
    return;
  }
  return o;
}, Xt = (e, t = !0) => {
  V.value = void 0, localStorage.removeItem(fe + e), t && Ye.value++;
}, Zt = { class: "top-projectSelector_item" }, eo = { class: "top-projectSelector_itemText" }, to = { class: "top-comment" }, oo = {
  key: 0,
  class: "top-comment"
}, ao = ["href"], Ge = 1e3, wo = /* @__PURE__ */ R({
  __name: "projectSelector",
  props: /* @__PURE__ */ _({
    client: {},
    project: {},
    addLinksToProjects: { type: Boolean, default: !0 },
    excludeProjectId: {},
    modificator: {},
    placeholder: {},
    buttonProps: {},
    openerShortcut: {}
  }, {
    project: { default: { id: null, name: "" } },
    projectModifiers: {}
  }),
  emits: ["update:project"],
  setup(e) {
    const t = B();
    if (!window.mo?.user?.id)
      throw new Error("TopProjectSelector: не удалось определить userId. Компонент требует авторизованного пользователя (см. window.mo.user.id)");
    const o = window.mo.user.id, a = e, n = b(e, "project"), l = Ve(
      a.client,
      o
    ), r = zt(a.client), d = M(Qt(o)), c = M(null), f = P(() => a.placeholder ?? t.Projects.Select_project), C = P(() => !V.value || !a.excludeProjectId ? V.value : V.value.filter((I) => I.id !== a.excludeProjectId)), i = P(() => {
      if (!(!d.value && d.value !== 0))
        return d.value < Ge ? "static" : "api";
    });
    G(Ye, () => {
      m();
    });
    const g = async () => {
      if (!Q.value) {
        const L = Ve(
          a.client,
          o,
          { limit: Ge }
        );
        Q.value = L.call();
      }
      const I = await Q.value;
      if (I.errors) {
        Q.value = null;
        return;
      }
      return Q.value = null, I;
    }, s = async () => {
      if (d.value) return;
      const I = await g();
      I && (d.value = I.total, i.value === "static" && !V.value && (V.value = I.result), d.value && _e(o, d.value));
    }, u = async (I) => {
      const L = await r.changeParams({
        url: I.name,
        name: I.name
      }).call();
      if (!L.errors) {
        if (V.value && i.value === "static") {
          const y = {
            id: Number(L.result),
            user_id: o,
            name: I.name,
            url: I.name,
            on: 0,
            right: "11111111111111111111",
            listItemProps: {
              attrs: { title: I.name }
            }
          }, p = V.value.findIndex((x) => x.on === 0);
          V.value = [
            ...V.value.slice(0, p),
            y,
            ...V.value.slice(p)
          ], d.value && (d.value += 1, _e(o, d.value));
        }
        i.value === "api" && Xt(o);
      }
    }, m = () => {
      i.value === "api" && c.value?.resetCache(!0);
    }, W = async () => {
      if (V.value || i.value !== "static") return;
      const I = await g();
      I && (V.value = I.result);
    };
    return Qe(async () => {
      await s();
    }), (I, L) => {
      const y = Ue("TopButton");
      return h(), j(je, {
        ref_key: "refSelector",
        ref: c,
        class: "top-projectSelector",
        modelValue: n.value,
        "onUpdate:modelValue": L[1] || (L[1] = (p) => n.value = p),
        items: C.value,
        title: I.$i18n.Projects.Search_projects,
        modificator: e.modificator,
        searchFields: ["id", "name", "url"],
        placeholder: f.value,
        hasCloserBtn: "",
        api: i.value === "api" ? v(l) : void 0,
        apiSetSearchParams: i.value === "api" ? (...p) => v(Jt)(...p) : void 0,
        useCache: "",
        appendSearchToResult: "",
        appendSearchAllowDuplicate: "",
        appendSearchToResultCond: v(ct),
        appendWithoutSelect: "",
        buttonProps: e.buttonProps,
        openerShortcut: e.openerShortcut,
        onAppendItem: u,
        onOpen: W
      }, {
        item: A(({ item: p }) => [
          U("div", Zt, [
            U("div", eo, [
              p.id ? (h(), T(D, { key: 0 }, [
                q(w(v(ft)(p.name, 20)) + " ", 1),
                U("span", to, " id " + w(p.id), 1)
              ], 64)) : (h(), T(D, { key: 1 }, [
                p.listItemProps?.type ? E("", !0) : (h(), T("div", oo, w(I.$i18n.Projects.Add_project) + ": ", 1)),
                q(" " + w(p.name), 1)
              ], 64))
            ]),
            p.id ? (h(), T(D, { key: 0 }, [
              e.addLinksToProjects ? (h(), T("a", {
                key: 0,
                class: "top-projectSelector_itemLink",
                href: v(Ht)(p.id)
              }, null, 8, ao)) : E("", !0),
              I.$core.state.isMobile ? E("", !0) : (h(), j(y, {
                key: 1,
                class: "top-projectSelector_itemExtLink",
                href: v(Me)(p.url),
                "data-top-icon": "",
                color: "theme",
                target: "_blank",
                onClick: L[0] || (L[0] = H(() => {
                }, ["stop"]))
              }, null, 8, ["href"])),
              O(Nt, {
                id: p.id,
                right: p.right ?? void 0,
                url: v(Me)(p.url)
              }, null, 8, ["id", "right", "url"])
            ], 64)) : E("", !0)
          ])
        ]),
        _: 1
      }, 8, ["modelValue", "items", "title", "modificator", "placeholder", "api", "apiSetSearchParams", "appendSearchToResultCond", "buttonProps", "openerShortcut"]);
    };
  }
}), Le = (e) => "-" + e, oe = (e) => e[0] === "-" ? e.substring(1) : e, ge = (e, t) => {
  e = oe(e);
  const o = t.find((a) => a.id === e);
  if (o)
    return o;
}, $o = (e, t, o) => {
  t || (t = { id: e.id }), t.id = e.id, t.pos ??= "3", t.notch ??= !0, t.posBy ??= "fixed";
  const a = mt.genElPopupOpener("div", t);
  return a.classList.add("top-tagSelector"), e.useTopButton && a.classList.add("top-tagSelector-useTopButton", "top-button", "top-color_theme", "top-as-selector"), e.useTopButton || a.classList.add("top-tagSelector-custom"), e.mode === "filter" && a.classList.add("top-tagSelector-filter"), e.mode === "setter" && !e.filters && a.classList.add("top-tagSelector-setter_single"), e.mode === "setter" && e.filters && a.classList.add("top-tagSelector-setter_several"), a.onclick = (n) => {
    n.preventDefault(), n.stopPropagation(), a.onclick = null;
    const l = M(e.modelValue), r = {
      model: l,
      mode: e.mode,
      targetId: e.targetId,
      filters: e.filters,
      payload: e.payload
    };
    Z(a, "topTagSelectorTarget", r), delete a.dataset.topPopupDisabled, we(e.modelValue) || G(l, () => {
      e.modelValue = l.value, re(a, e, o);
    }), a.click();
  }, we(e.modelValue) ? G(e.modelValue, () => re(a, e, o)) : Z(a, "topTagSelectorRender", (n) => {
    e.modelValue = n;
    const l = Z(a, "topTagSelectorTarget");
    l && (l.model.value = n), re(a, e, o);
  }), re(a, e, o), a;
}, bo = (e, t) => {
  Z(e, "topTagSelectorRender")?.(t);
}, re = (e, t, o) => {
  const a = v(t.modelValue);
  if (e.classList.toggle("top-tagSelector-selectedOne", !a.length || a.length === 1), e.classList.toggle("top-tagSelector-toTwoLine", a.length > 5), t.mode === "setter" && t.filters) {
    e.innerHTML = `<div>${o}</div>`;
    return;
  }
  if (e.innerHTML = "", !a.length && t.mode === "filter") {
    const n = Re({
      id: "all",
      colorId: "",
      name: B().Common?.All_tags ?? "",
      state: ""
    });
    e.append(n);
  }
  a.forEach((n) => {
    const l = Re({
      id: oe(n),
      colorId: ge(n, t.tags)?.color_id ?? "",
      name: ge(n, t.tags)?.name ?? "",
      state: oe(n) === n ? "selected" : "excluded"
    });
    e.append(l);
  });
}, Re = (e) => {
  const t = document.createElement("div");
  return t.classList.add("top-tagSelector_tagIcon"), t.classList.toggle("top-tagSelector-active", !!e.state), t.classList.toggle("top-tagSelector-excluded", e.state === "excluded"), t.dataset.tag_id = e.id, t.dataset.tag_color_id = e.colorId, t.title = e.name, t;
}, lo = [
  {
    id: "1",
    name: "Without Tag",
    color_id: "1"
  },
  {
    id: "2",
    name: "Red",
    color_id: "2"
  },
  {
    id: "3",
    name: "Orange",
    color_id: "3"
  },
  {
    id: "4",
    name: "Yellow",
    color_id: "4"
  },
  {
    id: "5",
    name: "Blue",
    color_id: "5"
  },
  {
    id: "6",
    name: "Purple",
    color_id: "6"
  },
  {
    id: "7",
    name: "Green",
    color_id: "7"
  },
  {
    id: "8",
    name: "Magenta",
    color_id: "8"
  },
  {
    id: "9",
    name: "Dark blue",
    color_id: "9"
  },
  {
    id: "10",
    name: "Turquoise",
    color_id: "10"
  }
], no = ["data-tag_id", "data-tag_color_id", "title"], Ce = /* @__PURE__ */ R({
  __name: "tagIcon",
  props: {
    id: {},
    colorId: {},
    name: {},
    state: {}
  },
  setup(e) {
    return (t, o) => (h(), T("div", {
      class: ae({
        "top-tagSelector_tagIcon": !0,
        "top-tagSelector-active": !!e.state,
        "top-tagSelector-excluded": e.state === "excluded"
      }),
      "data-tag_id": e.id,
      "data-tag_color_id": e.colorId,
      title: e.name
    }, null, 10, no));
  }
}), ro = ["contenteditable", "onKeydown"], Ke = /* @__PURE__ */ R({
  __name: "tagPopupListItem",
  props: /* @__PURE__ */ _({
    editable: { type: Boolean },
    disabled: { type: Boolean },
    canExclude: { type: Boolean },
    id: {},
    colorId: {},
    name: {},
    state: {}
  }, {
    name: {
      required: !0
    },
    nameModifiers: {}
  }),
  emits: /* @__PURE__ */ _(["update:name", "unselect", "exclude", "select"], ["update:name"]),
  setup(e, { emit: t }) {
    const o = e, a = t, n = b(e, "name"), l = M(null), r = P(() => navigator.userAgent.indexOf("Firefox") != -1 ? {
      contenteditable: d.value,
      onpaste: (g) => g.preventDefault()
    } : {}), d = M(!1), c = async () => {
      d.value = !0, await Xe(), l.value?.focus();
    }, f = () => {
      const g = l.value?.innerText;
      if (!g) return C();
      l.value && (l.value.innerText = g), d.value = !1, a("update:name", g);
    }, C = async () => {
      l.value && (l.value.innerText = o.name), d.value = !1;
    }, i = (g) => {
      if (d.value || o.disabled) return;
      let s = "selected";
      o.canExclude && (g.ctrlKey || g.metaKey) && (s = "excluded"), o.state == s && (s = ""), s === "" && a("unselect"), s === "selected" && a("select"), s === "excluded" && a("exclude");
    };
    return (g, s) => (h(), j(Te, {
      class: ae({
        "top-tagSelector_tagListItem": !0,
        "top-tagSelector_tagListItem-inEdit": d.value,
        "top-tagSelector_tagListItem-disabled": e.disabled,
        "top-tagSelector_tagListItem-canExclude": e.canExclude,
        "top-tagSelector-active": !!e.state,
        "top-tagSelector-excluded": e.state === "excluded"
      }),
      onClick: H(i, ["stop"])
    }, {
      default: A(() => [
        O(Ce, {
          id: e.id,
          name: n.value,
          colorId: e.colorId,
          state: e.state
        }, null, 8, ["id", "name", "colorId", "state"]),
        U("span", De({
          ref_key: "elName",
          ref: l,
          class: "top-tagSelector_tagListItemName",
          contenteditable: d.value ? "plaintext-only" : !1
        }, r.value, {
          onKeydown: [
            $e(H(f, ["stop"]), ["enter"]),
            $e(H(C, ["stop"]), ["esc"])
          ]
        }), w(n.value), 17, ro),
        e.editable ? (h(), T(D, { key: 0 }, [
          d.value ? (h(), T("span", {
            key: 1,
            "data-top-icon": "",
            class: "top-tagSelector_edit",
            onClick: H(f, ["stop"])
          })) : (h(), T("span", {
            key: 0,
            "data-top-icon": "",
            class: "top-tagSelector_edit",
            onClick: c
          }))
        ], 64)) : E("", !0)
      ]),
      _: 1
    }, 8, ["class"]));
  }
}), io = { key: 1 }, so = /* @__PURE__ */ R({
  inheritAttrs: !1,
  __name: "popupOpener",
  props: /* @__PURE__ */ _({
    modelValue: {},
    id: {},
    tags: {},
    mode: {},
    targetId: {},
    filters: {},
    useTopButton: { type: Boolean },
    payload: {},
    styling: {}
  }, {
    modelValue: {
      required: !0
    },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(e) {
    const t = e, o = b(e, "modelValue"), a = t.useTopButton ? te : "div", n = t.useTopButton ? "html" : "default", l = {
      model: o,
      mode: t.mode,
      targetId: t.targetId,
      filters: t.filters,
      payload: t.payload
    };
    return (r, d) => {
      const c = Ze("top-data");
      return h(), j(nt, { id: e.id }, {
        default: A(() => [
          et((h(), j(tt(v(a)), De({
            class: {
              "top-tagSelector": !0,
              "top-tagSelector-useTopButton": t.useTopButton,
              "top-tagSelector-custom": !t.useTopButton,
              "top-as-selector": t.useTopButton,
              "top-tagSelector-filter": t.mode === "filter",
              "top-tagSelector-setter_single": t.mode === "setter" && !e.filters,
              "top-tagSelector-setter_several": t.mode === "setter" && e.filters,
              "top-tagSelector-selectedOne": !o.value.length || o.value.length === 1,
              "top-tagSelector-toTwoLine": o.value.length > 5
            },
            color: "theme",
            styling: e.styling
          }, r.$attrs), {
            [v(n)]: A(() => [
              !o.value.length && e.mode === "filter" ? (h(), j(Ce, {
                key: 0,
                id: "all",
                colorId: "",
                name: r.$i18n.Common.All_tags ?? "",
                state: ""
              }, null, 8, ["name"])) : E("", !0),
              e.mode === "setter" && e.filters ? (h(), T("div", io, [
                ot(r.$slots, "default")
              ])) : (h(!0), T(D, { key: 2 }, me(o.value, (f) => (h(), j(Ce, {
                id: v(oe)(f),
                colorId: v(ge)(f, e.tags)?.color_id ?? "",
                name: v(ge)(f, e.tags)?.name ?? "",
                state: v(oe)(f) === f ? "selected" : "excluded"
              }, null, 8, ["id", "colorId", "name", "state"]))), 256))
            ]),
            _: 2
          }, 1040, ["class", "styling"])), [
            [c, l, "topTagSelectorTarget"]
          ])
        ]),
        _: 3
      }, 8, ["id"]);
    };
  }
}), Po = /* @__PURE__ */ R({
  __name: "tagSelector",
  props: /* @__PURE__ */ _({
    modelValue: {},
    tags: {},
    tagsEditable: { type: Boolean },
    tagsMax: { default: 10 },
    id: {},
    singleMode: { type: Boolean },
    requiredForSetter: { type: Boolean, default: !0 },
    maxTagsForSetter: {},
    emitDelay: { default: 500 },
    useTopButton: { type: Boolean, default: !0 },
    styling: {}
  }, {
    modelValue: {
      required: !0
    },
    modelModifiers: {},
    tags: {
      default: Oe(lo)
    },
    tagsModifiers: {}
  }),
  emits: /* @__PURE__ */ _(["selector", "setter", "tagsChanged"], ["update:modelValue", "update:tags"]),
  setup(e, { emit: t }) {
    const o = B(), a = e, n = b(e, "modelValue"), l = b(e, "tags"), r = t, d = lt((y, p) => {
      r(y, p);
    }, a.emitDelay);
    a.singleMode && !n.value.length && (n.value = [l.value[0].id]);
    const c = a.id ?? "top-popup-id-" + Math.random(), f = M("add"), C = () => {
      const y = " " + o.Common.Tags?.toLowerCase(), p = /* @__PURE__ */ new Map();
      return p.set("add", { value: "add", title: o.Common.Add + y }), p.set("replace", { value: "replace", title: o.Common.Replace + y }), p.set("delete", { value: "delete", title: o.Common.Delete + y }), p;
    };
    let i = Ne({
      model: n,
      mode: "filter",
      targetId: void 0,
      filters: void 0,
      payload: void 0
    });
    G(n, () => {
      d("selector", n.value);
    });
    const g = P(() => {
      if (i.value.mode === "setter" && a.maxTagsForSetter && !i.value.filters)
        return i.value.model.value.length >= a.maxTagsForSetter;
    }), s = (y) => {
      if (y !== "all") {
        if (i.value.model.value.includes(y)) return "selected";
        if (i.value.model.value.includes(Le(y))) return "excluded";
      }
      return y === "all" && !i.value.model.value.length ? "selected" : "";
    }, u = (y, p) => {
      const x = Le(y);
      let k = i.value.model.value.filter((K) => K !== y && K !== x);
      p === "select" && k.push(y), p === "exclude" && k.push(x), i.value.mode === "setter" && i.value.targetId !== void 0 && a.requiredForSetter && (k.length || k.push("1"), k.length === 2 && i.value.model.value.length === 1 && i.value.model.value[0] === "1" && (k = k.filter((K) => K !== "1"))), a.singleMode && !i.value.filters && (k.length || (k = i.value.model.value), k.length > 1 && (k = [k[k.length - 1]])), k.sort((K, le) => {
        if (!a.tags) return 0;
        const J = a.tags.findIndex((Y) => Y.id === K), z = a.tags.findIndex((Y) => Y.id === le);
        return J - z;
      }), i.value.model.value = k, i.value.mode === "setter" && i.value.targetId !== void 0 && d("setter", {
        tagsIds: k,
        targetId: i.value.targetId,
        payload: i.value.payload
      });
    }, m = P(() => {
      let y = "top-tagSelector_popup";
      return i.value.mode === "filter" && (y += " top-tagSelector_popup-filter"), i.value.mode === "setter" && (y += " top-tagSelector_popup-setter"), y;
    }), W = () => {
      const y = prompt("", "New tag");
      if (!y || y === "New tag") return;
      const p = l.value.length + 1;
      l.value.push({
        id: String(p),
        name: y,
        color_id: String((p - 1) % 10 + 1)
      }), r("tagsChanged", l.value);
    }, I = (y) => {
      if (i.value = Z(y.elPopupOpener, "topTagSelectorTarget"), !i.value) throw new Error("Open popup TopTagSelector required v-data:topTagSelectorTarget");
      if (i.value.filters && (f.value = "add", i.value.model.value = []), !X.$?.ui.sortable) {
        console.info("Для работы сортировки требуется глобальная загрузка jQuery UI Sortable");
        return;
      }
      !X.state.isMobile && !X.state.isMobileUA && l.value && $(y.elPopup).sortable({
        items: 'li:has([data-tag_id]:not([data-tag_id="all"]))',
        /**
         * @todo Удалить `[contenteditable="true"]` через пол года после выхода версии firefox с поддержкой contenteditable plaintext-only, включая бета версии
         */
        cancel: '[contenteditable="plaintext-only"], [contenteditable="true"]',
        distance: 10,
        stop: function(p, x) {
          if (!l.value) return;
          const k = $(x.item).parent().find("[data-tag_id]"), K = [];
          k.each((le, J) => {
            if (!l.value) return;
            const z = $(J).attr("data-tag_id");
            K.push(z);
          }), l.value.sort((le, J) => {
            const z = K.findIndex((ve) => ve === le.id), Y = K.findIndex((ve) => ve === J.id);
            return z - Y;
          }), d("tagsChanged", l.value);
        }
      });
    }, L = (y) => {
      X.$?.ui.sortable && $(y.elPopup).data("ui-sortable") && $(y.elPopup).sortable("destroy");
    };
    return (y, p) => (h(), T(D, null, [
      O(so, {
        modelValue: n.value,
        "onUpdate:modelValue": p[0] || (p[0] = (x) => n.value = x),
        id: v(c),
        tags: l.value,
        styling: e.styling,
        mode: "filter",
        useTopButton: e.useTopButton
      }, null, 8, ["modelValue", "id", "tags", "styling", "useTopButton"]),
      O(ke, {
        id: v(c),
        class: ae(m.value),
        onOpen: p[4] || (p[4] = (x) => I(x)),
        onClose: p[5] || (p[5] = (x) => L(x)),
        "transition-duration": 50
      }, at({
        contentList: A(() => [
          v(i).mode === "filter" && !e.singleMode ? (h(), j(Ke, {
            key: 0,
            id: "all",
            colorId: "",
            name: y.$i18n.Common.All_tags ?? "",
            state: v(i).model.value.length ? "" : "selected",
            onSelect: p[3] || (p[3] = (x) => v(i).model.value = [])
          }, null, 8, ["name", "state"])) : E("", !0),
          (h(!0), T(D, null, me(l.value, (x) => (h(), j(Ke, {
            key: x.id,
            id: x.id,
            colorId: x.color_id,
            name: x.name,
            state: s(x.id),
            canExclude: v(i).mode === "filter" && !e.singleMode,
            editable: e.tagsEditable,
            disabled: g.value && s(x.id) === "",
            onUnselect: (k) => u(x.id, "unselect"),
            onSelect: (k) => u(x.id, "select"),
            onExclude: (k) => u(x.id, "exclude"),
            "onUpdate:name": (k) => {
              x.name = k, v(d)("tagsChanged", l.value);
            }
          }, null, 8, ["id", "colorId", "name", "state", "canExclude", "editable", "disabled", "onUnselect", "onSelect", "onExclude", "onUpdate:name"]))), 128)),
          e.tagsEditable && l.value.length < e.tagsMax && l.value.length < 20 ? (h(), j(Te, {
            key: 1,
            "data-top-icon": "",
            onClick: H(W, ["stop"])
          }, {
            default: A(() => [
              q(w(y.$i18n.Common.Add), 1)
            ]),
            _: 1
          })) : E("", !0)
        ]),
        _: 2
      }, [
        v(i).mode === "setter" && v(i).filters ? {
          name: "header",
          fn: A(() => [
            O(Se, {
              modelValue: f.value,
              "onUpdate:modelValue": p[1] || (p[1] = (x) => f.value = x),
              options: C()
            }, null, 8, ["modelValue", "options"])
          ]),
          key: "0"
        } : void 0,
        v(i).mode === "setter" && v(i).filters ? {
          name: "footer",
          fn: A(() => [
            O(te, { color: "theme" }, {
              default: A(() => [
                q(w(y.$i18n.Common.Cancel), 1)
              ]),
              _: 1
            }),
            O(te, {
              onClick: p[2] || (p[2] = (x) => v(d)("setter", {
                tagsIds: v(i).model.value,
                filters: v(i).filters,
                filtersAction: f.value,
                payload: v(i).payload
              }))
            }, {
              default: A(() => [
                q(w(f.value === "add" ? y.$i18n.Common.Add : "") + " " + w(f.value === "replace" ? y.$i18n.Common.Replace : "") + " " + w(f.value === "delete" ? y.$i18n.Common.Delete : ""), 1)
              ]),
              _: 1
            })
          ]),
          key: "1"
        } : void 0
      ]), 1032, ["id", "class"])
    ], 64));
  }
});
export {
  To as TopCompetitorSelector,
  Bo as TopGroupSelector,
  wo as TopProjectSelector,
  Ao as TopRegionSelector,
  Po as TopTagSelector,
  so as TopTagSelectorPopupOpener,
  Ce as TopTagSelectorTagIcon,
  Xt as clearCache,
  kt as dialogRegionSelector,
  Ct as findRegion,
  $o as genElTopTagSelectorPopupOpener,
  He as genSearcherByKey,
  bo as renderElTopTagSelectorPopupOpener,
  jo as useItemsFromCompetitors
};
//# sourceMappingURL=project.js.map
