/*! phoscon-app 2024-10-07 */

export function initOverview(injectSwitchWizzardSvg,pageParams){let tableView;pageParams.constants.svgPathsBlinds;const OverviewView=Backbone.View.extend({el:"#overview",template:_.template(document.getElementById("blind-overview-template").innerHTML),initialize:function(){this.el.innerHTML=this.template(),tableView=new TableView},show:function(){this.el.classList.remove("hide")},hide:function(){this.el.classList.add("hide")}}),EmptyView=Backbone.View.extend({el:".empty-div",template:_.template(document.getElementById("blind-empty-template").innerHTML),initialize:function(){this.el.innerHTML=this.template()},show:function(){this.el.classList.remove("hide")},hide:function(){this.el.classList.add("hide")}}),TableView=Backbone.View.extend({el:"#switchTable",collection:app.blinds,initialize:function(){this.views=[],this.listenTo(this.collection,"add",this.addOne),this.listenTo(this.collection,"remove",this.removeOne),app.blinds.forEach(this.addOne,this)},addOne:function(model){var view=new TableRowView({model:model});this.$el.append(view.render().el),this.views.push(view)},removeOne:function(model){let views=this.views.filter(v=>v.model.get("id")!==model.get("id"));this.views=views}}),TableRowView=Backbone.View.extend({tagName:"tr",template:_.template($("#blind-item-template").html()),initialize:function(){this.model.on("change",this.render,this),this.model.on("destroy",this.remove,this),this.model.set("product",getDeviceProductName(this.model.attributes));var html=this.template(this.model.attributes);this.$el.html(html),this.$el.attr("data-bid",this.model.id),this.nameLabel=this.el.querySelector("td:nth-child(2)"),this.vendorLabel=this.el.querySelector("td:nth-child(3)"),this.productLabel=this.el.querySelector("td:nth-child(4)"),this.stateLabel=this.el.querySelector("td:nth-child(5)"),this.lightModel=app.lights.get(this.model.id);let iconImg=this.el.querySelector(".item-icon");iconImg.setAttribute("src","img/blinds/48px/blind-icon.svg#generic-blind-icon"),injectSwitchWizzardSvg([iconImg]),this.service=null,this.render()},events:{"click .open-detail":function(){app.router.navigate("blind/"+this.model.id,{trigger:!0})}},render:function(){console.log("render blind "+this.model.get("id")),this.model.get("reachable")?this.el.classList.remove("not-reachable"):this.el.classList.add("not-reachable");const name=this.model.get("name");this.nameLabel&&this.nameLabel.textContent!==name&&(this.nameLabel.textContent=name);const vendor=this.model.get("vendor")||this.model.get("manufacturername");this.vendorLabel&&this.vendorLabel.textContent!==vendor&&(this.vendorLabel.textContent=vendor);const product=this.model.get("product");this.productLabel&&this.productLabel.textContent!==product&&(this.productLabel.textContent=product);var val=(100*this.model.get("state").bri/254).toFixed(0);return"NaN"===val?val="":val+="% "+translate("txt_close"),this.stateLabel&&this.stateLabel.textContent!==val&&(this.stateLabel.textContent=val),this}});return{overview:new OverviewView,emptyview:new EmptyView,tableView:tableView}};