import{r as t,h as s,g as e}from"./p-b891c2f1.js";import{_ as i,s as r}from"./p-684c85b4.js";import"./p-aafd8ea4.js";import{a}from"./p-6fd3642a.js";import{o}from"./p-c2833cb1.js";import{a as n}from"./p-1c2e2695.js";import"./p-112455b1.js";const l=class{constructor(s){t(this,s),this.query={page:1,per_page:10},this.showPagination=!0,this.charges=[],this.pagination={total:0,total_pages:0}}componentWillLoad(){o(this.el,(()=>{this.getItems()}))}async getItems(){try{this.loading=!0;const t=await a({path:n("surecart/v1/charges/",{expand:["order","invoice"],...this.query}),parse:!1});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){this.error=(null==t?void 0:t.message)?t.message:i("Something went wrong","surecart"),console.error(this.error)}finally{this.loading=!1,this.loaded=!0}}renderOrderInvoiceNumber(t){var s,e;return"object"==typeof(null==t?void 0:t.order)&&(null===(s=t.order)||void 0===s?void 0:s.number)?r(i("Order #%s","surecart"),t.order.number):"object"==typeof(null==t?void 0:t.invoice)&&(null===(e=t.invoice)||void 0===e?void 0:e.number)?r(i("Invoice #%s","surecart"),t.invoice.number):void 0}renderRefundStatus(t){return(null==t?void 0:t.fully_refunded)?s("sc-tag",{type:"danger"},i("Refunded","surecart")):(null==t?void 0:t.refunded_amount)?s("sc-tag",{type:"warning"},i("Partially Refunded","surecart")):s("sc-tag",{type:"success"},i("Paid","surecart"))}renderEmpty(){return s("sc-stacked-list-row",{"mobile-size":0},s("slot",{name:"empty"},i("You have no saved payment methods.","surecart")))}renderLoading(){return 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%"}})))}renderContent(){var t;return this.loading&&!this.loaded?this.renderLoading():0===(null===(t=this.charges)||void 0===t?void 0:t.length)?this.renderEmpty():this.charges.map((t=>{var e,i;const{currency:r,amount:a,created_at:o}=t;return s("sc-stacked-list-row",{style:{"--columns":"4"},"mobile-size":600,href:(null===(e=null==t?void 0:t.order)||void 0===e?void 0:e.url)||(null===(i=null==t?void 0:t.invoice)||void 0===i?void 0:i.url)},s("strong",null,s("sc-format-date",{date:o,type:"timestamp",month:"short",day:"numeric",year:"numeric"})),s("sc-text",{style:{"--color":"var(--sc-color-gray-500)"}},this.renderOrderInvoiceNumber(t)),s("div",null,this.renderRefundStatus(t)),s("strong",null,s("sc-format-number",{type:"currency",value:a,currency: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 s("sc-dashboard-module",{class:"charges-list",error:this.error},s("span",{slot:"heading"},s("slot",{name:"heading"},this.heading||i("Payment History","surecart"))),!!this.allLink&&s("sc-button",{type:"link",href:this.allLink,slot:"end"},i("View all","surecart"),s("sc-icon",{name:"chevron-right",slot:"suffix"})),s("sc-card",{"no-padding":!0,style:{"--overflow":"hidden"}},s("sc-stacked-list",null,this.renderContent())),this.showPagination&&s("sc-pagination",{page:this.query.page,perPage:this.query.per_page,total:this.pagination.total,totalPages:this.pagination.total_pages,totalShowing:null===(t=null==this?void 0:this.charges)||void 0===t?void 0:t.length,onScNextPage:()=>this.nextPage(),onScPrevPage:()=>this.prevPage()}),this.loading&&this.loaded&&s("sc-block-ui",{spinner:!0}))}get el(){return e(this)}};l.style=":host{display:block;position:relative}.charges-list{display:grid;gap:1em}";export{l as sc_charges_list}