import{r as t,h as s,g as e}from"./p-dfbe004d.js";import{_ as r,s as i}from"./p-8415f806.js";import"./p-fd56940f.js";import{a}from"./p-7393a06c.js";import{o}from"./p-c2833cb1.js";import{a as n}from"./p-1c2e2695.js";import"./p-9a7a47e8.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:["checkout","checkout.order"],...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:r("Something went wrong","surecart"),console.error(this.error)}finally{this.loading=!1,this.loaded=!0}}renderRefundStatus(t){return(null==t?void 0:t.fully_refunded)?s("sc-tag",{type:"danger"},r("Refunded","surecart")):(null==t?void 0:t.refunded_amount)?s("sc-tag",{type:"warning"},r("Partially Refunded","surecart")):s("sc-tag",{type:"success"},r("Paid","surecart"))}renderEmpty(){return s("sc-stacked-list-row",{"mobile-size":0},s("slot",{name:"empty"},r("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;const{currency:a,amount:o,created_at:l}=t;return s("sc-stacked-list-row",{style:{"--columns":"4"},"mobile-size":600,href:n(window.location.href,{action:"show",model:"order",id:null===(e=t.checkout.order)||void 0===e?void 0:e.id})},s("strong",null,s("sc-format-date",{date:l,type:"timestamp",month:"short",day:"numeric",year:"numeric"})),s("sc-text",{style:{"--color":"var(--sc-color-gray-500)"}},i(r("#%s","surecart"),t.checkout.order.number)),s("div",null,this.renderRefundStatus(t)),s("strong",null,s("sc-format-number",{type:"currency",value:o,currency:a})))}))}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||r("Payment History","surecart"))),!!this.allLink&&s("sc-button",{type:"link",href:this.allLink,slot:"end"},r("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}