| 1 |
import{h,O as ve,i as pe,r as x,e as p,o as u,a as S,w as P,u as b,d as s,b as ee,F as I,g as B,c as $,f as te,t as k,n as R,a2 as _e}from"./chunks/vue.esm-bundler.js?ver=1.3.21";import{u as me}from"./chunks/useElementPlusComponents.js?ver=1.3.21";import{_ as fe}from"./chunks/AddProductItemModal.js?ver=1.3.21";import{t as g}from"./chunks/Translator.js?ver=1.3.21";import{u as he}from"./chunks/useElementor.js?ver=1.3.21";import{R as ae}from"./chunks/Rest.js?ver=1.3.21";import{A as ge}from"./chunks/Arr.js?ver=1.3.21";import{S as be}from"./chunks/ServerSidePreview.js?ver=1.3.21";import{n as ye}from"./chunks/Notify.js?ver=1.3.21";import Ve from"./chunks/CaretRight.js?ver=1.3.21";import Ce from"./chunks/Delete.js?ver=1.3.21";import"./chunks/index.js?ver=1.3.21";import"./chunks/index2.js?ver=1.3.21";import"./chunks/index4.js?ver=1.3.21";import"./chunks/dayjs.min.js?ver=1.3.21";import"./chunks/index3.js?ver=1.3.21";import"./chunks/DynamicIcon.js?ver=1.3.21";import"./chunks/Str.js?ver=1.3.21";import"./chunks/productService.js?ver=1.3.21";import"./chunks/Model.js?ver=1.3.21";import"./chunks/Asset.js?ver=1.3.21";import"./chunks/Url.js?ver=1.3.21";import"./chunks/vue-router.js?ver=1.3.21";import"./chunks/ServerSidePreview.vue_vue_type_style_index_0_scoped_e73ce754_lang.js?ver=1.3.21";import"./chunks/_plugin-vue_export-helper.js?ver=1.3.21";import"./chunks/add-query-args.js?ver=1.3.21";const Se={key:0},ke={key:1,class:"fluent-cart-pricing-table-block-editor"},we={class:"fluent-cart-pricing-table-block-editor-head"},Ae={class:"fluent-cart-pricing-table-block-editor-body"},Oe={key:0,class:"fct-custom-tabs"},je={key:0,class:"fct-tab-header"},Ee={class:"fct-tab-content"},xe={key:0,class:"fct-tab-content-inner"},De={class:"fct-active-product-select-container"},Te={class:"fct-form-group"},Ie={class:"fct-selected-products-container"},Ne=["onClick"],Fe={class:"icon"},Pe={class:"fct-selected-product-contents"},Be=["title"],$e={class:"product-id"},Re={class:"product-textarea-inner"},Ue=["placeholder","value","onBlur"],Me={class:"hint-text"},Qe=["onClick","title"],He={key:1},Je={__name:"App",props:{settings:{type:String,default:""}},setup(y){let v=null;const w=y,d=h(w.settings),D=h({}),U=h([]),r=h([]),i=h(0),A=h({}),j=h({}),o=h([]),M=h([]),T=h("editor"),Q=(e,t)=>{J(e),d.value.variations=e;let a={};t.forEach(l=>{l.variants.forEach(_=>{e.includes(_.id)&&(a[_.id]={other_info:_.other_info,variation_title:_.variation_title,id:_.id})})}),D.value={...a},U.value=Object.keys(a),H(a)},ne=e=>{const t={};Object.keys(j.value).forEach(a=>{t[a]=!1}),t[e]=!j.value[e],j.value=t},oe=(e,t)=>{ae.put("/products/variants/"+e+"/pricing-table",{description:t.other_info.description}).then(a=>{}).catch(a=>{console.error("Error updating variation data:",a),ye.error(g("Failed to update variation data"))})},ie=e=>{let t={...D.value};e in t&&delete t[e],D.value={...t},U.value=Object.keys(t),Array.isArray(o.value)?o.value=o.value.filter(l=>l.toString()!==e.toString()):typeof o.value=="string"&&(o.value=o.value.split(",").filter(l=>l!==e));let a=[];typeof o.value=="string"?a=o.value.split(",").map(Number):Array.isArray(o.value)&&(a=o.value.map(l=>parseInt(l,10))),J(o.value),d.value.variations=a,H(D.value)},H=(e,t="repeat_interval")=>{let a="repeat_interval";t==="payment_type"?a="payment_type":t==="none"&&(a="onetime");const l={};Object.entries(e).forEach(([V,m])=>{var C;let f=((C=m.other_info)==null?void 0:C[a])||"onetime";m.other_info&&m.other_info.installment==="yes"&&(f="installment"),l[f]||(l[f]={}),l[f][V]={id:V,other_info:m.other_info,variation_title:m.variation_title}});const _=Object.keys(l).map(V=>({title:V,content:Object.entries(l[V]).reduce((m,[f,C])=>(m[f]={id:f,...C},m),{})}));r.value=_,_.length&&(i.value=0)},J=e=>{typeof e=="string"?o.value=e.split(",").map(t=>parseInt(t,10)):Array.isArray(e)&&(o.value=e.map(t=>parseInt(t,10))),setTimeout(()=>{v.setSettings("variant_ids",o.value)},100)},le=(e=[])=>{let a={active_view:"publish",per_page:10,page:1,filter_type:"advanced",sort_by:"ID",with:["detail.variants.media","categories","variants.media"],advanced_filters:JSON.stringify([[{source:["variations","variation_items"],filter_type:"relation",operator:"contains",value:e,column:"id",relation:"variants"}]])};ae.get("products",a).then(l=>{M.value=ge.get(l,"products.data",[]),Q(e,M.value)}).catch(l=>{console.log(l)}).finally(()=>{})},se=e=>{d.value.active_variant=e,setTimeout(()=>{v.setSettings("active_variant",e)},100)},re=()=>{d.value.active_tab!==""&&(i.value=d.value.active_tab),d.value.variations&&(o.value=d.value.variations),d.value.active_variant&&(A.value=d.value.active_variant),d.value.editor_active_tab&&(T.value=d.value.editor_active_tab),ce()},ce=()=>{setTimeout(()=>{if(o.value.length!==""){let e=[];typeof o.value=="string"?e=o.value.split(",").map(t=>parseInt(t,10)):Array.isArray(o.value)&&(e=o.value.map(t=>parseInt(t,10))),le(e)}},100)},ue=e=>{i.value=e,setTimeout(()=>{v.setSettings("active_tab",i.value)},100)},de=e=>{setTimeout(()=>{v.setSettings("editor_active_tab",e)},100)};return ve(()=>{v=he()}),pe(()=>{d.value=JSON.parse(w.settings),re()}),(e,t)=>{var f,C,q,z;const a=x("el-tab-pane"),l=x("el-tabs"),_=x("el-button"),V=x("el-option"),m=x("el-select");return u(),p(I,null,[S(l,{modelValue:T.value,"onUpdate:modelValue":t[0]||(t[0]=n=>T.value=n),class:"demo-tabs",onTabChange:de},{default:P(()=>[S(a,{label:b(g)("Editor"),name:"editor"},null,8,["label"]),S(a,{label:b(g)("Preview"),name:"preview"},null,8,["label"])]),_:1},8,["modelValue"]),T.value==="preview"?(u(),p("div",Se,[S(be,{block:"fluent-cart/product-pricing-table",attributes:d.value},null,8,["attributes"])])):(u(),p("div",ke,[s("div",we,[S(fe,{isMultiple:!0,selectedIds:o.value,onOnVariationSelectionUpdated:Q},null,8,["selectedIds"])]),s("div",Ae,[r.value.length>0&&Object.keys(((f=r.value[i.value])==null?void 0:f.content)||{}).length>0?(u(),p("div",Oe,[r.value.length>1?(u(),p("div",je,[(u(!0),p(I,null,B(r.value,(n,c)=>(u(),$(_,{key:c,class:R({"is-primary":i.value==c," components-button":!0}),onClick:O=>ue(c)},{default:P(()=>[te(k(n.title),1)]),_:2},1032,["class","onClick"]))),128))])):ee("",!0),s("div",Ee,[r.value[i.value]?(u(),p("div",xe,[s("div",De,[s("div",Te,[s("label",null,k(b(g)("Recommended variant")),1),(u(),$(m,{key:((C=r.value[i.value])==null?void 0:C.title)||"",modelValue:A.value[((q=r.value[i.value])==null?void 0:q.title)||""],"onUpdate:modelValue":t[1]||(t[1]=n=>{var c;return A.value[((c=r.value[i.value])==null?void 0:c.title)||""]=n}),onChange:t[2]||(t[2]=n=>{var c;A.value={...A.value,[((c=r.value[i.value])==null?void 0:c.title)||""]:n},se(A.value)})},{default:P(()=>{var n;return[(u(!0),p(I,null,B(Object.keys(((n=r.value[i.value])==null?void 0:n.content)||{}),c=>{var O,E;return u(),$(V,{key:c,value:c,label:((E=(O=r.value[i.value])==null?void 0:O.content[c])==null?void 0:E.variation_title)||c},null,8,["value","label"])}),128))]}),_:1},8,["modelValue"]))])]),s("div",Ie,[(u(!0),p(I,null,B(Object.keys(((z=r.value[i.value])==null?void 0:z.content)||{}),n=>{var c,O,E,G,L,W,X,Y,Z;return u(),p("div",{key:`variations-${(O=(c=r.value[i.value])==null?void 0:c.content[n])==null?void 0:O.id}`,class:"fct-selected-product"},[s("div",{class:R(["fct-selected-product-toggle",{"is-expanded":j.value[n]}]),onClick:N=>ne(n)},[s("div",Fe,[S(Ve,{class:"w-3 h-3"})])],10,Ne),s("div",Pe,[s("div",{class:"product-title",title:(G=(E=r.value[i.value])==null?void 0:E.content[n])==null?void 0:G.variation_title},k((W=(L=r.value[i.value])==null?void 0:L.content[n])==null?void 0:W.variation_title),9,Be),s("div",$e,"#"+k(n),1),s("div",{class:R(["product-textarea",{"is-expanded":j.value[n]}])},[s("div",Re,[s("textarea",{placeholder:b(g)("Variants features..."),value:((Z=(Y=(X=r.value[i.value])==null?void 0:X.content[n])==null?void 0:Y.other_info)==null?void 0:Z.description)||"",onBlur:N=>{var K;const F=(K=r.value[i.value])==null?void 0:K.content[n];F&&(F.other_info.description=N.target.value.replace(/\r?\n/g,` |