import{r as e,h as t,a as s}from"./p-9add63ef.js";import"./p-8dccb656.js";import{o as i}from"./p-b719a497.js";import{a}from"./p-401e165e.js";import{a as r}from"./p-259c3935.js";import"./p-d3366af3.js";const o=":host{display:block;position:relative}.charges-list{display:grid;gap:1em}";const n=o;const d=class{constructor(t){e(this,t);this.query={page:1,per_page:10};this.heading=undefined;this.showPagination=true;this.allLink=undefined;this.charges=[];this.loading=undefined;this.loaded=undefined;this.error=undefined;this.pagination={total:0,total_pages:0}}componentWillLoad(){i(this.el,(()=>{this.getItems()}))}async getItems(){try{this.loading=true;const e=await r({path:a(`surecart/v1/charges/`,{expand:["checkout","checkout.order"],...this.query}),parse:false});this.pagination={total:parseInt(e.headers.get("X-WP-Total")),total_pages:parseInt(e.headers.get("X-WP-TotalPages"))};this.charges=await e.json()}catch(e){if(e===null||e===void 0?void 0:e.message){this.error=e.message}else{this.error=wp.i18n.__("Something went wrong","surecart")}console.error(this.error)}finally{this.loading=false;this.loaded=true}}renderRefundStatus(e){if(e===null||e===void 0?void 0:e.fully_refunded){return t("sc-tag",{type:"danger"},wp.i18n.__("Refunded","surecart"))}if(e===null||e===void 0?void 0:e.refunded_amount){return t("sc-tag",{type:"warning"},wp.i18n.__("Partially Refunded","surecart"))}return t("sc-tag",{type:"success"},wp.i18n.__("Paid","surecart"))}renderEmpty(){return t("sc-stacked-list-row",{"mobile-size":0},t("slot",{name:"empty"},wp.i18n.__("You have no saved payment methods.","surecart")))}renderLoading(){return t("sc-stacked-list-row",{style:{"--columns":"2"},"mobile-size":0},t("div",{style:{padding:"0.5em"}},t("sc-skeleton",{style:{width:"30%",marginBottom:"0.75em"}}),t("sc-skeleton",{style:{width:"20%",marginBottom:"0.75em"}}),t("sc-skeleton",{style:{width:"40%"}})))}renderContent(){var e;if(this.loading&&!this.loaded){return this.renderLoading()}if(((e=this.charges)===null||e===void 0?void 0:e.length)===0){return this.renderEmpty()}return this.charges.map((e=>{var s;const{created_at_date:i,display_amount:r}=e;return t("sc-stacked-list-row",{style:{"--columns":"4"},"mobile-size":600,href:a(window.location.href,{action:"show",model:"order",id:(s=e.checkout.order)===null||s===void 0?void 0:s.id})},t("strong",null,i),t("sc-text",{style:{"--color":"var(--sc-color-gray-500)"}},wp.i18n.sprintf(wp.i18n.__("#%s","surecart"),e.checkout.order.number)),t("div",null,this.renderRefundStatus(e)),t("strong",null,r))}))}nextPage(){this.query.page=this.query.page+1;this.getItems()}prevPage(){this.query.page=this.query.page-1;this.getItems()}render(){var e;return t("sc-dashboard-module",{key:"4bff2aa5b6a9730e58a62e99185eb142d5b481a3",class:"charges-list",error:this.error},t("span",{key:"5423f7a4bb3898f58035e7f57bb78d7096640dbc",slot:"heading"},t("slot",{key:"2976371f97c26a934b6ccfeb9495e483bbaad940",name:"heading"},this.heading||wp.i18n.__("Payment History","surecart"))),!!this.allLink&&t("sc-button",{key:"45d0a8cbc5db519c973782004f514299bcd4e574",type:"link",href:this.allLink,slot:"end"},wp.i18n.__("View all","surecart"),t("sc-icon",{key:"f683c4fa2b3697800de9152957edb0941c5e7130",name:"chevron-right",slot:"suffix"})),t("sc-card",{key:"11a3d342da7ddbf7139253b742900122ad28efb5","no-padding":true,style:{"--overflow":"hidden"}},t("sc-stacked-list",{key:"29d259661e86e3835291d35e7aa353f0b8b2f325"},this.renderContent())),this.showPagination&&t("sc-pagination",{key:"dc09932e2939ff648ef61798e33230cbee85de1b",page:this.query.page,perPage:this.query.per_page,total:this.pagination.total,totalPages:this.pagination.total_pages,totalShowing:(e=this===null||this===void 0?void 0:this.charges)===null||e===void 0?void 0:e.length,onScNextPage:()=>this.nextPage(),onScPrevPage:()=>this.prevPage()}),this.loading&&this.loaded&&t("sc-block-ui",{key:"6de6993b582447bcb9a7846e706888e4e2bf899e",spinner:true}))}get el(){return s(this)}};d.style=n;export{d as sc_charges_list};
//# sourceMappingURL=p-0d211387.entry.js.map