/*! maintenance_supporter frontend 2.98.0 */ import{a as X}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-WH65ZHYZ.js";import{a as o}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-DY5FF6TM.js";import{f as E,g as M,h as z,i as Q,j as U,k as Y,l as q,m as G,n as R,o as A,p as W}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-S7XZBRRU.js";import{a as B}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-GGO5IKKD.js";import{e as P,f as K}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-DLWOWMV7.js";import"/maintenance_supporter_panelfiles/panel-chunks/chunk-4PKMHUVO.js";import"/maintenance_supporter_panelfiles/panel-chunks/chunk-NEWWPCTD.js";import"/maintenance_supporter_panelfiles/panel-chunks/chunk-QKEXGIRG.js";import"/maintenance_supporter_panelfiles/panel-chunks/chunk-OUHDI2FL.js";import{B as S,H as F,K as g,L as v,O as N,P as I,T as w,V as T,a as $,c as p,f as y,h as H,l as k,m as j,n as C,q as D,s as a,u as L,y as O}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-27MZ7YLE.js";function J(b,i,t,s){let l=b.entries.filter(e=>e.type==="completed").sort((e,n)=>e.ts-n.ts),d=`${b.from?t.date(b.from):"\u2026"} \u2013 ${b.to?t.date(b.to):"\u2026"}`,r=b.totals,h=[[i.completions,t.number(r.completions)],[i.totalCost,t.cost(r.totalCost)],[i.avgCost,r.avgCost!=null?t.cost(r.avgCost):i.none],[i.totalTime,r.totalDuration?t.duration(r.totalDuration):i.none]].map(([e,n])=>`
${o(e)}
${o(n)}
`).join(""),u=b.byObject.map(e=>` ${o(e.objectName)} ${o(t.number(e.completions))} ${o(t.cost(e.cost))} ${o(t.share(e.share))} `).join(""),f=b.buckets.buckets.reduce((e,n)=>Math.max(e,n.cost),0),c=b.buckets.buckets.map(e=>{let n=f>0?Math.round(e.cost/f*100):0;return` ${o(t.bucket(e))} ${o(t.number(e.completions))} ${n>0?``:""} ${o(t.cost(e.cost))} `}).join(""),m=l.map(e=>{let n=[e.notes,e.completedBy?`${i.completedBy}: ${e.completedBy}`:null].filter(Boolean).join(" \xB7 "),x=e.phaseName?`${e.taskName} \xB7 ${e.phaseName}`:e.taskName;return` ${o(t.date(e.timestamp))} ${o(e.objectName)} ${o(x)} ${e.cost!=null?o(t.cost(e.cost)):o(i.none)} ${e.duration!=null?o(t.duration(e.duration)):o(i.none)} ${o(n)||o(i.none)} `}).join(` `);return` ${o(i.title)} \u2014 ${o(b.areaName)}

${o(i.title)} \u2014 ${o(b.areaName)}

${o(i.period)}: ${o(d)} \xB7 ${o(i.generated)} ${o(t.date(s))}

${h}

${o(i.costPerObject)}

${u||``}
${o(i.colObject)}${o(i.completions)} ${o(i.colCost)}${o(i.share)}
${o(i.none)}
${o(i.totalCost)}${o(t.number(r.completions))} ${o(t.cost(r.totalCost))}

${o(i.costPerBucket)}

${c||``}
${o(i.period)}${o(i.completions)} ${o(i.colCost)}
${o(i.none)}

${o(i.historyHeading)} (${o(t.number(l.length))})

${m||``}
${o(i.colDate)}${o(i.colObject)}${o(i.colTask)} ${o(i.colCost)}${o(i.colDuration)}${o(i.colNotes)}
${o(i.none)}
${o(i.totalCost)} ${o(t.cost(r.totalCost))} ${r.totalDuration?o(t.duration(r.totalDuration)):""}
${b.capped?`

${o(i.capNote)}

`:""} `}var Z=25,V=5,tt={completed:C.ok,missed:C.overdue,reset:C.paused,skipped:"var(--secondary-text-color)"},_=class extends H{constructor(){super(...arguments);this.areaKey="";this.objects=[];this.showArchived=!1;this.currencySymbol="";this.userName=()=>null;this._from="";this._to="";this._entryFilter="";this._taskQuery="";this._expanded=!1;this._printing=!1;this._histories=new X(this);this._localeReady=!1;this._filtersFor=null;this._memo=null}createRenderRoot(){return this}get _lang(){return F(this.hass)}willUpdate(t){if(super.willUpdate(t),t.has("areaKey")&&this._filtersFor!==this.areaKey){this._filtersFor=this.areaKey;let s=R();this._from=s.from,this._to=s.to,this._entryFilter="",this._taskQuery="",this._expanded=!1}if(t.has("objects")||t.has("areaKey")||t.has("showArchived")||t.has("hass")&&t.get("hass")===void 0){let s=this._areaObjects().flatMap(l=>l.tasks.map(d=>({entryId:l.entry_id,task:d})));this._histories.sync(this.hass,s)}}updated(t){super.updated(t),!this._localeReady&&this.hass&&(this._localeReady=!0,L(this._lang).then(()=>this.requestUpdate()))}_areaObjects(){return z(this.objects,this.areaKey,this.showArchived).sort((t,s)=>t.object.name.localeCompare(s.object.name))}_entries(t){let s=[this.objects,this.areaKey,this.showArchived,this._histories.version];if(this._memo&&this._memo.deps.every((d,r)=>d===s[r]))return this._memo.entries;let l=Q(t,(d,r)=>this._histories.historyOf(d,r));return this._memo={deps:s,entries:l},l}_figures(){let t=this._areaObjects(),s=this._entries(t),l={from:this._from||null,to:this._to||null},d=U(s,{...l,entryId:this._entryFilter||null,taskQuery:this._taskQuery}),r=this._entryFilter?t.filter(h=>h.entry_id===this._entryFilter):t;return{objects:t,entries:s,filtered:d,totals:Y(d),buckets:G(d,l),byObject:q(d,r)}}_setRange(t){this._from=t.from,this._to=t.to,this._expanded=!1}_openObject(t){this.dispatchEvent(new CustomEvent("open-object",{detail:{entryId:t},bubbles:!0,composed:!0}))}_openTask(t,s){this.dispatchEvent(new CustomEvent("open-task",{detail:{entryId:t,taskId:s},bubbles:!0,composed:!0}))}_bucketLabel(t,s){return t.month==null?String(t.year):`${T(t.month,this._lang,s)} ${t.year}`}_countText(t,s,l){let d=this._lang;return l===1?a(s,d):a(t,d).replace("{n}",g(l,d))}async _print(){if(this._printing)return;let t=K();this._printing=!0;try{await this._histories.settled()}finally{this._printing=!1}let s=this._lang,l=this.currencySymbol,{filtered:d,totals:r,buckets:h,byObject:u}=this._figures(),f={title:a("area_report_title",s),generated:a("report_generated",s),period:a("area_report_period",s),completions:a("area_kpi_completions",s),totalCost:a("total_cost",s),avgCost:a("avg_cost",s),totalTime:a("area_kpi_total_time",s),costPerObject:a("area_cost_per_object",s),costPerBucket:h.unit==="month"?a("area_cost_per_month",s):a("area_cost_per_year",s),share:a("area_cost_share",s),historyHeading:a("area_history_section",s),colDate:a("date",s),colObject:a("object",s),colTask:a("task_name",s),colCost:a("cost",s),colDuration:a("duration",s),colNotes:a("notes_label",s),completedBy:a("completed_by",s),capNote:a("object_history_cap_note",s),none:"\u2014"},c=d.filter(n=>n.type==="completed"),m=d.map(n=>({...n,completedBy:n.completedBy?this.userName(n.completedBy):null,notes:n.notes?B(n.notes,s):null})),e=J({areaName:E(this.areaKey,this.hass?.areas,a("no_area",s)),from:this._from||S(c[c.length-1]?.timestamp)||null,to:this._to||O(),totals:r,byObject:u,buckets:h,entries:m,capped:this._histories.capped},f,{date:n=>N(n,s),cost:n=>v(n,l,s),duration:n=>w(n,s),bucket:n=>this._bucketLabel(n,"long"),share:n=>`${g(n*100,s,0)} %`,number:n=>g(n,s)},new Date().toISOString());P(e,t)}_renderRangeChips(t){let s=this._lang,l=O(),d=R(l),r=u=>this._from===u.from&&this._to===u.to,h=W(t,Number(l.slice(0,4))).slice(0,V);return p`
${h.map(u=>p` `)}
`}_renderChart(t){let s=this._lang,l=this.currencySymbol,d=t.reduce((c,m)=>Math.max(c,m.cost),0),r=t.reduce((c,m)=>Math.min(c,m.cost),0);if(d<=0&&r>=0)return p`

${a("area_no_costs",s)}

`;let h=c=>Math.round(c/(d-r)*1e3)/10,u=Math.max(1,Math.ceil(t.length/12)),f=t.map((c,m)=>({b:c,i:m})).filter(({i:c})=>c%u===0);return p`
${v(d,l,s)}
${r<0?p`
`:y} ${t.map(c=>{let m=`${this._bucketLabel(c,"long")}: ${v(c.cost,l,s)} \xB7 ${a("area_kpi_completions",s)}: ${g(c.completions,s)}`,e=c.cost<0?h(c.cost-r):h(-r);return p`
${c.cost!==0?p`
`:y}
`})}
${r<0?p`
${v(r,l,s)}
`:y}
${f.map(({b:c,i:m})=>p`${c.month==null?String(c.year):p`${T(c.month,s,"short")}${c.month===0||m===0?p`
${c.year}`:y}`}
`)}
`}render(){if(!this.hass||!this.areaKey)return y;let t=this._lang,s=this.currencySymbol,{objects:l,entries:d,filtered:r,totals:h,buckets:u,byObject:f}=this._figures(),c=l.reduce((e,n)=>e+n.tasks.filter(x=>this.showArchived||!x.archived).length,0),m=this._expanded?r:r.slice(0,Z);return p`

${E(this.areaKey,this.hass.areas,a("no_area",t))}

this._print()}> ${this._printing?a("loading",t):a("area_report_print",t)}

${this._countText("area_object_count","area_object_count_one",l.length)} · ${this._countText("templates_task_count","templates_task_count_one",c)} ${this._histories.loading?p` · ${a("loading",t)}`:y}

${this._renderRangeChips(d)}
{this._from=e.detail.value}} > {this._to=e.detail.value}} > {this._taskQuery=e.target.value}} />
${a("area_kpi_completions",t)}
${g(h.completions,t)}
${a("total_cost",t)}
${v(h.totalCost,s,t)}
${a("avg_cost",t)}
${h.avgCost!=null?v(h.avgCost,s,t):"\u2014"}
${a("area_kpi_total_time",t)}
${h.totalDuration?w(h.totalDuration,t):"\u2014"}

${u.unit==="month"?a("area_cost_per_month",t):a("area_cost_per_year",t)}

${this._renderChart(u.buckets)}

${a("area_cost_per_object",t)}

${f.map(e=>p` this._openObject(e.entryId)}> `)}
${a("object",t)} ${a("area_kpi_completions",t)} ${a("cost",t)} ${a("area_cost_share",t)}
${e.objectName} ${g(e.completions,t)} ${v(e.cost,s,t)} ${g(e.share*100,t,0)} %

${a("area_history_section",t)} ${g(r.length,t)}

${r.length===0?p`

${a("object_history_empty",t)}

`:p`
${m.map(e=>{let n=e.notes?B(e.notes,t):"";return p` this._openTask(e.entryId,e.taskId)}> `})}
${a("date",t)} ${a("object",t)} ${a("task_name",t)} ${a("cost",t)} ${a("duration",t)} ${a("notes_label",t)}
${N(e.timestamp,t)} ${a(e.type,t)} ${e.cost!=null?v(e.cost,s,t):"\u2014"} ${e.duration!=null?w(e.duration,t):"\u2014"} ${n||"\u2014"}
${r.length>m.length?p`{this._expanded=!0}}> ${a("show_all",t)} (${g(r.length,t)}) `:y} `} ${this._histories.capped?p`

${a("object_history_cap_note",t)}

`:y}
`}};$([k({attribute:!1})],_.prototype,"hass",2),$([k()],_.prototype,"areaKey",2),$([k({attribute:!1})],_.prototype,"objects",2),$([k({type:Boolean})],_.prototype,"showArchived",2),$([k()],_.prototype,"currencySymbol",2),$([k({attribute:!1})],_.prototype,"userName",2),$([j()],_.prototype,"_from",2),$([j()],_.prototype,"_to",2),$([j()],_.prototype,"_entryFilter",2),$([j()],_.prototype,"_taskQuery",2),$([j()],_.prototype,"_expanded",2),$([j()],_.prototype,"_printing",2);customElements.get("maintenance-area-view")||customElements.define("maintenance-area-view",_);export{_ as MaintenanceAreaView};