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

"use strict";function bbInitGroups(){let pollBusy=!1,pollQueue=[],pollTimer=null;function processPoll(){if(pollTimer=null,pollBusy||0===pollQueue.length)return;pollBusy=!0;let r=pollQueue.shift();pollQueue.length>3&&(console.log("poll /groups instead",pollQueue.length,"single requests"),pollQueue=[],r=app.groups),restGetResource(r).catch(console.log).then(()=>{pollBusy=!1,pollQueue.length>0&&(pollTimer=setTimeout(processPoll,50))})}app.api.on("event",function(e){if("groups"===e.r)if("added"!==e.e){if("changed"===e.e){var g=app.groups.get(e.id);if(g){e.name&&g.set({name:e.name}),pollQueue.push(g),pollTimer||(pollTimer=setTimeout(processPoll,5e3));var args={};_.map(e,function(val,key){if(g.has(key)){if("state"===key){var mod=!1,state=g.attributes.state;return _.map(val,function(val2,key2){state[key2]!==val2&&(state[key2]=val2,mod=!0)}),void(mod&&(g.unset("state",{silent:!0}),g.set({state:state})))}if("action"===key){mod=!1;var action=g.attributes.action;return _.map(val,function(val2,key2){action[key2]!==val2&&(action[key2]=val2,mod=!0)}),void(mod&&(g.unset("action",{silent:!0}),g.set({action:action})))}g.get(key)!==val&&(args[key]=val)}}),g.set(args)}}}else app.groups.fetch()});var Group=Backbone.Model.extend({initialize:function(){},sync:function(method,model,options){return"patch"===method&&(method="update"),Backbone.sync(method,model,options)}});app.GroupCollection=Backbone.Collection.extend({name:"groups",model:Group,url:"//"+app.session.gw+"/api/"+app.apikey+"/groups",parse:function(response){return _.map(response,(group,gid)=>(group.id=gid,group.devicemembership=group.devicemembership||[],group.scenes=group.scenes||[],app.resourcelinks&&app.resourcelinks.some(rl=>{let links=rl.get("links"),classid=rl.get("classid"),groupPath="/groups/"+gid;if(6e3===classid&&rl.get("name")==="room "+gid)return group.type="Room",!0;links.includes(groupPath)&&(9e3===classid?group.type="LightGroup":9001===classid?group.type="BlindGroup":9002===classid&&(group.type="ThermostatGroup"))}),group))}}),app.groups=new app.GroupCollection;var cache=sessionStorage.getItem("app.groups");cache&&app.groups.reset(JSON.parse(cache)),app.groups.on("add",function(group,collection){}),app.groups.on("change",function(group,options){})}