import"./chunks/chunk-LO2NM3CE.js";var A="maintenance-supporter",I=`ll-strategy-dashboard-${A}`,L="hui-maintenance-supporter-strategy-editor",P="NOT_RUNNING",G=[{status:"overdue",title:"Overdue",icon:"mdi:alert-circle",path:"overdue"},{status:"triggered",title:"Triggered",icon:"mdi:flash",path:"triggered"},{status:"due_soon",title:"Due Soon",icon:"mdi:clock-alert-outline",path:"due-soon"},{status:"ok",title:"OK",icon:"mdi:check-circle-outline",path:"ok"}],C=[{title:"Overdue",icon:"mdi:alert-circle",path:"overdue",filter:{filter_due_max_days:-1},matches:i=>i<=-1},{title:"Today",icon:"mdi:calendar-today",path:"today",filter:{filter_due_min_days:0,filter_due_max_days:0},matches:i=>i===0},{title:"This Week",icon:"mdi:calendar-week",path:"this-week",filter:{filter_due_min_days:1,filter_due_max_days:7},matches:i=>i>=1&&i<=7},{title:"This Month",icon:"mdi:calendar-month",path:"this-month",filter:{filter_due_min_days:8,filter_due_max_days:30},matches:i=>i>=8&&i<=30},{title:"Later",icon:"mdi:calendar-clock",path:"later",filter:{filter_due_min_days:31},matches:i=>i>=31}];function u(i){return{type:"grid",cards:[i]}}var H={condition:"view_columns",min:2};function V(i={}){let n=e=>i[e]||`sensor.maintenance_supporter_${e}`;return{type:"markdown",text_only:!0,content:[`\u{1F534} **{{ states('${n("overdue")}') }}** overdue`,`\u26A1 **{{ states('${n("triggered")}') }}** triggered`,`\u{1F7E1} **{{ states('${n("due_soon")}') }}** due soon`,`\u{1F7E2} **{{ states('${n("ok")}') }}** ok`].join(" \xB7 ")}}function N(){return{title:"Maintenance",type:"panel",cards:[{type:"empty-state",icon:"mdi:wrench-clock",icon_color:"primary",content_only:!0,title:"No maintenance objects yet",content:"Open the Maintenance panel to add your first object \u2014 pool pump, HVAC filter, vehicle, anything that needs scheduled care.",buttons:[{icon:"mdi:wrench",text:"Open Maintenance panel",appearance:"filled",variant:"brand",tap_action:{action:"navigate",navigation_path:"/maintenance-supporter"}},{icon:"mdi:plus",text:"Add object",appearance:"outlined",variant:"brand",tap_action:{action:"fire-dom-event",ll_custom:{type:"maintenance-supporter:add-object"}}}]}]}}function B(i={}){let n=V(i);return{title:"Overview",icon:"mdi:wrench-clock",path:"overview",type:"sections",header:{layout:"responsive",card:n},sidebar:{sections:[{type:"grid",cards:[{type:"heading",heading:"Status",heading_style:"title"},n]}],visibility:[H],content_label:"Tasks",sidebar_label:"Status"},sections:[u({type:"custom:maintenance-supporter-card",show_header:!1,filter_status:["overdue","triggered","due_soon"]})]}}function $(i,n){let e=new Map;for(let r of i){let a=r.object.area_id||null;e.has(a)||e.set(a,[]),e.get(a).push(r)}let s=Array.from(e.keys()).filter(r=>r!==null);s.sort((r,a)=>{let c=n[r]?.name||r,d=n[a]?.name||a;return c.localeCompare(d)});let t=[];for(let r of s){let a=e.get(r);if(a.length===0)continue;let c=n[r];t.push({title:c?.name||r,icon:c?.icon||"mdi:floor-plan",path:`area-${r}`,type:"sections",sections:[u({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:a.map(d=>d.object.name)})]})}let o=e.get(null);return o&&o.length>0&&t.push({title:"Unassigned",icon:"mdi:help-circle-outline",path:"unassigned",type:"sections",sections:[u({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:o.map(r=>r.object.name)})]}),t}function U(i){let n=new Set;for(let s of i)for(let t of s.tasks||[])t.status&&n.add(t.status);let e=[];for(let s of G)n.has(s.status)&&e.push({title:s.title,icon:s.icon,path:s.path,type:"sections",sections:[u({type:"custom:maintenance-supporter-card",show_header:!1,filter_status:[s.status]})]});return e}function W(i,n,e){let s=new Map;for(let a of i){let c=a.object.area_id,d=c&&n[c]?.floor_id||null;s.has(d)||s.set(d,[]),s.get(d).push(a)}let t=Array.from(s.keys()).filter(a=>a!==null);t.sort((a,c)=>{let d=e[a],g=e[c],l=d?.level??0,p=g?.level??0;return l!==p?l-p:(d?.name||a).localeCompare(g?.name||c)});let o=[];for(let a of t){let c=s.get(a);if(c.length===0)continue;let d=e[a];o.push({title:d?.name||a,icon:d?.icon||"mdi:home-floor-1",path:`floor-${a}`,type:"sections",sections:[u({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:c.map(g=>g.object.name)})]})}let r=s.get(null);return r&&r.length>0&&o.push({title:"Other",icon:"mdi:help-circle-outline",path:"other",type:"sections",sections:[u({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:r.map(a=>a.object.name)})]}),o}function Y(i){return[{title:"Week",icon:"mdi:calendar-week",path:"cal-7",window_days:7},{title:"Fortnight",icon:"mdi:calendar-week-begin",path:"cal-14",window_days:14},{title:"Month",icon:"mdi:calendar-month",path:"cal-30",window_days:30},{title:"Year",icon:"mdi:calendar-clock",path:"cal-365",window_days:365}].map(e=>({title: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 F(i){let n=new Set;for(let s of i)for(let t of s.tasks||[]){let o=t.days_until_due;o!=null&&C.forEach((r,a)=>{r.matches(o)&&n.add(a)})}let e=[];return C.forEach((s,t)=>{n.has(t)&&e.push({title:s.title,icon:s.icon,path:s.path,type:"sections",sections:[u({type:"custom:maintenance-supporter-card",show_header:!1,...s.filter})]})}),e}var E=class extends HTMLElement{static getCreateSuggestions(n){return{title:"Maintenance Supporter",icon:"mdi:wrench-clock"}}static async getConfigElement(){return document.createElement(L)}static async generate(n,e){if(e.config?.state===P)return{views:[{type:"sections",sections:[{cards:[{type:"starting"}]}]}]};if(e.config?.recovery_mode)return{views:[{type:"sections",sections:[{cards:[{type:"recovery-mode"}]}]}]};let s;try{s=await e.connection.sendMessagePromise({type:"maintenance_supporter/objects"})}catch{return{title:"Maintenance",views:[{title:"Maintenance",cards:[{type:"markdown",content:"**Maintenance Supporter** is not loaded. Install/enable the integration first."}]}]}}let t=s.objects||[];if(t.length===0)return{title:"Maintenance",views:[N()]};let o=n?.group_by??"area",r={area:()=>$(t,e.areas||{}),status:()=>U(t),floor:()=>W(t,e.areas||{},e.floors||{}),due_date:()=>F(t),calendar:()=>Y(t)},a={};try{a=(await e.connection.sendMessagePromise({type:"maintenance_supporter/statistics"})).summary_entity_ids||{}}catch{}return{title:"Maintenance",views:[B(a),...(r[o]??r.area)()]}}},q=[{value:"area",label:"By area (default)"},{value:"status",label:"By status (Overdue / Triggered / Due Soon / OK)"},{value:"floor",label:"By floor (uses HA floors)"},{value:"due_date",label:"By due date (Overdue / Today / Week / Month / Later)"},{value:"calendar",label:"Rolling calendar (Week / Fortnight / Month / Year)"}],h=class extends HTMLElement{constructor(){super(...arguments);this._config={type:"custom:maintenance-supporter"}}set hass(e){this._hass=e}setConfig(e){this._config=e,this._render()}connectedCallback(){this._render()}_render(){let e=this._config.group_by??"area",s=q.map(o=>``).join("");this.innerHTML=`