import{r as i,d as o,h as t}from"./p-03169580.js";import{r as l}from"./p-ef308962.js";import"./p-82ae0260.js";import"./p-80de33dc.js";import"./p-3775d1fc.js";import"./p-c2fbed0d.js";import"./p-5717491f.js";let e=class{constructor(t){i(this,t);this.fireenjinFetch=o(this,"fireenjinFetch",7);this.groupBy="month";this.timeframe=new Date;this.options=[];this.paths={};this.totals={}}async onSuccess(i){var o,t,l,e,n,d,s,v,a,r,h,u,c,f;if(((o=i===null||i===void 0?void 0:i.detail)===null||o===void 0?void 0:o.endpoint)==="findTotaller"){const o=(e=(l=(t=i===null||i===void 0?void 0:i.detail)===null||t===void 0?void 0:t.data)===null||l===void 0?void 0:l.totaller)===null||e===void 0?void 0:e.id;for(const[t,l]of Object.entries(((s=(d=(n=i===null||i===void 0?void 0:i.detail)===null||n===void 0?void 0:n.data)===null||d===void 0?void 0:d.totaller)===null||s===void 0?void 0:s.paths)||{})){if(!this.paths[o])this.paths[o]={};this.paths[o][t]=l;if(this.groupBy===t)this.fetchTotals(o,l);if(!this.options.includes(t))this.options.push(t)}this.options=[...this.options];this.paths={...this.paths}}else if(((v=i===null||i===void 0?void 0:i.detail)===null||v===void 0?void 0:v.endpoint)==="findTotals"){const o=(u=(h=(r=(a=i===null||i===void 0?void 0:i.detail)===null||a===void 0?void 0:a.event)===null||r===void 0?void 0:r.detail)===null||h===void 0?void 0:h.params)===null||u===void 0?void 0:u.totallerId;this.totals={...this.totals,[o]:(f=(c=i===null||i===void 0?void 0:i.detail)===null||c===void 0?void 0:c.data)===null||f===void 0?void 0:f.totals}}}async fetchTotals(i,o,t){this.fireenjinFetch.emit({endpoint:"findTotals",params:{totallerId:i,path:this.renderPathTemplate(i,o,t)}})}async onChange(i){var o,t,l;if(((o=i===null||i===void 0?void 0:i.target)===null||o===void 0?void 0:o.name)==="groupBy"){this.groupBy=(t=i===null||i===void 0?void 0:i.target)===null||t===void 0?void 0:t.value}for(const o of this.totallerIds){const t=new Date(Date.parse(i.target.value));t.setHours(24);this.fetchTotals(o,this.paths[o][this.groupBy],((l=i===null||i===void 0?void 0:i.target)===null||l===void 0?void 0:l.name)==="timeframe"?t:this.timeframe)}}renderPathTemplate(i,o,t){return l(o,{totaller:{id:i},data:{createdAt:t||new Date}})}render(){return[t("floodteam-title-bar",null,t("fireenjin-select",{style:{display:"none"},ref:i=>this.selectEl=i,label:"View By",labelPosition:"stacked",name:"groupBy",value:this.groupBy,options:(this.options||[]).map((i=>({label:i,value:i})))}),t("fireenjin-chip-bar",null,t("ion-chip",{onClick:()=>this.selectEl.querySelector("ion-select").click()},this.groupBy,t("ion-icon",{name:"chevron-down-circle"})),t("ion-chip",null,t("fireenjin-input",{"clear-on-edit":true,name:"timeframe",type:"date",value:this.timeframe})))),(this.totallerIds||[]).map((i=>{var o;return t("floodteam-totaller-cards",{totals:(o=this.totals)===null||o===void 0?void 0:o[i],totallerId:i})}))]}static get watchers(){return{groupBy:["onSuccess"]}}};export{e as floodteam_totaller_card_list};
//# sourceMappingURL=p-21a0fff6.entry.js.map