define(["require","exports","vue","./page.vue_vue_type_script_setup_true_lang-fl6-Ql4d.amd","./utils-CWn_G7OO.amd","../utils/string.amd","../utils/searchers.amd","./forms-DDNzqU6o.amd","../require/css.amd!../assets/dialog_regionSelectorRegions.css"],(function(U,m,e,p,y,k,u,v){"use strict";if(typeof e>"u")var e=window.Vue;const x={class:"dialog_regionSelectorRegions_header"},h=["data-top-icon"],C=["src","alt"],V={class:"top-ellipsis"},S={class:"dialog_regionSelectorRegions_regionAreaName"},b={key:1},N=["data-top-icon"],B=e.defineComponent({id:"regionSelectorRegions",__name:"dialog_regionSelectorRegions",props:{regions:{},regionsIndexes:{},"@update:regionsIndexes":{type:Function}},setup(I){const i=I,_=y.useTopDialogSelf(),r=e.ref([]),s=e.ref(null),d=e.reactive({searcher_key:-1,key:-1,name:-1}),f=e.computed({get(){return r.value.every(t=>t.selected)},set(t){r.value=r.value.map(o=>({...o,selected:t}))}}),g=t=>{d[t]=-d[t],r.value.sort((o,n)=>!o[t]||!n[t]?-1:o[t]>=n[t]?d[t]:-d[t])},R=()=>{if(!r.value.some(o=>o.selected))return;const t=r.value.filter(o=>o.selected).map(o=>o.index);i["@update:regionsIndexes"]?.(t),_.close()};e.watch([()=>i.regions,()=>i.regionsIndexes],()=>{if(r.value=[],!i.regions||!i.regionsIndexes)return;let t=[...i.regions];const o=new Map(i.regionsIndexes.map((n,a)=>[n,a]));t.sort((n,a)=>{const l=o.get(n.index)??Number.MAX_VALUE,c=o.get(a.index)??Number.MAX_VALUE;return l-c}),t.forEach(n=>{let a=n.name;n.areaName&&(a+=` (${n.areaName})`);const l=i.regionsIndexes?.includes(n.index)??!1,c=u.getSearcherGIcon(n.searcher_key),w=n.lang!==void 0?u.getLangLabel(n.searcher_key??999,n.lang):void 0,A=n.device!==void 0?u.getDeviceGIcon(n.device):void 0,T=n.countryCode!==void 0?k.genFlagLinkByCountryCode(n.countryCode):void 0,D={...n,selected:l,title:a,searcherIcon:c,langLabel:w,deviceIcon:A,flagLink:T};r.value.push(D)})});const E=()=>{if(!v.Core.$?.ui.sortable){console.info("Для работы сортировки требуется глобальная загрузка jQuery UI Sortable");return}s.value&&$(s.value).sortable({distance:10,stop:()=>{const t=[...s.value.children].map(o=>Number(o.getAttribute("data-region-index")));r.value.sort((o,n)=>t.indexOf(o.index)-t.indexOf(n.index))}})},L=()=>{v.Core.$?.ui.sortable&&s.value&&$(s.value).sortable("destroy")};return(t,o)=>{const n=e.resolveComponent("TopCheckbox"),a=e.resolveComponent("TopButton");return e.openBlock(),e.createBlock(e.unref(p._sfc_main),{id:e.unref(_).id,pageActive:"regions",class:"dialog_regionSelectorRegions",height:"600px",width:"600px",onOpen:E,onClose:L},{default:e.withCtx(()=>[e.createVNode(e.unref(p._sfc_main$1),{name:"regions",order:0},{header:e.withCtx(()=>[e.createElementVNode("div",x,[e.createVNode(n,{modelValue:f.value,"onUpdate:modelValue":o[0]||(o[0]=l=>f.value=l)},null,8,["modelValue"]),e.createVNode(a,{class:"dialog_regionSelectorRegions_sortButton",color:"theme","data-top-icon":"",onClick:o[1]||(o[1]=l=>g("searcher_key")),title:t.$i18n.Projects?.Sort_by_search_engine},null,8,["title"]),e.createVNode(a,{class:"dialog_regionSelectorRegions_sortButton",color:"theme","data-top-icon":"",onClick:o[2]||(o[2]=l=>g("key")),title:t.$i18n.Projects?.Sort_by_yande_region_code},null,8,["title"]),e.createVNode(a,{class:"dialog_regionSelectorRegions_sortButton",color:"theme","data-top-icon":"",onClick:o[3]||(o[3]=l=>g("name")),title:t.$i18n.Projects?.Sort_by_lphabetically},null,8,["title"])])]),body:e.withCtx(()=>[e.createElementVNode("div",{ref_key:"elRegions",ref:s},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.value,l=>(e.openBlock(),e.createBlock(n,{key:l.index,modelValue:l.selected,"onUpdate:modelValue":c=>l.selected=c,class:"dialog_regionSelectorRegions_region","data-region-index":l.index},{default:e.withCtx(()=>[e.createElementVNode("div",{class:"dialog_regionSelectorRegions_regionSearcherIcon","data-top-icon":l.searcherIcon},null,8,h),l.flagLink?(e.openBlock(),e.createElementBlock("img",{key:0,class:"top-flag",src:"//topvisor.dev"+l.flagLink,alt:l.countryCode},null,8,C)):e.createCommentVNode("",!0),e.createElementVNode("div",V,[e.createTextVNode(e.toDisplayString(l.name)+" ",1),e.createElementVNode("span",S,e.toDisplayString(l.areaName),1)]),l.langLabel?(e.openBlock(),e.createElementBlock("div",b," ["+e.toDisplayString(l.langLabel)+"] ",1)):e.createCommentVNode("",!0),l.deviceIcon?(e.openBlock(),e.createElementBlock("div",{key:2,"data-top-icon":l.deviceIcon},null,8,N)):e.createCommentVNode("",!0)]),_:2},1032,["modelValue","onUpdate:modelValue","data-region-index"]))),128))],512)]),footer:e.withCtx(()=>[e.createVNode(a,{onClick:R},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(t.$i18n.Common?.Apply),1)]),_:1})]),_:1})]),_:1},8,["id"])}}});m.default=B,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
//# sourceMappingURL=dialog_regionSelectorRegions-CZ0tMVSq.amd.js.map
