/*! maintenance_supporter frontend 2.95.0 */ import{j as O}from"./chunks/chunk-4JW6SHXP.js";import{c as j,d as p,g as A,i as L}from"./chunks/chunk-3MSNNIFG.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=>A(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 z={condition:"view_columns",min:2};function _(t,r,e){let s=r[t];if(s)return`{{ states('${s}') }}`;let n=e[t];return n==null?"\u2014":String(n)}function Q(t={},r={}){return{type:"markdown",text_only:!0,content:[`\u{1F534} **${_("overdue",t,r)}** ${c("overdue")}`,`\u26A1 **${_("triggered",t,r)}** ${c("triggered")}`,`\u{1F7E1} **${_("due_soon",t,r)}** ${c("due_soon")}`,`\u{1F7E2} **${_("ok",t,r)}** ${c("ok")}`].join(" \xB7 ")}}function X(){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={},r={}){let e=Q(t,r);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:[z],content_label:c("tasks"),sidebar_label:c("strat_status")},sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_status:[...j]})]}}function Z(t,r){let e=new Map;for(let i of t){let a=i.object.area_id||null;e.has(a)||e.set(a,[]),e.get(a).push(i)}let s=Array.from(e.keys()).filter(i=>i!==null);s.sort((i,a)=>{let d=r[i]?.name||i,u=r[a]?.name||a;return d.localeCompare(u)});let n=[];for(let i of s){let a=e.get(i);if(a.length===0)continue;let d=r[i];n.push({title:d?.name||i,icon:d?.icon||"mdi:floor-plan",path:`area-${i}`,type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:a.map(u=>u.object.name)})]})}let o=e.get(null);return o&&o.length>0&&n.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(i=>i.object.name)})]}),n}function ee(t){let r=new Set;for(let s of t)for(let n of s.tasks||[])n.status&&r.add(n.status);let e=[];for(let s of q)r.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,r,e){let s=new Map;for(let a of t){let d=a.object.area_id,u=d&&r[d]?.floor_id||null;s.has(u)||s.set(u,[]),s.get(u).push(a)}let n=Array.from(s.keys()).filter(a=>a!==null);n.sort((a,d)=>{let u=e[a],y=e[d],M=u?.level??0,R=y?.level??0;return M!==R?M-R:(u?.name||a).localeCompare(y?.name||d)});let o=[];for(let a of n){let d=s.get(a);if(d.length===0)continue;let u=e[a];o.push({title:u?.name||a,icon:u?.icon||"mdi:home-floor-1",path:`floor-${a}`,type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:d.map(y=>y.object.name)})]})}let i=s.get(null);return i&&i.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:i.map(a=>a.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 r=new Set;for(let s of t)for(let n of s.tasks||[]){let o=n.days_until_due;o!=null&&x.forEach((i,a)=>{i.matches(o)&&r.add(a)})}let e=[];return x.forEach((s,n)=>{r.has(n)&&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(r){return{title:"Maintenance Supporter",icon:"mdi:wrench-clock"}}static async getConfigElement(){return document.createElement(B)}static async generate(r,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 n=s.objects||[];if(n.length===0)return{title:c("maintenance"),views:[X()]};let o=r?.group_by??"area",i={area:()=>Z(n,e.areas||{}),status:()=>ee(n),floor:()=>te(n,e.areas||{},e.floors||{}),due_date:()=>re(n),calendar:()=>ne(n)},a={},d={};try{let u=await e.connection.sendMessagePromise({type:"maintenance_supporter/statistics"});a=u.summary_entity_ids||{},d={overdue:u.overdue,triggered:u.triggered,due_soon:u.due_soon,ok:u.ok}}catch{}return{title:c("maintenance"),views:[J(a,d),...(i[o]??i.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,r=>`${r.charCodeAt(0)};`)}var T=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=`