import{h as k,v as B,K as S,i as N,r as b,e as d,o as n,d as h,a as g,t as c,w as u,f as v,b as f,n as x,c as V,p as E,F as C,g as w}from"./vue.esm-bundler.js?ver=1.5.4";import{_ as U}from"./DynamicIcon.js?ver=1.5.4";import{o as A}from"./vue-router.js?ver=1.5.4";import{t as y}from"./Translator.js?ver=1.5.4";import{U as T}from"./Utils.js?ver=1.5.4";import{_ as P}from"./_plugin-vue_export-helper.js?ver=1.5.4";const F={class:"fct-save-bar-inner"},L={class:"fct-save-bar-left"},j={class:"title"},D={class:"fct-save-bar-right"},M={class:"fct-btn-group"},q={key:0,class:"cmd"},Z={__name:"SaveBar",props:{isActive:String,saveButtonText:{type:String,default:y("Save")},discardButtonText:{type:String,default:y("Discard")},loading:{type:Boolean,default:!1},showCmndIcon:{type:Boolean,default:!1},unSaveChangesText:{type:String,default:y("Unsaved Changes")}},emits:["discard","save"],setup(e,{emit:l}){const o=e,a=k(!1),t=k("");B(()=>o.isActive,(r,I)=>{t.value=r});const s=l,p=()=>{t.value="",s("discard")},_=()=>{t.value="",s("save")},i=r=>{t.value&&t.value!==""?(r.preventDefault(),a.value=!0,setTimeout(()=>{a.value=!1},2e3),r.returnValue=""):a.value=!1};return A((r,I,m)=>{t.value&&t.value!==""?(a.value=!0,setTimeout(()=>{a.value=!1},1e3),m(!1)):(m(),a.value=!1)}),S(()=>{window.removeEventListener("beforeunload",i)}),N(()=>{window.addEventListener("beforeunload",i)}),(r,I)=>{const m=b("el-button");return n(),d("div",{class:x(`fct-save-bar ${e.isActive??""} ${a.value?"shake-unsave-changes":""}`)},[h("div",F,[h("div",L,[g(U,{name:"AlertIcon"}),h("h4",j,c(e.unSaveChangesText),1)]),h("div",D,[h("div",M,[g(m,{onClick:p,type:"info",soft:""},{default:u(()=>[v(c(e.discardButtonText),1)]),_:1}),g(m,{type:"primary",onClick:_,loading:e.loading},{default:u(()=>[e.showCmndIcon?(n(),d("span",q,"⌘s")):f("",!0),v(" "+c(e.saveButtonText),1)]),_:1},8,["loading"])])])])],2)}}},z={name:"ProductVariationSelector",props:{modelValue:{type:[Array,String,Number],default:()=>[]},is_multiple:{type:Boolean,default:!0},popoverClass:{type:String,default:""},scopes:{type:Array,default:()=>[]}},emits:["update:modelValue","visible-change"],data(){return{products:[],selectedVariationIds:this.modelValue,loading:!1}},computed:{Utils(){return T},selectedFormattedItems(){let e=this.selectedVariationIds;if(this.is_multiple||(e=[],this.selectedVariationIds&&e.push(this.selectedVariationIds)),!e||!(e!=null&&e.length))return null;let l={},o={};this.products.forEach(t=>{l[t.label]=t.children,t.children.forEach(s=>{o[s.value]={productName:t.label,variationName:s.label}})});let a={};return e.forEach(t=>{if(o[t]){let s=o[t];a[s.productName]||(a[s.productName]=[]),a[s.productName].push(s.variationName)}else a.Unknown||(a.Unknown=[]),a.Unknown.push(t)}),Object.keys(a).forEach(t=>{var s;a[t].length===((s=l[t])==null?void 0:s.length)&&(a[t]=[])}),a}},watch:{selectedVariationIds(e){this.$emit("update:modelValue",e)},modelValue(e){this.selectedVariationIds=e}},mounted(){this.is_multiple?Array.isArray(this.selectedVariationIds)||(this.selectedVariationIds=[]):this.selectedVariationIds=this.selectedVariationIds?parseInt(this.selectedVariationIds):null,this.searchProducts()},methods:{onVisibleChange(e){this.$emit("visible-change",e)},searchProducts(e=""){this.loading=!0;const l={search:e,include_ids:this.is_multiple?this.selectedVariationIds:[this.selectedVariationIds]};this.scopes.length&&(l.scopes=this.scopes),this.$get("products/search-product-variant-options",l).then(o=>{this.products=o.products}).catch(o=>{}).finally(()=>{this.loading=!1})},filterNodeMethod(e,l){return l}}},K={key:0,class:"flex items-center flex-wrap gap-1.5"},O={key:0},R={key:0,class:"flex items-center flex-wrap gap-1.5"},$={key:0};function G(e,l,o,a,t,s){const p=b("el-tag"),_=b("el-tree-select");return n(),V(_,{modelValue:t.selectedVariationIds,"onUpdate:modelValue":l[0]||(l[0]=i=>t.selectedVariationIds=i),data:t.products,"filter-method":s.Utils.debounce(s.searchProducts),"filter-node-method":s.filterNodeMethod,filterable:"","show-checkbox":"",multiple:o.is_multiple,clearable:"",placeholder:e.$t("Select product"),onVisibleChange:l[1]||(l[1]=i=>{s.onVisibleChange(i)}),"popper-class":o.popoverClass,class:x(t.loading?"is-custom-loading":"")},E({_:2},[o.is_multiple?{name:"tag",fn:u(()=>[s.selectedFormattedItems?(n(),d("div",R,[(n(!0),d(C,null,w(s.selectedFormattedItems,(i,r)=>(n(),V(p,{class:"mr-2"},{default:u(()=>[v(c(r)+" ",1),i.length?(n(),d("span",$," | "+c(i.join(", ")),1)):f("",!0)]),_:2},1024))),256))])):f("",!0)]),key:"1"}:{name:"label",fn:u(()=>[s.selectedFormattedItems?(n(),d("div",K,[(n(!0),d(C,null,w(s.selectedFormattedItems,(i,r)=>(n(),V(p,{class:"mr-2"},{default:u(()=>[v(c(r)+" ",1),i.length?(n(),d("span",O," | "+c(i.join(", ")),1)):f("",!0)]),_:2},1024))),256))])):f("",!0)]),key:"0"}]),1032,["modelValue","data","filter-method","filter-node-method","multiple","placeholder","popper-class","class"])}const ee=P(z,[["render",G]]);export{ee as P,Z as _};
