/*! phoscon-app 2025-10-13 */

export const getMigrationGroupView=()=>{const MigrationGroupItemView=Backbone.View.extend({tagName:"li",className:"migrationGroup",template:_.template($("#migration-group-item-template").html()),events:{click:"onClicked"},initialize:function(){this.$el.html(this.template(this.model)),this.listenTo(this.model,"delete remove",this.remove),this.checked_svg=this.el.querySelector(".checked-icon"),this.selected=!1},onClicked:function(){this.selected=!this.selected,this.check(),verifyUpdateRoomCreate()},check:function(){this.checked_svg.innerHTML='<use transform="scale(1.0)" xlink:href="#" />',this.selected&&(this.checked_svg.innerHTML='<use transform="scale(0.7)" xlink:href="#check-icon" />',document.querySelector("#update1-next-btn").innerHTML=translate("text_next")),app.migrationGroupView.checkIcon()},render:function(){return this},remove:function(){this.el=""}}),MigrationGroupListView=Backbone.View.extend({el:"#migrationGroupList",initialize:function(){this.views=[],this.remove()},render:function(){this.views=[],restGetResource(app.groups).then(()=>{restGetResource(app.resourcelinks).then(()=>{app.resourcelinks.forEach(roomLink=>{if("migration room"==roomLink.attributes.name){let buRoomLinks=roomLink.attributes.links;roomLink.attributes.links.forEach(groupLink=>{let group=app.groups.get(groupLink.split("/")[2]);if(void 0!=group){if("Phoscon_All_Off"!=group.get("name")&&"Luminaire"!=group.get("type")&&"Room"!==group.get("type")){var view=new MigrationGroupItemView({model:group});this.views.push(view)}}else buRoomLinks.pop(buRoomLinks.indexOf(groupLink)),restUpdateResource(roomLink,{links:buRoomLinks})}),this.el.innerHTML="";let trans=translate("text_no_groups");0===this.views.length?this.el.innerHTML='<div><p style="display:flex; align-items: center; justify-content: center;">'+trans+"</p></div>":this.views.forEach(view=>{this.el.appendChild(view.render().el)})}})}).then(()=>{this.checkButton()})})},checkButton:function(){restGetResource(app.resourcelinks).then(()=>{app.resourcelinks.forEach(link=>{"migration room"==link.attributes.name&&(0!==link.attributes.links.length?document.getElementById("showUpdateAssistant").classList="dashboard-btn-top btn":document.getElementById("showUpdateAssistant").classList="hidden")})})},remove:function(model){let view=this.views.find(view=>view.model==model);view&&(view.remove(),this.views=this.views.filter(v=>v!=view))},toggleall:function(){let allset=!0;this.views.forEach(view=>{!1===view.selected&&(allset=!1)}),this.views.forEach(view=>{this.setselected(view,!allset)}),verifyUpdateRoomCreate()},setselected:function(view,setstate){view.selected=setstate,view.check()},checkIcon:function(){let allset=!0,anyset=!1;document.querySelector("#update1-next-btn").innerHTML=translate("skip"),this.views.forEach(view=>{!1===view.selected?allset=!1:(anyset=!0,document.querySelector("#update1-next-btn").innerHTML=translate("text_next"))})}}),MigrationGroupListView2=Backbone.View.extend({el:"#migrationGroupList2",initialize:function(){this.views=[],this.remove()},render:function(){this.views=[],restGetResource(app.groups).then(()=>{restGetResource(app.resourcelinks).then(()=>{app.resourcelinks.forEach(roomLink=>{if("migration room"==roomLink.attributes.name){let buRoomLinks=roomLink.attributes.links;roomLink.attributes.links.forEach(groupLink=>{let group=app.groups.get(groupLink.split("/")[2]);if(void 0!=group){if("Phoscon_All_Off"!=group.get("name")&&"Luminaire"!=group.get("type")&&"Room"!==group.get("type")){var view=new MigrationGroupItemView({model:group});this.views.push(view)}}else buRoomLinks.pop(buRoomLinks.indexOf(groupLink)),restUpdateResource(roomLink,{links:buRoomLinks})}),this.el.innerHTML="";let trans=translate("text_no_groups");0===this.views.length?this.el.innerHTML='<div><p style="display:flex; align-items: center; justify-content: center;">'+trans+"</p></div>":this.views.forEach(view=>{this.el.appendChild(view.render().el)})}})}).then(()=>{this.checkButton()})})},checkButton:function(){restGetResource(app.resourcelinks).then(()=>{app.resourcelinks.forEach(link=>{"migration room"==link.attributes.name&&(0!==link.attributes.links.length?document.getElementById("showUpdateAssistant").classList="dashboard-btn-top btn":document.getElementById("showUpdateAssistant").classList="hidden")})})},remove:function(model){let view=this.views.find(view=>view.model==model);view&&(view.remove(),this.views=this.views.filter(v=>v!=view))},toggleall:function(){let allset=!0;this.views.forEach(view=>{!1===view.selected&&(allset=!1)}),this.views.forEach(view=>{this.setselected(view,!allset)}),verifyUpdateRoomCreate()},setselected:function(view,setstate){view.selected=setstate,view.check()},checkIcon:function(){let allset=!0;this.views.forEach(view=>{!1===view.selected&&(allset=!1)})}});return[new MigrationGroupListView,new MigrationGroupListView2]};