import{r as t,h as s,a}from"./p-9add63ef.js";import"./p-445fd8b4.js";import{o as i}from"./p-b719a497.js";import{a as e}from"./p-401e165e.js";import{a as o}from"./p-259c3935.js";import"./p-d3366af3.js";const n=":host{display:block}.download__details{opacity:0.75}";const d=n;const h=class{constructor(s){t(this,s);this.query={page:1,per_page:10};this.allLink=undefined;this.heading=undefined;this.isCustomer=undefined;this.requestNonce=undefined;this.purchases=[];this.loading=undefined;this.busy=undefined;this.error=undefined;this.pagination={total:0,total_pages:0}}componentWillLoad(){i(this.el,(()=>{this.initialFetch()}))}async initialFetch(){if(!this.isCustomer){return}try{this.loading=true;await this.getItems()}catch(t){console.error(this.error);this.error=(t===null||t===void 0?void 0:t.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.loading=false}}async fetchItems(){if(!this.isCustomer){return}try{this.busy=true;await this.getItems()}catch(t){console.error(this.error);this.error=(t===null||t===void 0?void 0:t.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.busy=false}}async getItems(){const t=await await o({path:e(`surecart/v1/purchases/`,{expand:["product","product.downloads","download.media","variant","variant.downloads"],downloadable:true,revoked:false,...this.query}),parse:false});this.pagination={total:parseInt(t.headers.get("X-WP-Total")),total_pages:parseInt(t.headers.get("X-WP-TotalPages"))};this.purchases=await t.json();return this.purchases}nextPage(){this.query.page=this.query.page+1;this.fetchItems()}prevPage(){this.query.page=this.query.page-1;this.fetchItems()}render(){var t;return s("sc-purchase-downloads-list",{key:"0dadadb9a7a46a14b4023e73d0b948488f368109",heading:this.heading,allLink:this.allLink&&this.pagination.total_pages>1?this.allLink:"",loading:this.loading,busy:this.busy,requestNonce:this.requestNonce,error:this.error,purchases:this.purchases},s("span",{key:"430a10214dbcfa50b9b24da625099f6b972bb076",slot:"heading"},s("slot",{key:"31fbe8804df2e1be5de9c94238cf34d733aebd80",name:"heading"},this.heading||wp.i18n.__("Downloads","surecart"))),s("sc-pagination",{key:"9e09d0496dd94ae78d72af9e8f7f3de401960fe9",slot:"after",page:this.query.page,perPage:this.query.per_page,total:this.pagination.total,totalPages:this.pagination.total_pages,totalShowing:(t=this===null||this===void 0?void 0:this.purchases)===null||t===void 0?void 0:t.length,onScNextPage:()=>this.nextPage(),onScPrevPage:()=>this.prevPage()}))}get el(){return a(this)}};h.style=d;export{h as sc_dashboard_downloads_list};
//# sourceMappingURL=p-03e6d153.entry.js.map