import{r as e,h as t,a as s}from"./p-e97fde0a.js";import{a as i}from"./p-dd3464cd.js";import{o as a}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 d=o;const n=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(){a(this.el,(()=>{this.getItems()}))}async getItems(){try{this.loading=true;const e=await i({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:i,display_amount:a}=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,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,a))}))}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:"b56d22ca3b94a216dbe7270954ee50602c694610",class:"charges-list",error:this.error},t("span",{key:"b30c306a6c4a5d970db79297f20085d6ca378454",slot:"heading"},t("slot",{key:"b0280110e26446bd44d4794494734abe5e492715",name:"heading"},this.heading||wp.i18n.__("Payment History","surecart"))),!!this.allLink&&t("sc-button",{key:"bddeda819eac6f5dbbf217608360112986c9bf83",type:"link",href:this.allLink,slot:"end"},wp.i18n.__("View all","surecart"),t("sc-icon",{key:"6eee2f83861c880a0f95af7c75533137f8cfbd92",name:"chevron-right",slot:"suffix"})),t("sc-card",{key:"9c3ec1daa18f5337f07e962d6cb1e241c6eabebd","no-padding":true,style:{"--overflow":"hidden"}},t("sc-stacked-list",{key:"ed3ea1efa8a2d2ed21211e5e161eff268a6f45ff"},this.renderContent())),this.showPagination&&t("sc-pagination",{key:"681d48dc1c067f0b2fa5e96c9e2bf872f41e2f9e",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:"8aafdc530b1f017354330af84b7c857c1dfc729b",spinner:true}))}get el(){return s(this)}};n.style=d;export{n as sc_charges_list};
//# sourceMappingURL=p-b6eec6a7.entry.js.map