import{r as e,h as t,a as s}from"./p-e97fde0a.js";import{a}from"./p-dd3464cd.js";import{o as i}from"./p-b719a497.js";import{a as r}from"./p-401e165e.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 a({path:r(`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:a,display_amount:i}=e;return t("sc-stacked-list-row",{style:{"--columns":"4"},"mobile-size":600,href:r(window.location.href,{action:"show",model:"order",id:(s=e.checkout.order)===null||s===void 0?void 0:s.id})},t("strong",null,a),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,i))}))}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:"19f9a14ef83b6da0c80e1b7ba94ad48d4ec9f475",class:"charges-list",error:this.error},t("span",{key:"0550d7d7254169290f9a1f946aabff9aed4de921",slot:"heading"},t("slot",{key:"aedc10b656a45b65feac521fd59a716a083bf1e7",name:"heading"},this.heading||wp.i18n.__("Payment History","surecart"))),!!this.allLink&&t("sc-button",{key:"a4943ee8d8fd3d42278623f66777cb2546aaa27e",type:"link",href:this.allLink,slot:"end"},wp.i18n.__("View all","surecart"),t("sc-icon",{key:"c42dcab818f10a4b2ac445193f0074f919b5560b",name:"chevron-right",slot:"suffix"})),t("sc-card",{key:"eacc48fe6d3e7829b554cfad24fd7e81d451178c","no-padding":true,style:{"--overflow":"hidden"}},t("sc-stacked-list",{key:"6495a8d123f60b40cab6c8e496be21562695ce5d"},this.renderContent())),this.showPagination&&t("sc-pagination",{key:"8fb7a756f8e8b286779f1497829f641aecbf3bc7",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:"22b37e853aa5ea0081f35e0bfb168b4b799c5fdd",spinner:true}))}get el(){return s(this)}};d.style=n;export{d as sc_charges_list};
//# sourceMappingURL=p-9d6b2b61.entry.js.map