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