{console.log(e)})}renderShowAll(){if(!this.show_all&&this.entities.find(i=>i.is_disabled_by_default))return C``}render(){function i(n,o){return n.reduce(function(r,a){return(r.get(a[o])||(()=>{let c=[];return r.set(a[o],c),c})()).push(a),r},new Map)}const t=this.show_all?this.entities:this.entities.filter(n=>!n.is_disabled_by_default),e=i(t,"entity_category"),s=Array.from(e,([n,o])=>({name:n,value:o}));return C`${s.map(n=>C`
${n.value.map((o,r)=>C`
${o.icon?C``:R}
${o.name}
${this.has_controls&&o.has_action?this.control(o):C`
${o.state}
`}
${o.domain==="sensor"?C`
`:R}
`)}
`)} ${this.renderShowAll()}
`}static get styles(){return[ji,en,ra,aa,Bi]}_handleEntityRowClick(i){var t,e;((t=i==null?void 0:i.currentTarget)==null?void 0:t.domain)==="sensor"&&((i==null?void 0:i.ctrlKey)||i.stopPropagation(),(e=i==null?void 0:i.currentTarget)==null||e.classList.toggle("expanded",i.ctrlKey?!0:void 0))}};lt.ENTITY_UNDEFINED="States";lt.ENTITY_CATEGORIES=["Sensor and Control","Configuration","Diagnostic"];Pi([ft()],lt.prototype,"entities",2);Pi([ft()],lt.prototype,"has_controls",2);Pi([ft()],lt.prototype,"show_all",2);lt=Pi([Wt("esp-entity-table")],lt);class bu{exec(t){if(!this[t]||typeof this[t]!="function"){console.log(`ActionRenderer.${t} is not callable`);return}return this[t]()}_actionButton(t,e,s){if(!t)return;let n=s||e.toLowerCase();return C``}_switch(t){return C`{var n;let s="turn_"+e.detail.state;(n=this.actioner)==null||n.restAction(t,s.toLowerCase())}}">`}_select(t,e,s,n,o){return C``}_range(t,e,s,n,o,r,a){return C` {var h,d;const l=(h=c.target)==null?void 0:h.value;(d=this.actioner)==null||d.restAction(t,`${e}?${s}=${l}`)}}">
`}_textinput(t,e,s,n,o,r,a){return C`{var h,d;const l=(h=c.target)==null?void 0:h.value;(d=this.actioner)==null||d.restAction(t,`${e}?${s}=${encodeURIComponent(l)}`)}}">`}_datetime(t,e,s,n){let o="";return n.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?$/)?o="datetime-local":n.match(/^\d{4}-\d{2}-\d{2}$/)?o="date":n.match(/^\d{2}:\d{2}(:\d{2})?$/)&&(o="time"),console.log("type"),console.log(o),C`{var c,l;const a=(c=r.target)==null?void 0:c.value;(l=this.actioner)==null||l.restAction(t,`${e}?${s}=${a}`)}}">`}_colorpicker(t,e,s){function n(r){return Number(r).toString(16).padStart(2,"0")}function o(r){var c;const a=((c=r.match(/[0-9a-f]{2}/gi))==null?void 0:c.map(l=>parseInt(l,16)))||[0,0,0];return`r=${a[0]}&g=${a[1]}&b=${a[2]}`}return C`{var c,l;const a=(c=r.target)==null?void 0:c.value;(l=this.actioner)==null||l.restAction(t,`${e}?${o(a)}`)}}">
`}render_binary_sensor(){var e;if(!this.entity)return;const t=this.entity.state==Rr;return C``}render_switch(){if(!!this.entity)return this.entity.assumed_state?C`${this._actionButton(this.entity,"\u274C","turn_off")} ${this._actionButton(this.entity,"\u2714\uFE0F","turn_on")}`:this._switch(this.entity)}render_fan(){if(!!this.entity)return[this.entity.speed," ",this.entity.speed_level,this._switch(this.entity),this.entity.speed_count?this._range(this.entity,`turn_${this.entity.state.toLowerCase()}`,"speed_level",this.entity.speed_level?this.entity.speed_level:0,0,this.entity.speed_count,1):""]}render_light(){var t,e;if(!!this.entity)return[C`${this._switch(this.entity)} ${this.entity.brightness?this._range(this.entity,"turn_on","brightness",this.entity.brightness,0,255,1):""} ${this.entity.color_mode==="rgb"||this.entity.color_mode==="rgbw"?this._colorpicker(this.entity,"turn_on",(t=this.entity)==null?void 0:t.color):""} ${((e=this.entity.effects)==null?void 0:e.filter(s=>s!="None").length)?this._select(this.entity,"turn_on","effect",this.entity.effects||[],this.entity.effect):""}
`]}render_lock(){if(!!this.entity)return C`${this._actionButton(this.entity,"\u{1F510}","lock")} ${this._actionButton(this.entity,"\u{1F513}","unlock")} ${this._actionButton(this.entity,"\u2191","open")}`}render_cover(){if(!!this.entity)return C`${this._actionButton(this.entity,"\u2191","open")} ${this._actionButton(this.entity,"\u2610","stop")} ${this._actionButton(this.entity,"\u2193","close")}`}render_button(){if(!!this.entity)return C`${this._actionButton(this.entity,"PRESS","press")}`}render_select(){if(!!this.entity)return this._select(this.entity,"set","option",this.entity.option||[],this.entity.value)}render_number(){if(!!this.entity)return C`${this._range(this.entity,"set","value",this.entity.value,this.entity.min_value,this.entity.max_value,this.entity.step)} ${this.entity.uom}`}render_datetime(){if(!!this.entity)return C`${this._datetime(this.entity,"set","value",this.entity.value)} ${this.entity.uom}`}render_text(){if(!!this.entity)return this._textinput(this.entity,"set","value",this.entity.value,this.entity.min_length,this.entity.max_length,this.entity.pattern)}render_climate(){if(!this.entity)return;let t,e;this.entity.target_temperature_low!==void 0&&this.entity.target_temperature_high!==void 0?(e=C`${this.entity.target_temperature_low} .. ${this.entity.target_temperature_high}`,t=C`${this._range(this.entity,"set","target_temperature_low",this.entity.target_temperature_low,this.entity.min_temp,this.entity.max_temp,this.entity.step)} ${this._range(this.entity,"set","target_temperature_high",this.entity.target_temperature_high,this.entity.min_temp,this.entity.max_temp,this.entity.step)}`):(e=C`${this.entity.target_temperature}`,t=C`${this._range(this.entity,"set","target_temperature",this.entity.target_temperature,this.entity.min_temp,this.entity.max_temp,this.entity.step)}`);let s=C``;return(this.entity.modes?this.entity.modes.length:0)>0&&(s=C`Mode:
${this._select(this.entity,"set","mode",this.entity.modes||[],this.entity.mode||"")}`),C` ${t} ${s}`}}var _u=Object.defineProperty,yu=Object.getOwnPropertyDescriptor,$i=(i,t,e,s)=>{for(var n=s>1?void 0:s?yu(t,e):t,o=i.length-1,r;o>=0;o--)(r=i[o])&&(n=(s?r(t,e,n):r(n))||n);return s&&n&&_u(t,e,n),n};let Re=class extends J{constructor(){super();this.rows=10,this.scheme="",this.logs=[]}connectedCallback(){var i;super.connectedCallback(),(i=window.source)==null||i.addEventListener("log",t=>{const s=t.data;let o=s.slice(10,s.length-4).split(":").slice(0,2).join(":"),r=s.slice(12+o.length,s.length-4);const c={type:{"[1;31m":"e","[0;33m":"w","[0;32m":"i","[0;35m":"c","[0;36m":"d","[0;37m":"v"}[s.slice(0,7)],level:s.slice(7,10),tag:o,detail:r,when:new Date().toTimeString().split(" ")[0]};this.logs.push(c),this.logs=this.logs.slice(-this.rows)})}render(){return C`${this.logs.map(i=>C`
${i.when}
${i.level}
${i.tag}
${i.detail}
`)}
`}static get styles(){return[Bi,it`.tbody .trow:nth-child(2n),.thead{background-color:rgba(127,127,127,.05)}.trow div{font-family:monospace;width:100%;line-height:1.2rem}.trow{display:flex}.thead{line-height:1rem}.thead .trow{text-align:left;padding:.25rem .5rem}.trow{display:flex}.trow>div{align-self:flex-start;padding-right:.25em;flex:2 0;overflow:hidden;text-overflow:ellipsis}.trow>div:nth-child(2){flex:1 0}.trow>div:nth-child(3){flex:3 0}.trow>div:last-child{flex:15 0;padding-right:0}pre{margin:0}.v{color:#888}.d{color:#0dd}.c{color:#ff00ff}.i{color:#32cd32}.w{color:#ff0}.e{color:red;font-weight:700}.logs[color-scheme=light]{font-weight:700}.logs[color-scheme=light] .w{color:#cc0}.logs[color-scheme=dark] .d{color:#0aa}.logs{overflow-x:auto;border-radius:12px;border-width:1px;border-style:solid;border-color:rgba(127,127,127,.12);transition:all .3s ease-out 0s;font-size:14px;padding:16px}@media (max-width:1024px){.trow>div:nth-child(2){display:none!important}}`]}};$i([st({type:Number})],Re.prototype,"rows",2);$i([st({type:String})],Re.prototype,"scheme",2);$i([ft()],Re.prototype,"logs",2);Re=$i([Wt("esp-log")],Re);var xu=Object.defineProperty,vu=Object.getOwnPropertyDescriptor,Zt=(i,t,e,s)=>{for(var n=s>1?void 0:s?vu(t,e):t,o=i.length-1,r;o>=0;o--)(r=i[o])&&(n=(s?r(t,e,n):r(n))||n);return s&&n&&xu(t,e,n),n};const zr="checkbox-lever";let Lt=class extends J{constructor(){super(...arguments);this.checkbox=null,this.stateOn=Rr,this.stateOff=Fr,this.state=Fr,this.color="currentColor",this.disabled=!1}firstUpdated(i){var t;this.checkbox=(t=this.shadowRoot)==null?void 0:t.getElementById(zr)}isOn(){return this.state===this.stateOn}toggle(i){const t=this.isOn()?this.stateOff:this.stateOn;let e=new CustomEvent("state",{detail:{state:t,id:this.id}});this.dispatchEvent(e)}render(){return C``}static get styles(){return[ji,it`.sw,.sw *{-webkit-tap-highlight-color:transparent;user-select:none;cursor:pointer}input[type=checkbox]{opacity:0;width:0;height:0}input[type=checkbox]:checked+.lever{background-color:currentColor;background-image:linear-gradient(0deg,rgba(255,255,255,.5) 0,rgba(255,255,255,.5) 100%)}input[type=checkbox]:checked+.lever:after,input[type=checkbox]:checked+.lever:before{left:18px}input[type=checkbox]:checked+.lever:after{background-color:currentColor}input[type=checkbox]:not(:checked)+.lever:after{background-color:rgba(127,127,127,.5)}.lever{content:"";display:inline-block;position:relative;width:36px;height:14px;background-image:linear-gradient(0deg,rgba(127,127,127,.5) 0,rgba(127,127,127,.5) 100%);background-color:inherit;border-radius:15px;transition:background .3s ease;vertical-align:middle}.lever:after,.lever:before{content:"";position:absolute;display:inline-block;width:20px;height:20px;border-radius:50%;left:0;top:-3px;transition:left .3s ease,background .3s ease,box-shadow .1s ease,transform .1s ease}.lever:before{background-color:currentColor;background-image:linear-gradient(0deg,rgba(255,255,255,.9) 0,rgba(255,255,255,.9) 100%)}.lever:after{background-color:#f1f1f1;box-shadow:0 3px 1px -2px rgba(0,0,0,.2),0 2px 2px 0 rgba(0,0,0,.14),0 1px 5px 0 rgba(0,0,0,.12)}input[type=checkbox]:checked:not(:disabled).tabbed:focus~.lever::before,input[type=checkbox]:checked:not(:disabled)~.lever:active::before{transform:scale(2.4);background-color:rgba(255,255,255,.9) 0;background-image:linear-gradient(0deg,rgba(255,255,255,.9) 0,rgba(255,255,255,.9) 100%)}input[type=checkbox]:not(:disabled).tabbed:focus~.lever::before,input[type=checkbox]:not(:disabled)~.lever:active:before{transform:scale(2.4);background-color:rgba(0,0,0,.08)}input[type=checkbox][disabled]+.lever{cursor:default;background-color:rgba(0,0,0,.12)}input[type=checkbox][disabled]+.lever:after,input[type=checkbox][disabled]:checked+.lever:after{background-color:#949494}`]}};Zt([st({type:String})],Lt.prototype,"stateOn",2);Zt([st({type:String})],Lt.prototype,"stateOff",2);Zt([st({type:String})],Lt.prototype,"state",2);Zt([st({type:String})],Lt.prototype,"color",2);Zt([st({type:Boolean})],Lt.prototype,"disabled",2);Lt=Zt([Wt("esp-switch")],Lt);var wu='',ku=Object.defineProperty,Su=Object.getOwnPropertyDescriptor,Mu=(i,t,e,s)=>{for(var n=s>1?void 0:s?Su(t,e):t,o=i.length-1,r;o>=0;o--)(r=i[o])&&(n=(s?r(t,e,n):r(n))||n);return s&&n&&ku(t,e,n),n};let Nr=class extends J{render(){return Kr([wu])}};Nr=Mu([Wt("esp-logo")],Nr);var Ou=it`.flex-grid-half{display:grid;grid-template-columns:500px 2fr}.flex-grid-half.expanded_entity,.flex-grid-half.expanded_logs{grid-template-columns:1fr}.flex-grid-half .col{margin:8px}.flex-grid-half .col:nth-child(2){overflow:hidden}.flex-grid-half.expanded_logs .col:nth-child(1){display:none}.flex-grid-half.expanded_entity .col:nth-child(2){display:none}@media (max-width:1024px){.flex-grid,.flex-grid-half{display:block}.flex-grid-half .col{width:100%!important;margin:0 0 10px 0!important;display:block!important}}*{box-sizing:border-box}.flex-grid{margin:0 0 20px 0}h1{text-align:center;width:100%;line-height:1.1em;margin-block:.25em}header div{text-align:center;width:100%}header #logo,header iconify-icon{float:right;font-size:2.5rem;color:rgba(127,127,127,.5)}header #logo{float:left;color:rgba(127,127,127,.5)}esp-logo{float:left;line-height:1em;font-size:initial}form{display:flex;justify-content:space-between;background-color:rgba(127,127,127,.05);border-radius:12px;border-width:1px;border-style:solid;border-color:rgba(127,127,127,.12)}form .btn{margin-right:0}`,Cu=Object.defineProperty,Au=Object.getOwnPropertyDescriptor,Jt=(i,t,e,s)=>{for(var n=s>1?void 0:s?Au(t,e):t,o=i.length-1,r;o>=0;o--)(r=i[o])&&(n=(s?r(t,e,n):r(n))||n);return s&&n&&Cu(t,e,n),n};window.source=new EventSource(Rs()+"/events");function Pu(i){const t=Math.sign(i);if(i===0)return new Intl.RelativeTimeFormat("en").format(0,"second");const e=[{type:"year",seconds:12*30*24*60*60*1e3},{type:"month",seconds:30*24*60*60*1e3},{type:"week",seconds:7*24*60*60*1e3},{type:"day",seconds:24*60*60*1e3},{type:"hour",seconds:60*60*1e3},{type:"minute",seconds:60*1e3},{type:"second",seconds:1e3}];let s="";const n=new Intl.RelativeTimeFormat("en");let o=0;for(let r of e){const a=Math.trunc(Math.abs(i/r.seconds));if(a>0){const c=n.format(a*t,r.type);if(i-=a*r.seconds*t,s+=o===0&&r.type!="second"?c.replace(" ago"," "):c,o++>=1)break}}return s}let Rt=class extends J{constructor(){super();this.scheme="",this.ping=0,this.connected=!0,this.lastUpdate=0,this.version="2.0.5",this.config={ota:!1,log:!0,title:"",comment:""},this.darkQuery=window.matchMedia("(prefers-color-scheme: dark)"),this.frames=[{},{color:"red",transform:"scale(1.25)"},{}];const i=document.querySelector("script#config");i&&this.setConfig(JSON.parse(i.innerText))}setConfig(i){"log"in i||(i.log=this.config.log),this.config=i,document.title=i.title,document.documentElement.lang=i.lang}firstUpdated(i){super.firstUpdated(i),document.getElementsByTagName("head")[0].innerHTML+='';const t=document.querySelector("link[rel~='icon']");t.href='data:image/svg+xml,',this.scheme=this.schemeDefault(),window.source.addEventListener("ping",e=>{var s;((s=e.data)==null?void 0:s.length)&&(this.setConfig(JSON.parse(e.data)),this.requestUpdate()),this._updateUptime(e),this.lastUpdate=Date.now()}),window.source.addEventListener("log",e=>{this._updateUptime(e),this.lastUpdate=Date.now()}),window.source.addEventListener("state",e=>{this.lastUpdate=Date.now()}),window.source.addEventListener("error",e=>{console.dir(e),this.connected=!1,this.requestUpdate()}),setInterval(()=>{this.connected=!!this.ping&&Date.now()-this.lastUpdate<15e3},5e3)}schemeDefault(){return this.darkQuery.matches?"dark":"light"}updated(i){super.updated(i),i.has("scheme")&&document.documentElement.style.setProperty("color-scheme",this.scheme),i.has("ping")&&this.ping&&this.beat.animate(this.frames,1e3)}uptime(){return`${Pu(-this.ping|0)}`}renderOta(){if(this.config.ota){let i=Rs();return C``}}renderLog(){return this.config.log?C``:R}renderTitle(){return C`${this.config.title||C` `}
${[this.config.comment,`started ${this.uptime()}`].filter(i=>i).map(i=>`${i}`).join(" \xB7 ")}
`}render(){return C`${this.renderLog()}`}_handleDblClick(i){var t,e,s,n,o,r;(s=(t=i.currentTarget)==null?void 0:t.parentNode)==null||s.classList.toggle("expanded_entity",((e=i.currentTarget)==null?void 0:e.id)==="col_entities"?void 0:!1),(r=(n=i.currentTarget)==null?void 0:n.parentNode)==null||r.classList.toggle("expanded_logs",((o=i.currentTarget)==null?void 0:o.id)==="col_logs"?void 0:!1)}_updateUptime(i){i.lastEventId&&(this.ping=parseInt(i.lastEventId),this.connected=!0,this.requestUpdate())}static get styles(){return[ji,en,Ou,Bi]}};Jt([ft()],Rt.prototype,"scheme",2);Jt([ft()],Rt.prototype,"ping",2);Jt([ft()],Rt.prototype,"connected",2);Jt([ft()],Rt.prototype,"lastUpdate",2);Jt([oa("#beat")],Rt.prototype,"beat",2);Rt=Jt([Wt("esp-app")],Rt);