import{r as i,d as o,f as t,B as l,h as d}from"./p-03169580.js";import{r as s}from"./p-ef308962.js";import"./p-82ae0260.js";import"./p-80de33dc.js";import"./p-3775d1fc.js";import"./p-c2fbed0d.js";import"./p-5717491f.js";const n="floodteam-total-graph fireenjin-graph{display:block;margin:0 auto;width:75%}@media only screen and (max-width: 1050px ){floodteam-total-graph fireenjin-graph{width:95%}}";let r=class{constructor(t){i(this,t);this.fireenjinFetch=o(this,"fireenjinFetch",7);this.sumKeyToIndex={};this.type="bar";this.labels=[];this.dataSets=[];this.groupBy="month";this.options=[];this.paths={};this.totals={};this.sumKeys=[]}ongroupByChanged(){t(this.fetchTotaller())}async onSuccess(i){var o,t,l,d,s,n,r,a,h,v,e,u,p,c,f,m,g,j,b;if(i.detail.endpoint==="findTotaller"){this.totaller=((t=(o=i===null||i===void 0?void 0:i.detail)===null||o===void 0?void 0:o.data)===null||t===void 0?void 0:t.totaller)||null;this.sumKeys=Object.keys(((l=this.totaller)===null||l===void 0?void 0:l.sums)||{});this.dataSets=Object.values(((d=this.totaller)===null||d===void 0?void 0:d.sums)||{}).map(((i,o)=>{this.sumKeyToIndex[i===null||i===void 0?void 0:i.id]=o;return{label:(i===null||i===void 0?void 0:i.name)||(i===null||i===void 0?void 0:i.id),data:[],borderColor:(i===null||i===void 0?void 0:i.color)||this.randomColor(),backgroundColor:(i===null||i===void 0?void 0:i.color)||this.randomColor()}}));const e=(r=(n=(s=i===null||i===void 0?void 0:i.detail)===null||s===void 0?void 0:s.data)===null||n===void 0?void 0:n.totaller)===null||r===void 0?void 0:r.id;for(const[o,t]of Object.entries(((v=(h=(a=i===null||i===void 0?void 0:i.detail)===null||a===void 0?void 0:a.data)===null||h===void 0?void 0:h.totaller)===null||v===void 0?void 0:v.paths)||{})){if(!this.paths[e])this.paths[e]={};this.paths[e][o]=t;if(this.groupBy===o)this.fetchTotals(e,t);if(!this.options.includes(o))this.options.push(o)}this.options=[...this.options];this.paths={...this.paths}}else if(((e=i===null||i===void 0?void 0:i.detail)===null||e===void 0?void 0:e.endpoint)==="listTotals"){console.log(i.detail);const o=[];for(const t of((p=(u=i===null||i===void 0?void 0:i.detail)===null||u===void 0?void 0:u.data)===null||p===void 0?void 0:p.totals)||[]){o.push(t===null||t===void 0?void 0:t.id);this.sumKeys.map((i=>{this.dataSets[this.sumKeyToIndex[i]].data.push(t[i]||0)}))}this.labels=o;const t=(g=(m=(f=(c=i===null||i===void 0?void 0:i.detail)===null||c===void 0?void 0:c.event)===null||f===void 0?void 0:f.detail)===null||m===void 0?void 0:m.params)===null||g===void 0?void 0:g.totallerId;this.totals={...this.totals,[t]:(b=(j=i===null||i===void 0?void 0:i.detail)===null||j===void 0?void 0:j.data)===null||b===void 0?void 0:b.totals}}}randomNumber(){return Math.random()*10}randomColor(){return"#"+Math.floor(Math.random()*16777215).toString(16)}renderPathTemplate(i,o,t){return s(o,{totaller:{id:i},data:{createdAt:t||new Date}})}async fetchTotaller(){this.fireenjinFetch.emit({endpoint:"findTotaller",params:{id:this.totallerId}})}async fetchTotals(i,o,t){let l=this.renderPathTemplate(i,o,t);const d=l.split("/");d.pop();l=d.join("/");this.fireenjinFetch.emit({endpoint:"listTotals",params:{totallerId:i,path:l}})}async componentDidLoad(){if(!(l===null||l===void 0?void 0:l.isBrowser))return;this.fetchTotaller()}render(){return d("fireenjin-graph",{type:this.type,labels:this.labels,datasets:this.dataSets})}static get watchers(){return{groupBy:["ongroupByChanged"]}}};r.style=n;export{r as floodteam_total_graph};
//# sourceMappingURL=p-dfcea7b0.entry.js.map