(()=>{function e(t,n,c,e){var i=5,a=i;function s(){l(null,i)}function l(e,n){t.searchDone=!1,t.searchProgress=!0,t.devices.length=0,a=i;e=e?e.text:"";(e?c.searchIncludingChildDevices({text:e,pageSize:n}):c.list({pageSize:n})).then(o).then(r).finally(function(){t.searchDone=!0,t.searchProgress=!1})}function r(e){return t.paging.next&&e.length<a?t.paging.next().then(o).then(r):n.when()}function o(e){var n=_.uniqBy((t.selectedDevices||[]).concat(t.devices||[]).concat(e),"id"),c=(t.devices=n,!!t.paging&&t.paging.loading);return t.paging=e.paging,t.paging.loading=c,n}function g(){t.selectedDevices.splice(0,t.selectedDevices.length)}t.devices=[],t.selectedDevices=[];t.placeholder=e("Device's name or value of any device's property"),t.search=l,t.loadNext=function(){a+=i,t.paging.loading=!0,t.paging.next().then(o).then(r).finally(function(){t.paging.loading=!1})},t.clearSearch=function(){t.devices.length=0,t.selectedDevices.length=0,t.searchDone=!1,t.searchProgress=!1,t.searchData=t.searchData||{},t.searchData.text="",s()},t.selectAll=function c(e,n){n||g(),_.forEach(e,function(e){var n;n=e,_.find(t.disabledDevices,function(e){return e.id===n.id})||t.selectedDevices.push(e),c(e.children,!0)})},t.deselectAll=g,t.checkEnter=function(e){13===e.keyCode&&l(t.searchData)},s()}e.$inject=["$scope","$q","c8yDevices","gettext"],angular.module("c8y.deviceSelector").controller("deviceSelectorCtrl",e)})();