/*! maintenance_supporter frontend 2.96.0 */ import{j as O}from"./chunks/chunk-XOYZSKDM.js";import{c as A,d as p,g as j,i as L}from"./chunks/chunk-RGIYRWN4.js";var Y={maintenance:"Maintenance",overview:"Overview",overdue:"Overdue",triggered:"Triggered",due_soon:"Due Soon",ok:"OK",today:"Today",today_this_week:"This week",unassigned:"Unassigned",tasks:"Tasks",strat_this_month:"This Month",strat_later:"Later",strat_week:"Week",strat_fortnight:"Fortnight",strat_month:"Month",strat_year:"Year",strat_other:"Other",strat_status:"Status",strat_empty_title:"No maintenance objects yet",strat_empty_content:"Open the Maintenance panel to add your first object \u2014 pool pump, HVAC filter, vehicle, anything that needs scheduled care.",strat_open_panel:"Open Maintenance panel",strat_add_object:"Add object",strat_not_loaded:"**Maintenance Supporter** is not loaded. Install/enable the integration first.",strat_group_by:"Group views by",strat_group_area:"By area (default)",strat_group_status:"By status (Overdue / Triggered / Due Soon / OK)",strat_group_floor:"By floor (uses HA floors)",strat_group_due_date:"By due date (Overdue / Today / Week / Month / Later)",strat_group_calendar:"Rolling calendar (Week / Fortnight / Month / Year)",strat_editor_help:'The "Overview" view is always first. Empty groups are skipped.'},h="en",c=t=>j(t,h,Y[t]);async function $(t){h=t?.language||"en",await L(h)}var V="maintenance-supporter",W=`ll-strategy-dashboard-${V}`,B="hui-maintenance-supporter-strategy-editor",F="NOT_RUNNING",q=[{status:"overdue",title:"overdue",icon:p.overdue,path:"overdue"},{status:"triggered",title:"triggered",icon:p.triggered,path:"triggered"},{status:"due_soon",title:"due_soon",icon:p.due_soon,path:"due-soon"},{status:"ok",title:"ok",icon:p.ok,path:"ok"}],x=[{title:"overdue",icon:p.overdue,path:"overdue",filter:{filter_due_max_days:-1},matches:t=>t<=-1},{title:"today",icon:"mdi:calendar-today",path:"today",filter:{filter_due_min_days:0,filter_due_max_days:0},matches:t=>t===0},{title:"today_this_week",icon:"mdi:calendar-week",path:"this-week",filter:{filter_due_min_days:1,filter_due_max_days:7},matches:t=>t>=1&&t<=7},{title:"strat_this_month",icon:"mdi:calendar-month",path:"this-month",filter:{filter_due_min_days:8,filter_due_max_days:30},matches:t=>t>=8&&t<=30},{title:"strat_later",icon:"mdi:calendar-clock",path:"later",filter:{filter_due_min_days:31},matches:t=>t>=31}];function l(t){return{type:"grid",cards:[t]}}var X={condition:"view_columns",min:2};function _(t,n,e){let s=n[t];if(s)return`{{ states('${s}') }}`;let r=e[t];return r==null?"\u2014":String(r)}function z(t={},n={}){return{type:"markdown",text_only:!0,content:[`\u{1F534} **${_("overdue",t,n)}** ${c("overdue")}`,`\u26A1 **${_("triggered",t,n)}** ${c("triggered")}`,`\u{1F7E1} **${_("due_soon",t,n)}** ${c("due_soon")}`,`\u{1F7E2} **${_("ok",t,n)}** ${c("ok")}`].join(" \xB7 ")}}function Q(){return{title:c("maintenance"),type:"panel",cards:[{type:"empty-state",icon:"mdi:wrench-clock",icon_color:"primary",content_only:!0,title:c("strat_empty_title"),content:c("strat_empty_content"),buttons:[{icon:"mdi:wrench",text:c("strat_open_panel"),appearance:"filled",variant:"brand",tap_action:{action:"navigate",navigation_path:"/maintenance-supporter"}},{icon:"mdi:plus",text:c("strat_add_object"),appearance:"outlined",variant:"brand",tap_action:{action:"fire-dom-event",ll_custom:{type:"maintenance-supporter:add-object"}}}]}]}}function J(t={},n={}){let e=z(t,n);return{title:c("overview"),icon:"mdi:wrench-clock",path:"overview",type:"sections",header:{layout:"responsive",card:e},sidebar:{sections:[{type:"grid",cards:[{type:"heading",heading:c("strat_status"),heading_style:"title"},e]}],visibility:[X],content_label:c("tasks"),sidebar_label:c("strat_status")},sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_status:[...A]})]}}function Z(t,n){let e=new Map;for(let a of t){let i=a.object.area_id||null;e.has(i)||e.set(i,[]),e.get(i).push(a)}let s=Array.from(e.keys()).filter(a=>a!==null);s.sort((a,i)=>{let u=n[a]?.name||a,d=n[i]?.name||i;return u.localeCompare(d)});let r=[];for(let a of s){let i=e.get(a);if(i.length===0)continue;let u=n[a];r.push({title:u?.name||a,icon:u?.icon||"mdi:floor-plan",path:`area-${a}`,type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:i.map(d=>d.object.name)})]})}let o=e.get(null);return o&&o.length>0&&r.push({title:c("unassigned"),icon:"mdi:help-circle-outline",path:"unassigned",type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:o.map(a=>a.object.name)})]}),r}function ee(t){let n=new Set;for(let s of t)for(let r of s.tasks||[])r.status&&n.add(r.status);let e=[];for(let s of q)n.has(s.status)&&e.push({title:c(s.title),icon:s.icon,path:s.path,type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_status:[s.status]})]});return e}function te(t,n,e){let s=new Map;for(let i of t){let u=i.object.area_id,d=u&&n[u]?.floor_id||null;s.has(d)||s.set(d,[]),s.get(d).push(i)}let r=Array.from(s.keys()).filter(i=>i!==null);r.sort((i,u)=>{let d=e[i],y=e[u],M=d?.level??0,R=y?.level??0;return M!==R?M-R:(d?.name||i).localeCompare(y?.name||u)});let o=[];for(let i of r){let u=s.get(i);if(u.length===0)continue;let d=e[i];o.push({title:d?.name||i,icon:d?.icon||"mdi:home-floor-1",path:`floor-${i}`,type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:u.map(y=>y.object.name)})]})}let a=s.get(null);return a&&a.length>0&&o.push({title:c("strat_other"),icon:"mdi:help-circle-outline",path:"other",type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:a.map(i=>i.object.name)})]}),o}function ne(t){return[{title:"strat_week",icon:"mdi:calendar-week",path:"cal-7",window_days:7},{title:"strat_fortnight",icon:"mdi:calendar-week-begin",path:"cal-14",window_days:14},{title:"strat_month",icon:"mdi:calendar-month",path:"cal-30",window_days:30},{title:"strat_year",icon:"mdi:calendar-clock",path:"cal-365",window_days:365}].map(e=>({title:c(e.title),icon:e.icon,path:e.path,type:"panel",cards:[{type:"custom:maintenance-supporter-calendar-card",window_days:e.window_days,show_window_chips:!1,show_user_filter:!0}]}))}function re(t){let n=new Set;for(let s of t)for(let r of s.tasks||[]){let o=r.days_until_due;o!=null&&x.forEach((a,i)=>{a.matches(o)&&n.add(i)})}let e=[];return x.forEach((s,r)=>{n.has(r)&&e.push({title:c(s.title),icon:s.icon,path:s.path,type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,...s.filter})]})}),e}var I=class extends HTMLElement{static getCreateSuggestions(n){return{title:"Maintenance Supporter",icon:"mdi:wrench-clock"}}static async getConfigElement(){return document.createElement(B)}static async generate(n,e){if(e.config?.state===F)return{views:[{type:"sections",sections:[{cards:[{type:"starting"}]}]}]};if(e.config?.recovery_mode)return{views:[{type:"sections",sections:[{cards:[{type:"recovery-mode"}]}]}]};await $(e);let s;try{s=await e.connection.sendMessagePromise({type:"maintenance_supporter/objects"})}catch{return{title:c("maintenance"),views:[{title:c("maintenance"),cards:[{type:"markdown",content:c("strat_not_loaded")}]}]}}let r=s.objects||[];if(r.length===0)return{title:c("maintenance"),views:[Q()]};let o=n?.group_by??"area",a={area:()=>Z(r,e.areas||{}),status:()=>ee(r),floor:()=>te(r,e.areas||{},e.floors||{}),due_date:()=>re(r),calendar:()=>ne(r)},i={},u={};try{let d=await e.connection.sendMessagePromise({type:"maintenance_supporter/statistics"});i=d.summary_entity_ids||{},u={overdue:d.overdue,triggered:d.triggered,due_soon:d.due_soon,ok:d.ok}}catch{}return{title:c("maintenance"),views:[J(i,u),...(a[o]??a.area)()]}}},se=[{value:"area",label:"strat_group_area"},{value:"status",label:"strat_group_status"},{value:"floor",label:"strat_group_floor"},{value:"due_date",label:"strat_group_due_date"},{value:"calendar",label:"strat_group_calendar"}];function k(t){return t.replace(/[&<>"']/g,n=>`${n.charCodeAt(0)};`)}var E=class extends HTMLElement{constructor(){super(...arguments);this._config={type:"custom:maintenance-supporter"}}set hass(e){let s=(e?.language||"en")!==h;this._hass=e,s&&$(e).then(()=>this._render())}setConfig(e){this._config=e,this._render()}connectedCallback(){this._render()}_render(){let e=this._config.group_by??"area",s=se.map(o=>``).join("");this.innerHTML=`