import{r as t,h as e,a as s}from"./p-9add63ef.js";import"./p-445fd8b4.js";import{o as a}from"./p-b719a497.js";import{a as i}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(e){t(this,e);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 t=await r({path:i(`surecart/v1/charges/`,{expand:["checkout","checkout.order"],...this.query}),parse:false});this.pagination={total:parseInt(t.headers.get("X-WP-Total")),total_pages:parseInt(t.headers.get("X-WP-TotalPages"))};this.charges=await t.json()}catch(t){if(t===null||t===void 0?void 0:t.message){this.error=t.message}else{this.error=wp.i18n.__("Something went wrong","surecart")}console.error(this.error)}finally{this.loading=false;this.loaded=true}}renderRefundStatus(t){if(t===null||t===void 0?void 0:t.fully_refunded){return e("sc-tag",{type:"danger"},wp.i18n.__("Refunded","surecart"))}if(t===null||t===void 0?void 0:t.refunded_amount){return e("sc-tag",{type:"warning"},wp.i18n.__("Partially Refunded","surecart"))}return e("sc-tag",{type:"success"},wp.i18n.__("Paid","surecart"))}renderEmpty(){return e("sc-stacked-list-row",{"mobile-size":0},e("slot",{name:"empty"},wp.i18n.__("You have no saved payment methods.","surecart")))}renderLoading(){return e("sc-stacked-list-row",{style:{"--columns":"2"},"mobile-size":0},e("div",{style:{padding:"0.5em"}},e("sc-skeleton",{style:{width:"30%",marginBottom:"0.75em"}}),e("sc-skeleton",{style:{width:"20%",marginBottom:"0.75em"}}),e("sc-skeleton",{style:{width:"40%"}})))}renderContent(){var t;if(this.loading&&!this.loaded){return this.renderLoading()}if(((t=this.charges)===null||t===void 0?void 0:t.length)===0){return this.renderEmpty()}return this.charges.map((t=>{var s;const{created_at_date:a,display_amount:r}=t;return e("sc-stacked-list-row",{style:{"--columns":"4"},"mobile-size":600,href:i(window.location.href,{action:"show",model:"order",id:(s=t.checkout.order)===null||s===void 0?void 0:s.id})},e("strong",null,a),e("sc-text",{style:{"--color":"var(--sc-color-gray-500)"}},wp.i18n.sprintf(wp.i18n.__("#%s","surecart"),t.checkout.order.number)),e("div",null,this.renderRefundStatus(t)),e("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 t;return e("sc-dashboard-module",{key:"e63b82f5be0dae89f51dc53861af6f01557004fb",class:"charges-list",error:this.error},e("span",{key:"18c690252fa71980458c5ea9a0259ed4c58200ec",slot:"heading"},e("slot",{key:"451c50790882c1ffd1852d697ada6479b69f61e0",name:"heading"},this.heading||wp.i18n.__("Payment History","surecart"))),!!this.allLink&&e("sc-button",{key:"263baabfbbfa3f28f454a653845b7bbf1d60434b",type:"link",href:this.allLink,slot:"end"},wp.i18n.__("View all","surecart"),e("sc-icon",{key:"38bbf6026a264b103404774c0d009797fbb8f00e",name:"chevron-right",slot:"suffix"})),e("sc-card",{key:"74b4e192ef653a72a19fc2d3b62a8e023e0e0c8c","no-padding":true,style:{"--overflow":"hidden"}},e("sc-stacked-list",{key:"9ab6894493f6f97d61abe140d70764ace8d0f740"},this.renderContent())),this.showPagination&&e("sc-pagination",{key:"f4b7109eed3e401b3ab42ea12a40687322e69eb9",page:this.query.page,perPage:this.query.per_page,total:this.pagination.total,totalPages:this.pagination.total_pages,totalShowing:(t=this===null||this===void 0?void 0:this.charges)===null||t===void 0?void 0:t.length,onScNextPage:()=>this.nextPage(),onScPrevPage:()=>this.prevPage()}),this.loading&&this.loaded&&e("sc-block-ui",{key:"aa02b5d1089c78a8ab7630d249fcd76ef65f9af3",spinner:true}))}get el(){return s(this)}};d.style=n;export{d as sc_charges_list};
//# sourceMappingURL=p-1f458e06.entry.js.map