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