import{LitElement as e,html as t,css as i}from"lit";import{ResizeController as c}from"./controllers/resize-controller.js";import{unique as s,sortBy as o}from"./lib/utils.js";import{i18n as n}from"./translation.js";import"./cc-block-section.js";import"./cc-block.js";import"./cc-button.js";import{PENDING_STATUSES as l,PROCESSING_STATUS as r,PROCESSED_STATUSES as a}from"./cc-invoice-table.js";import"./cc-notice.js";import"./cc-select.js";import"./cc-toggle.js";const v=[520];function d(e){const t=new Date(e).getUTCFullYear();return String(t)}class p extends e{static get properties(){return{state:{type:Object},_yearFilter:{type:String,state:!0}}}constructor(){super(),this.state={type:"loading"},this._yearFilter=null,new c(this,{widthBreakpoints:v})}_onYearFilterValue({detail:e}){this._yearFilter=e}render(){if("error"===this.state.type)return this._renderView(t`<cc-notice intent=warning message=${n("cc-invoice-list.error")}></cc-notice>`);if("loading"===this.state.type)return this._renderView(t`<cc-block-section><div slot=title>${n("cc-invoice-list.pending")}</div><cc-invoice-table></cc-invoice-table></cc-block-section><cc-block-section><div slot=title>${n("cc-invoice-list.processed")}</div><cc-invoice-table></cc-invoice-table></cc-block-section>`);const e={type:"loaded",invoices:this.state.invoices.filter((e=>l.includes(e.status)))},i={type:"loaded",invoices:this.state.invoices.filter((e=>e.status===r))},c={type:"loaded",invoices:this.state.invoices.filter((e=>a.includes(e.status)))},v=c.invoices.map((e=>d(e.emissionDate))).flatMap(s),p=v.map((e=>({label:e,value:e}))).sort(o("label")),g=null==this._yearFilter?function(e){const t=e.map((e=>Number(e))),i=Math.max(...t);return String(i)}(v):this._yearFilter,b={type:"loaded",invoices:c.invoices.filter((e=>d(e.emissionDate)===g))},m=b.invoices.length>0&&p.length>1;return this._renderView(t`<cc-block-section><div slot=title>${n("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>${n("cc-invoice-list.pending.no-invoices")}</div>`:""}</cc-block-section>${i.invoices.length>0?t`<cc-block-section><div slot=title>${n("cc-invoice-list.processing")}</div><cc-invoice-table .state=${i}></cc-invoice-table></cc-block-section>`:""}<cc-block-section><div slot=title>${n("cc-invoice-list.processed")}</div>${m?t`<cc-toggle legend=${n("cc-invoice-list.year")} .choices=${p} value=${g} inline @cc-toggle:input=${this._onYearFilterValue}></cc-toggle><cc-select label=${n("cc-invoice-list.year")} .options=${p} value=${g} inline @cc-select:input=${this._onYearFilterValue}></cc-select>`:""} ${b.invoices.length>0?t`<cc-invoice-table .state=${b}></cc-invoice-table>`:""} ${0===b.invoices.length?t`<div class=empty-msg>${n("cc-invoice-list.processed.no-invoices")}</div>`:""}</cc-block-section>`)}_renderView(e){return t`<cc-block><div slot=title>${n("cc-invoice-list.title")}</div>${e}</cc-block>`}static get styles(){return[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}`]}}window.customElements.define("cc-invoice-list",p);export{p as CcInvoiceList};
//# sourceMappingURL=cc-invoice-list.js.map
