import{LitElement as e,html as t,css as i}from"lit";import{iconRemixInformationFill as c}from"./assets/cc-remix.icons.js";import{ResizeController as o}from"./controllers/resize-controller.js";import{unique as s,sortBy as n}from"./lib/utils.js";import{ccLink as l,linkStyles as r}from"./templates/cc-link/cc-link.js";import{i18n as a}from"./translation.js";import"./cc-block-section.js";import"./cc-block.js";import"./cc-button.js";import{PENDING_STATUSES as v,PROCESSING_STATUS as d,PROCESSED_STATUSES as p}from"./cc-invoice-table.js";import"./cc-notice.js";import"./cc-select.js";import"./cc-toggle.js";const g=[520];function m(e){const t=new Date(e).getUTCFullYear();return String(t)}class b extends e{static get properties(){return{state:{type:Object},_yearFilter:{type:String,state:!0}}}constructor(){super(),this.state={type:"loading"},this._yearFilter=null,new o(this,{widthBreakpoints:g})}_onYearFilterValue({detail:e}){this._yearFilter=e}render(){if("error"===this.state.type)return this._renderView(t`<cc-notice slot=content intent=warning message=${a("cc-invoice-list.error")}></cc-notice>`);if("loading"===this.state.type)return this._renderView(t`<cc-block-section slot=content-body><div slot=title>${a("cc-invoice-list.pending")}</div><cc-invoice-table></cc-invoice-table></cc-block-section><cc-block-section slot=content-body><div slot=title>${a("cc-invoice-list.processed")}</div><cc-invoice-table></cc-invoice-table></cc-block-section>`);const e={type:"loaded",invoices:this.state.invoices.filter((e=>v.includes(e.status)))},i={type:"loaded",invoices:this.state.invoices.filter((e=>e.status===d))},c={type:"loaded",invoices:this.state.invoices.filter((e=>p.includes(e.status)))},o=c.invoices.map((e=>m(e.emissionDate))).flatMap(s),l=o.map((e=>({label:e,value:e}))).sort(n("label")),r=null==this._yearFilter?function(e){const t=e.map((e=>Number(e))),i=Math.max(...t);return String(i)}(o):this._yearFilter,g={type:"loaded",invoices:c.invoices.filter((e=>m(e.emissionDate)===r))},b=g.invoices.length>0&&l.length>1;return this._renderView(t`<cc-block-section slot=content-body><div slot=title>${a("cc-invoice-list.pending")}</div>${e.invoices.length>0?t`<cc-invoice-table .state=${e}></cc-invoice-table>`:""} ${0===e.invoices.length?t`<div class=empty-msg>${a("cc-invoice-list.pending.no-invoices")}</div>`:""}</cc-block-section>${i.invoices.length>0?t`<cc-block-section slot=content-body><div slot=title>${a("cc-invoice-list.processing")}</div><cc-invoice-table .state=${i}></cc-invoice-table></cc-block-section>`:""}<cc-block-section slot=content-body><div slot=title>${a("cc-invoice-list.processed")}</div>${b?t`<cc-toggle legend=${a("cc-invoice-list.year")} .choices=${l} value=${r} inline @cc-toggle:input=${this._onYearFilterValue}></cc-toggle><cc-select label=${a("cc-invoice-list.year")} .options=${l} value=${r} inline @cc-select:input=${this._onYearFilterValue}></cc-select>`:""} ${g.invoices.length>0?t`<cc-invoice-table .state=${g}></cc-invoice-table>`:""} ${0===g.invoices.length?t`<div class=empty-msg>${a("cc-invoice-list.processed.no-invoices")}</div>`:""}</cc-block-section>`)}_renderView(e){return t`<cc-block><div slot=header-title>${a("cc-invoice-list.title")}</div>${e}<div slot=footer-right>${l("https://developers.clever-cloud.com/doc/billing/unified-invoices/",t`<cc-icon .icon=${c}></cc-icon>${a("cc-invoice-list.documentation.text")}`)}</div></cc-block>`}static get styles(){return[r,i`:host{display:block}cc-toggle{justify-self:start}:host([w-lt-520]) cc-toggle{display:none}:host([w-gte-520]) cc-select{display:none}cc-select{width:max-content}.empty-msg{color:var(--cc-color-text-weak);font-style:italic}[slot=footer-right] .cc-link{align-items:center;display:flex;gap:.5em}`]}}window.customElements.define("cc-invoice-list",b);export{b as CcInvoiceList};
//# sourceMappingURL=cc-invoice-list.js.map
