import{_ as f,s as d,f as _}from"./app.js";import{P as i}from"./PostShortcut.js";import{L as g}from"./LoadMoreButton.js";import"./swiper.js";const w={name:"SoylentPostShortcutList",components:{LoadMoreButton:g,PostShortcut:i},data:function(){return{pageItems:[],page:1,archiveUrl:null,loading:!1}},props:["element"],computed:{postShortcutComponent(){return d.getByName("postShortcut",i)},amount:function(){return this.element.data.amount?this.element.data.amount:10},postShortcut:function(){return d.getByName("postShortcut",i)},total:function(){return this.element.data.total?this.element.data.total:0}},watch:{element(){this.setDataSettings()}},methods:{handleResponse:function(t){let e=!1;if(t.data.template==="not-found"){this.archiveUrl=null;return}t.data.data.blocks.forEach(n=>{n.elements.forEach(a=>{a.subtype==="postShortcutList"&&a.data.items.forEach(r=>{e=!0,this.pageItems.push(r)})})}),(!e||this.pageItems.length>=this.total)&&(this.archiveUrl=null)},loadMore:function(){this.loading=!0,this.page++;const t=this.archiveUrl+"page/"+this.page+"/";_.get("/headless"+t).then(e=>this.handleResponse(e)).catch(e=>{if(!e.response){console.debug(e);return}this.archiveUrl=null}).finally(()=>{this.loading=!1})},setDataSettings:function(){this.pageItems=this.element.data.items,this.page=this.element.data.page,this.pageItems.length!==this.total&&(this.archiveUrl=this.element.data.archive_url)}},mounted(){this.setDataSettings()}},v=window.Vue.renderList,y=window.Vue.Fragment,o=window.Vue.openBlock,l=window.Vue.createElementBlock,S=window.Vue.resolveDynamicComponent,h=window.Vue.createBlock,s=window.Vue.createElementVNode,V=window.Vue.resolveComponent,m=window.Vue.createCommentVNode,k=window.Vue.normalizeClass,C={class:"post-shortcuts -col-4"},B={key:1,class:"loading-state"},L=s("div",{class:"button"},[s("span",{class:"button__label"},[s("span",{class:"button__text"},"WIRD GELADEN")])],-1),E=[L];function b(t,e,n,a,r,c){const p=V("LoadMoreButton");return o(),l("div",{class:k(["element",n.element.type,n.element.subtype])},[s("div",C,[(o(!0),l(y,null,v(t.pageItems,u=>(o(),h(S(c.postShortcut),{post:u,key:u.post_id},null,8,["post"]))),128))]),!t.loading&&t.archiveUrl?(o(),h(p,{key:0,onClick:c.loadMore},null,8,["onClick"])):m("",!0),t.loading?(o(),l("div",B,E)):m("",!0)],2)}const M=f(w,[["render",b]]);export{M as default};