import{r as t,h as s,g as e}from"./p-dfbe004d.js";import{_ as i,s as r,a}from"./p-8415f806.js";import"./p-fd56940f.js";import{a as o}from"./p-7393a06c.js";import{o as n}from"./p-c2833cb1.js";import{a as l}from"./p-1c2e2695.js";import"./p-9a7a47e8.js";const c=class{constructor(s){t(this,s),this.query={page:1,per_page:10},this.invoices=[],this.pagination={total:0,total_pages:0}}componentWillLoad(){n(this.el,(()=>{this.initialFetch()}))}async initialFetch(){try{this.loading=!0,await this.getItems()}catch(t){console.error(this.error),this.error=(null==t?void 0:t.message)||i("Something went wrong","surecart")}finally{this.loading=!1}}async fetchItems(){try{this.busy=!0,await this.getItems()}catch(t){console.error(this.error),this.error=(null==t?void 0:t.message)||i("Something went wrong","surecart")}finally{this.busy=!1}}async getItems(){const t=await await o({path:l("surecart/v1/invoices/",{expand:["invoice_items","charge"],...this.query}),parse:!1});return this.pagination={total:parseInt(t.headers.get("X-WP-Total")),total_pages:parseInt(t.headers.get("X-WP-TotalPages"))},this.invoices=await t.json(),this.invoices}nextPage(){this.query.page=this.query.page+1,this.fetchItems()}prevPage(){this.query.page=this.query.page-1,this.fetchItems()}renderStatusBadge(t){const{status:e,charge:r}=t;if("object"==typeof r){if(null==r?void 0:r.fully_refunded)return s("sc-tag",{type:"danger"},i("Refunded","surecart"));if(null==r?void 0:r.refunded_amount)return s("sc-tag",{type:"info"},i("Partially Refunded","surecart"))}return s("sc-order-status-badge",{status:e})}renderLoading(){return s("sc-card",{noPadding:!0},s("sc-stacked-list",null,s("sc-stacked-list-row",{style:{"--columns":"4"},"mobile-size":500},[...Array(4)].map((()=>s("sc-skeleton",{style:{width:"100px",display:"inline-block"}}))))))}renderEmpty(){return s("div",null,s("sc-divider",{style:{"--spacing":"0"}}),s("slot",{name:"empty"},s("sc-empty",{icon:"tag"},i("You don't have any invoices.","surecart"))))}renderList(){return this.invoices.map((t=>{var e,i;const{invoice_items:o,total_amount:n,currency:l,created_at:c,url:d}=t;return s("sc-stacked-list-row",{href:d,style:{"--columns":"4"},"mobile-size":500},s("div",null,s("sc-format-date",{class:"order__date",date:c,type:"timestamp",month:"short",day:"numeric",year:"numeric"})),s("div",null,s("sc-text",{truncate:!0,style:{"--color":"var(--sc-color-gray-500)"}},r(a("%s item","%s items",(null===(e=null==o?void 0:o.pagination)||void 0===e?void 0:e.count)||0,"surecart"),(null===(i=null==o?void 0:o.pagination)||void 0===i?void 0:i.count)||0))),s("div",null,this.renderStatusBadge(t)),s("div",null,s("sc-format-number",{type:"currency",currency:l,value:n})))}))}renderContent(){var t;return this.loading?this.renderLoading():0===(null===(t=this.invoices)||void 0===t?void 0:t.length)?this.renderEmpty():s("sc-card",{"no-padding":!0},s("sc-stacked-list",null,this.renderList()))}render(){var t,e;return s("sc-dashboard-module",{class:"invoices-list",error:this.error},s("span",{slot:"heading"},s("slot",{name:"heading"},this.heading||i("Invoice History","surecart"))),!!this.allLink&&!!(null===(t=this.invoices)||void 0===t?void 0:t.length)&&s("sc-button",{type:"link",href:this.allLink,slot:"end"},i("View all","surecart"),s("sc-icon",{name:"chevron-right",slot:"suffix"})),this.renderContent(),!this.allLink&&s("sc-pagination",{page:this.query.page,perPage:this.query.per_page,total:this.pagination.total,totalPages:this.pagination.total_pages,totalShowing:null===(e=null==this?void 0:this.invoices)||void 0===e?void 0:e.length,onScNextPage:()=>this.nextPage(),onScPrevPage:()=>this.prevPage()}),this.busy&&s("sc-block-ui",null))}get el(){return e(this)}};c.style=":host{display:block}.orders-list{display:grid;gap:0.75em}.orders-list__heading{display:flex;flex-wrap:wrap;align-items:flex-end;justify-content:space-between}.orders-list__title{font-size:var(--sc-font-size-x-large);font-weight:var(--sc-font-weight-bold);line-height:var(--sc-line-height-dense)}.orders-list a{text-decoration:none;font-weight:var(--sc-font-weight-semibold);display:inline-flex;align-items:center;gap:0.25em;color:var(--sc-color-primary-500)}.order__row{color:var(--sc-color-gray-800);text-decoration:none;display:grid;align-items:center;justify-content:space-between;gap:0;grid-template-columns:1fr 1fr 1fr auto;margin:0;padding:var(--sc-spacing-small) var(--sc-spacing-large)}.order__row:not(:last-child){border-bottom:1px solid var(--sc-color-gray-200)}.order__row:hover{background:var(--sc-color-gray-50)}.order__date{font-weight:var(--sc-font-weight-semibold)}";export{c as sc_invoices_list}