
		import { Core as _autoloadCSSCore } from '../core/app.js';
		const fileNames = ['../assets/dialog_regionSelectorRegions.css'].map(fileName => import.meta.resolve(fileName));
		_autoloadCSSCore.insertCSSLinkToPage(fileNames, true);
	
import { defineComponent as E, ref as k, reactive as j, computed as w, watch as D, resolveComponent as b, createBlock as S, openBlock as i, unref as f, withCtx as c, createVNode as d, createTextVNode as C, toDisplayString as p, createElementVNode as m, createElementBlock as _, Fragment as M, renderList as O, createCommentVNode as y } from "vue";
import { _ as P, a as G } from "./page.vue_vue_type_script_setup_true_lang-BMTt9SU8.es.js";
import { b as X } from "./utils-BYaZxGC1.es.js";
import { genFlagLinkByCountryCode as Q } from "../utils/string.js";
import { getSearcherGIcon as q, getLangLabel as z, getDeviceGIcon as H } from "../utils/searchers.js";
import { C as I } from "./forms-BAUgA7Ct.es.js";
const J = { class: "dialog_regionSelectorRegions_header" }, K = ["data-top-icon"], W = ["src", "alt"], Y = { class: "top-ellipsis" }, Z = { class: "dialog_regionSelectorRegions_regionAreaName" }, F = { key: 1 }, ee = ["data-top-icon"], re = /* @__PURE__ */ E({
  id: "regionSelectorRegions",
  __name: "dialog_regionSelectorRegions",
  props: {
    regions: {},
    regionsIndexes: {},
    "@update:regionsIndexes": { type: Function }
  },
  setup(R) {
    const l = R, h = X(), a = k([]), r = k(null), g = j({
      searcher_key: -1,
      key: -1,
      name: -1
    }), x = w({
      get() {
        return a.value.every((o) => o.selected);
      },
      set(o) {
        a.value = a.value.map((e) => ({ ...e, selected: o }));
      }
    }), v = (o) => {
      g[o] = -g[o], a.value.sort((e, t) => !e[o] || !t[o] ? -1 : e[o] >= t[o] ? g[o] : -g[o]);
    }, V = () => {
      if (!a.value.some((e) => e.selected)) return;
      const o = a.value.filter((e) => e.selected).map((e) => e.index);
      l["@update:regionsIndexes"]?.(o), h.close();
    };
    D([
      () => l.regions,
      () => l.regionsIndexes
    ], () => {
      if (a.value = [], !l.regions || !l.regionsIndexes) return;
      let o = [...l.regions];
      const e = new Map(l.regionsIndexes.map((t, s) => [t, s]));
      o.sort((t, s) => {
        const n = e.get(t.index) ?? Number.MAX_VALUE, u = e.get(s.index) ?? Number.MAX_VALUE;
        return n - u;
      }), o.forEach((t) => {
        let s = t.name;
        t.areaName && (s += ` (${t.areaName})`);
        const n = l.regionsIndexes?.includes(t.index) ?? !1, u = q(t.searcher_key), N = t.lang !== void 0 ? z(t.searcher_key ?? 999, t.lang) : void 0, A = t.device !== void 0 ? H(t.device) : void 0, T = t.countryCode !== void 0 ? Q(t.countryCode) : void 0, U = {
          ...t,
          selected: n,
          title: s,
          searcherIcon: u,
          langLabel: N,
          deviceIcon: A,
          flagLink: T
        };
        a.value.push(U);
      });
    });
    const L = () => {
      if (!I.$?.ui.sortable) {
        console.info("Для работы сортировки требуется глобальная загрузка jQuery UI Sortable");
        return;
      }
      r.value && $(r.value).sortable({
        distance: 10,
        stop: () => {
          const o = [...r.value.children].map((e) => Number(e.getAttribute("data-region-index")));
          a.value.sort((e, t) => o.indexOf(e.index) - o.indexOf(t.index));
        }
      });
    }, B = () => {
      I.$?.ui.sortable && r.value && $(r.value).sortable("destroy");
    };
    return (o, e) => {
      const t = b("TopCheckbox"), s = b("TopButton");
      return i(), S(f(P), {
        id: f(h).id,
        pageActive: "regions",
        class: "dialog_regionSelectorRegions",
        height: "600px",
        width: "600px",
        onOpen: L,
        onClose: B
      }, {
        default: c(() => [
          d(f(G), {
            name: "regions",
            order: 0
          }, {
            header: c(() => [
              m("div", J, [
                d(t, {
                  modelValue: x.value,
                  "onUpdate:modelValue": e[0] || (e[0] = (n) => x.value = n)
                }, null, 8, ["modelValue"]),
                d(s, {
                  class: "dialog_regionSelectorRegions_sortButton",
                  color: "theme",
                  "data-top-icon": "",
                  onClick: e[1] || (e[1] = (n) => v("searcher_key")),
                  title: o.$i18n.Projects?.Sort_by_search_engine
                }, null, 8, ["title"]),
                d(s, {
                  class: "dialog_regionSelectorRegions_sortButton",
                  color: "theme",
                  "data-top-icon": "",
                  onClick: e[2] || (e[2] = (n) => v("key")),
                  title: o.$i18n.Projects?.Sort_by_yande_region_code
                }, null, 8, ["title"]),
                d(s, {
                  class: "dialog_regionSelectorRegions_sortButton",
                  color: "theme",
                  "data-top-icon": "",
                  onClick: e[3] || (e[3] = (n) => v("name")),
                  title: o.$i18n.Projects?.Sort_by_lphabetically
                }, null, 8, ["title"])
              ])
            ]),
            body: c(() => [
              m("div", {
                ref_key: "elRegions",
                ref: r
              }, [
                (i(!0), _(M, null, O(a.value, (n) => (i(), S(t, {
                  key: n.index,
                  modelValue: n.selected,
                  "onUpdate:modelValue": (u) => n.selected = u,
                  class: "dialog_regionSelectorRegions_region",
                  "data-region-index": n.index
                }, {
                  default: c(() => [
                    m("div", {
                      class: "dialog_regionSelectorRegions_regionSearcherIcon",
                      "data-top-icon": n.searcherIcon
                    }, null, 8, K),
                    n.flagLink ? (i(), _("img", {
                      key: 0,
                      class: "top-flag",
                      src: "//topvisor.dev" + n.flagLink,
                      alt: n.countryCode
                    }, null, 8, W)) : y("", !0),
                    m("div", Y, [
                      C(p(n.name) + " ", 1),
                      m("span", Z, p(n.areaName), 1)
                    ]),
                    n.langLabel ? (i(), _("div", F, " [" + p(n.langLabel) + "] ", 1)) : y("", !0),
                    n.deviceIcon ? (i(), _("div", {
                      key: 2,
                      "data-top-icon": n.deviceIcon
                    }, null, 8, ee)) : y("", !0)
                  ]),
                  _: 2
                }, 1032, ["modelValue", "onUpdate:modelValue", "data-region-index"]))), 128))
              ], 512)
            ]),
            footer: c(() => [
              d(s, { onClick: V }, {
                default: c(() => [
                  C(p(o.$i18n.Common?.Apply), 1)
                ]),
                _: 1
              })
            ]),
            _: 1
          })
        ]),
        _: 1
      }, 8, ["id"]);
    };
  }
});
export {
  re as default
};
//# sourceMappingURL=dialog_regionSelectorRegions-Btp9cfmF.es.js.map
