/*! maintenance_supporter frontend 2.95.0 */ import{a as W}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-APJICCRG.js";import{a as o}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-XSFV5MUM.js";import{f as T,g as K,h as z,i as M,j as Y,k as Q,l as U,m as q,n as R,o as E,p as G}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-YKVD2DJ5.js";import{a as A}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-E7KPGZZO.js";import{e as F,f as I}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-S7ZP4PVX.js";import"/maintenance_supporter_panelfiles/panel-chunks/chunk-ODPGZXCU.js";import{b as P}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-JEWIFUZC.js";import"/maintenance_supporter_panelfiles/panel-chunks/chunk-UVBHIULM.js";import"/maintenance_supporter_panelfiles/panel-chunks/chunk-WUMSAU4G.js";import{B as $,C as g,F as O,G as S,J as w,L as N,a as b,c as p,f as y,h as B,l as v,m as k,n as C,q as D,s as a,u as H,y as L}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-4XNVTWGC.js";function X(_,r,t,s){let d=_.entries.filter(e=>e.type==="completed").sort((e,i)=>e.ts-i.ts),l=`${_.from?t.date(_.from):"\u2026"} \u2013 ${_.to?t.date(_.to):"\u2026"}`,n=_.totals,h=[[r.completions,t.number(n.completions)],[r.totalCost,t.cost(n.totalCost)],[r.avgCost,n.avgCost!=null?t.cost(n.avgCost):r.none],[r.totalTime,n.totalDuration?t.duration(n.totalDuration):r.none]].map(([e,i])=>`
${o(e)}
${o(i)}
`).join(""),c=_.byObject.map(e=>` ${o(e.objectName)} ${o(t.number(e.completions))} ${o(t.cost(e.cost))} ${o(t.share(e.share))} `).join(""),m=_.buckets.buckets.reduce((e,i)=>Math.max(e,i.cost),0),f=_.buckets.buckets.map(e=>{let i=m>0?Math.round(e.cost/m*100):0;return` ${o(t.bucket(e))} ${o(t.number(e.completions))} ${i>0?``:""} ${o(t.cost(e.cost))} `}).join(""),j=d.map(e=>{let i=[e.notes,e.completedBy?`${r.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(r.none)} ${e.duration!=null?o(t.duration(e.duration)):o(r.none)} ${o(i)||o(r.none)} `}).join(` `);return` ${o(r.title)} \u2014 ${o(_.areaName)}

${o(r.title)} \u2014 ${o(_.areaName)}

${o(r.period)}: ${o(l)} \xB7 ${o(r.generated)} ${o(t.date(s))}

${h}

${o(r.costPerObject)}

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

${o(r.costPerBucket)}

${f||``}
${o(r.period)}${o(r.completions)} ${o(r.colCost)}
${o(r.none)}

${o(r.historyHeading)} (${o(t.number(d.length))})

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

${o(r.capNote)}

`:""} `}var J=25,Z=5,V={completed:C.ok,missed:C.overdue,reset:C.paused,skipped:"var(--secondary-text-color)"},u=class extends B{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 W(this);this._localeReady=!1;this._filtersFor=null;this._memo=null}createRenderRoot(){return this}get _lang(){return L(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(d=>d.tasks.map(l=>({entryId:d.entry_id,task:l})));this._histories.sync(this.hass,s)}}updated(t){super.updated(t),!this._localeReady&&this.hass&&(this._localeReady=!0,H(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((l,n)=>l===s[n]))return this._memo.entries;let d=M(t,(l,n)=>this._histories.historyOf(l,n));return this._memo={deps:s,entries:d},d}_figures(){let t=this._areaObjects(),s=this._entries(t),d={from:this._from||null,to:this._to||null},l=Y(s,{...d,entryId:this._entryFilter||null,taskQuery:this._taskQuery}),n=this._entryFilter?t.filter(h=>h.entry_id===this._entryFilter):t;return{objects:t,entries:s,filtered:l,totals:Q(l),buckets:q(l,d),byObject:U(l,n)}}_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):`${N(t.month,this._lang,s)} ${t.year}`}_countText(t,s,d){let l=this._lang;return d===1?a(s,l):a(t,l).replace("{n}",$(d,l))}async _print(){if(this._printing)return;let t=I();this._printing=!0;try{await this._histories.settled()}finally{this._printing=!1}let s=this._lang,d=this.currencySymbol,{filtered:l,totals:n,buckets:h,byObject:c}=this._figures(),m={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"},f=l.filter(i=>i.type==="completed"),j=l.map(i=>({...i,completedBy:i.completedBy?this.userName(i.completedBy):null,notes:i.notes?A(i.notes,s):null})),e=X({areaName:T(this.areaKey,this.hass?.areas,a("no_area",s)),from:this._from||f[f.length-1]?.timestamp||null,to:this._to||P(new Date),totals:n,byObject:c,buckets:h,entries:j,capped:this._histories.capped},m,{date:i=>O(i,s),cost:i=>g(i,d,s),duration:i=>w(i,s),bucket:i=>this._bucketLabel(i,"long"),share:i=>`${$(i*100,s,0)} %`,number:i=>$(i,s)},new Date().toISOString());F(e,t)}_renderRangeChips(t){let s=this._lang,d=new Date,l=R(d),n=c=>this._from===c.from&&this._to===c.to,h=G(t,d.getFullYear()).slice(0,Z);return p`
${h.map(c=>p` `)}
`}_renderChart(t){let s=this._lang,d=this.currencySymbol,l=t.reduce((c,m)=>Math.max(c,m.cost),0);if(l<=0)return p`

${a("area_no_costs",s)}

`;let n=Math.max(1,Math.ceil(t.length/12)),h=t.map((c,m)=>({b:c,i:m})).filter(({i:c})=>c%n===0);return p`
${g(l,d,s)}
${t.map(c=>{let m=`${this._bucketLabel(c,"long")}: ${g(c.cost,d,s)} \xB7 ${a("area_kpi_completions",s)}: ${$(c.completions,s)}`;return p`
${c.cost>0?p`
`:y}
`})}
${h.map(({b:c,i:m})=>p`${c.month==null?String(c.year):p`${N(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:d,entries:l,filtered:n,totals:h,buckets:c,byObject:m}=this._figures(),f=d.reduce((e,i)=>e+i.tasks.filter(x=>this.showArchived||!x.archived).length,0),j=this._expanded?n:n.slice(0,J);return p`

${T(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",d.length)} · ${this._countText("templates_task_count","templates_task_count_one",f)} ${this._histories.loading?p` · ${a("loading",t)}`:y}

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

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

${this._renderChart(c.buckets)}

${a("area_cost_per_object",t)}

${m.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} ${$(e.completions,t)} ${g(e.cost,s,t)} ${$(e.share*100,t,0)} %

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

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

${a("object_history_empty",t)}

`:p`
${j.map(e=>{let i=e.notes?A(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)}
${O(e.timestamp,t)} ${a(e.type,t)} ${e.cost!=null?g(e.cost,s,t):"\u2014"} ${e.duration!=null?w(e.duration,t):"\u2014"} ${i||"\u2014"}
${n.length>j.length?p`{this._expanded=!0}}> ${a("show_all",t)} (${$(n.length,t)}) `:y} `} ${this._histories.capped?p`

${a("object_history_cap_note",t)}

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