import j from"./DQQturlO.js";import E from"./CWalxxGV.js";import{u as F}from"./Bxmfm8sn.js";import K from"./CXhFgGTt.js";import{K as L,i as l,j as u,w as O,m as I,A as N,l as R,T as U,P as Y,u as q,s as z,b as H}from"./BCLrUOBx.js";import"./CcKtUwWJ.js";import"./Dyp1qGEf.js";import"./CTAcmMAz.js";import"./B2sEaWda.js";import"./a5umXhxZ.js";import"./BnLnKt_p.js";import"./Di7fl9dA.js";import"./Ce8lFovl.js";import"./CE4It_C4.js";import"./-hq_PDZF.js";const J={setup(){const s=q(),{langCode:t}=z(s),n=H(),{unAuthGet:a}=n;return{unAuthGet:a,langCode:t}},name:"SuggestedProducts",data(){return{fetchingSuggested:!0,suggestedData:null,lastPage:1,currentPage:1,totalSuggested1:0,totalSuggested2:0,perPageSuggested1:0,perPageSuggested2:0,suggested1:[],suggested2:[],loaded:[]}},watch:{},props:{productId:{type:String,default:""}},components:{ProductsDynamic:j,Spinner:E,ProductsSlider:K},computed:{},mixins:[F],methods:{async fetchSuggested(s,t=0){var a,e,i,o,r,g,h,p,m,f,_,P,S,D,w,k,x,y,C,b;t===1?this.suggested1=this.suggested1.concat(["","","","",""]):t===2?this.suggested2=this.suggested2.concat(["","","","",""]):(this.suggested1=this.suggested1.concat(["","","","",""]),this.suggested2=this.suggested2.concat(["","","","",""])),this.loaded.push(s);const n=await this.unAuthGet({api:"suggested_products",params:`/${this.productId}?${Y({page:s})}`,lang:this.langCode});if(this.fetchingSuggested=!1,this.suggestedData=n.data,t===1?this.suggested1.splice(this.suggested1.length-5,5):t===2?this.suggested2.splice(this.suggested2.length-5,5):(this.suggested1.splice(this.suggested1.length-5,5),this.suggested2.splice(this.suggested2.length-5,5)),(e=(a=this.suggestedData)==null?void 0:a.suggestion_1)!=null&&e.data&&(this.suggested1=this.suggested1.concat((o=(i=this.suggestedData)==null?void 0:i.suggestion_1)==null?void 0:o.data)),(g=(r=this.suggestedData)==null?void 0:r.suggestion_2)!=null&&g.data&&(this.suggested2=this.suggested2.concat((p=(h=this.suggestedData)==null?void 0:h.suggestion_2)==null?void 0:p.data)),s===1){const A=(f=(m=this.suggestedData)==null?void 0:m.suggestion_1)==null?void 0:f.total,d=(P=(_=this.suggestedData)==null?void 0:_.suggestion_1)==null?void 0:P.per_page,B=(D=(S=this.suggestedData)==null?void 0:S.suggestion_1)==null?void 0:D.last_page;A<d?this.totalSuggested1=B*d:this.totalSuggested1=A;const G=(k=(w=this.suggestedData)==null?void 0:w.suggestion_2)==null?void 0:k.total,c=(y=(x=this.suggestedData)==null?void 0:x.suggestion_2)==null?void 0:y.per_page,T=(b=(C=this.suggestedData)==null?void 0:C.suggestion_2)==null?void 0:b.last_page;G<c?this.totalSuggested2=T*c:this.totalSuggested2=G,this.perPageSuggested1=d,this.perPageSuggested2=c;const V=B??0,v=T??0;v>V?this.lastPage=v:this.lastPage=V}},async change(s,t){this.currentPage+=t,this.currentPage<1?this.currentPage=this.lastPage:this.currentPage>this.lastPage&&(this.currentPage=1),this.loaded.indexOf(this.currentPage)===-1&&await this.fetchSuggested(this.currentPage,s)}},created(){},async mounted(){await this.fetchSuggested(this.currentPage)}},M={key:0},Q={key:1,class:"spinner-wrapper flex"};function W(s,t,n,a,e,i){const o=j,r=E;return u(),l(U,{name:"fade",mode:"out-in"},{default:O(()=>[e.fetchingSuggested?(u(),I("div",Q,[R(r,{radius:100})])):(u(),I("div",M,[e.suggested1.length?(u(),l(o,{key:0,title:s.$t("suggestedProducts.recommendedForYou"),"item-list":e.suggested1,"per-page":e.perPageSuggested1,"total-item":e.totalSuggested1,onChange:t[0]||(t[0]=g=>i.change(1,g)),class:"b-t pt-20 pt-sm-15 npb-5"},null,8,["title","item-list","per-page","total-item"])):N("",!0),e.suggested2.length?(u(),l(o,{key:1,title:s.$t("suggestedProducts.alsoViewed"),"item-list":e.suggested2,"total-item":e.totalSuggested2,"per-page":e.perPageSuggested2,onChange:t[1]||(t[1]=g=>i.change(2,g)),class:"b-t pt-20 pt-sm-15 pb-15 pb-sm-5"},null,8,["title","item-list","total-item","per-page"])):N("",!0)]))]),_:1})}const lt=L(J,[["render",W]]);export{lt as default};
