import{r as t,h as s,a as i}from"./p-9add63ef.js";import"./p-445fd8b4.js";import{o as e}from"./p-b719a497.js";import{a as n}from"./p-401e165e.js";import{a}from"./p-259c3935.js";import"./p-d3366af3.js";const o=":host{display:block}.subscriptions-list{display:grid;gap:0.5em}.subscriptions-list__heading{display:flex;flex-wrap:wrap;align-items:flex-end;justify-content:space-between;margin-bottom:0.5em}.subscriptions-list__title{font-size:var(--sc-font-size-x-large);font-weight:var(--sc-font-weight-bold);line-height:var(--sc-line-height-dense)}.subscriptions-list a{text-decoration:none;font-weight:var(--sc-font-weight-semibold);display:inline-flex;align-items:center;gap:0.25em;color:var(--sc-color-primary-500)}.subscriptions__title{display:none}.subscriptions--has-title-slot .subscriptions__title{display:block}";const r=o;const c=class{constructor(s){t(this,s);this.query={page:1,per_page:10};this.allLink=undefined;this.heading=undefined;this.isCustomer=undefined;this.cancelBehavior="period_end";this.subscriptions=[];this.loading=undefined;this.busy=undefined;this.error=undefined;this.pagination={total:0,total_pages:0}}componentWillLoad(){e(this.el,(()=>{this.initialFetch()}))}async initialFetch(){try{this.loading=true;await this.getSubscriptions()}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 fetchSubscriptions(){try{this.busy=true;await this.getSubscriptions()}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 getSubscriptions(){if(!this.isCustomer){return}const t=await await a({path:n(`surecart/v1/subscriptions/`,{expand:["price","price.product","current_period","period.checkout","purchase","purchase.license","license.activations","discount","discount.coupon"],...this.query}),parse:false});this.pagination={total:parseInt(t.headers.get("X-WP-Total")),total_pages:parseInt(t.headers.get("X-WP-TotalPages"))};this.subscriptions=await t.json();return this.subscriptions}nextPage(){this.query.page=this.query.page+1;this.fetchSubscriptions()}prevPage(){this.query.page=this.query.page-1;this.fetchSubscriptions()}renderEmpty(){return s("div",null,s("sc-divider",{style:{"--spacing":"0"}}),s("slot",{name:"empty"},s("sc-empty",{icon:"repeat"},wp.i18n.__("You don't have any subscriptions.","surecart"))))}renderLoading(){return s("sc-card",{"no-padding":true,style:{"--overflow":"hidden"}},s("sc-stacked-list",null,s("sc-stacked-list-row",{style:{"--columns":"2"},"mobile-size":0},s("div",{style:{padding:"0.5em"}},s("sc-skeleton",{style:{width:"30%",marginBottom:"0.75em"}}),s("sc-skeleton",{style:{width:"20%",marginBottom:"0.75em"}}),s("sc-skeleton",{style:{width:"40%"}})))))}getSubscriptionLink(t){return n(window.location.href,{action:"edit",model:"subscription",id:t.id})}renderList(){return this.subscriptions.map((t=>s("sc-stacked-list-row",{href:this.getSubscriptionLink(t),key:t.id,"mobile-size":0},s("sc-subscription-details",{subscription:t}),s("sc-icon",{name:"chevron-right",slot:"suffix"}))))}renderContent(){var t;if(this.loading){return this.renderLoading()}if(((t=this.subscriptions)===null||t===void 0?void 0:t.length)===0){return this.renderEmpty()}return s("sc-card",{"no-padding":true,style:{"--overflow":"hidden"}},s("sc-stacked-list",null,this.renderList()))}render(){var t,i;return s("sc-dashboard-module",{key:"967ffb0b6fe482e178b220b06cbfe22640cbba28",class:"subscriptions-list",error:this.error},s("span",{key:"2a4b9060dab4c36751b886c24e549718e515b31e",slot:"heading"},s("slot",{key:"0127ee91510b2145c976c6613173016f490880c9",name:"heading"},this.heading||wp.i18n.__("Subscriptions","surecart"))),!!this.allLink&&!!((t=this.subscriptions)===null||t===void 0?void 0:t.length)&&s("sc-button",{key:"2f37882d96b5abb1e623ae133b6779cde7a0f283",type:"link",href:this.allLink,slot:"end","aria-label":wp.i18n.sprintf(wp.i18n.__("View all %s","surecart"),this.heading||"Subscriptions")},wp.i18n.__("View all","surecart"),s("sc-icon",{key:"61412517d10a8a25ae71426d66d6d470b3bb1e74","aria-hidden":"true",name:"chevron-right",slot:"suffix"})),this.renderContent(),!this.allLink&&s("sc-pagination",{key:"b992f17d13be51fcdf9384d86e700de7015c16e2",page:this.query.page,perPage:this.query.per_page,total:this.pagination.total,totalPages:this.pagination.total_pages,totalShowing:(i=this===null||this===void 0?void 0:this.subscriptions)===null||i===void 0?void 0:i.length,onScNextPage:()=>this.nextPage(),onScPrevPage:()=>this.prevPage()}),this.busy&&s("sc-block-ui",{key:"3b06d5ecc2123389e3c8e9a1aeadd1d3fb3c3a4c"}))}get el(){return i(this)}};c.style=r;export{c as sc_subscriptions_list};
//# sourceMappingURL=p-c6d759eb.entry.js.map