import{r as t,h as s,g as a}from"./p-dfbe004d.js";import{_ as i}from"./p-8415f806.js";import"./p-fd56940f.js";import{a as o}from"./p-7393a06c.js";import{o as e}from"./p-c2833cb1.js";import{a as h}from"./p-1c2e2695.js";import"./p-9a7a47e8.js";const r=class{constructor(s){t(this,s),this.query={page:1,per_page:10},this.purchases=[],this.pagination={total:0,total_pages:0}}componentWillLoad(){e(this.el,(()=>{this.initialFetch()}))}async initialFetch(){if(this.isCustomer)try{this.loading=!0,await this.getItems()}catch(t){console.error(this.error),this.error=(null==t?void 0:t.message)||i("Something went wrong","surecart")}finally{this.loading=!1}}async fetchItems(){if(this.isCustomer)try{this.busy=!0,await this.getItems()}catch(t){console.error(this.error),this.error=(null==t?void 0:t.message)||i("Something went wrong","surecart")}finally{this.busy=!1}}async getItems(){const t=await await o({path:h("surecart/v1/purchases/",{expand:["product","product.downloads","download.media"],downloadable:!0,revoked:!1,...this.query}),parse:!1});return this.pagination={total:parseInt(t.headers.get("X-WP-Total")),total_pages:parseInt(t.headers.get("X-WP-TotalPages"))},this.purchases=await t.json(),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",{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",{slot:"heading"},s("slot",{name:"heading"},this.heading||i("Downloads","surecart"))),s("sc-pagination",{slot:"after",page:this.query.page,perPage:this.query.per_page,total:this.pagination.total,totalPages:this.pagination.total_pages,totalShowing:null===(t=null==this?void 0:this.purchases)||void 0===t?void 0:t.length,onScNextPage:()=>this.nextPage(),onScPrevPage:()=>this.prevPage()}))}get el(){return a(this)}};r.style=":host{display:block}.download__details{opacity:0.75}";export{r as sc_dashboard_downloads_list}