(()=>{function e(n,t){var r,o,i=this,e="username",l=e,s="single",u="multiple",a=s,d={object:function(e){return _.omit(e,["_selected","_expanded","_owner","_owns"])},username:function(e){return e.userName}},c=t.mapToUsersInMemory;function f(e){e=0<arguments.length&&void 0!==e?e:{};i.loading=!0,_.defaults(e,{pageSize:100}),r=n.list(e).then(function(e){return o=e.statistics,e}).then(_.map).finally(function(){i.loading=!1})}function p(){var e=i.ngModelController.$modelValue,n=[];e&&(_.isString(e)&&(n=[e]),_.isArray(e)&&(n=_.map(e,function(e){return e&&e.id||e})),_.isObject(e))&&(n=[e.id]),_.forEach(i.userFlatTree,function(e){e._selected=_.includes(n,e.id)})}function g(e){var n=t.hideUsers(e,i.hiddenUsers),e=_.reject(e,_.partial(_.includes,n)),n=((e,n)=>{var t=i.includeRoot,n=_(i.rootUsers).map(c(n)).filter().value();return e=n.length?t?n:_(n).map("_owns").flatten().uniq().value():e})(t.buildUserTree(e),e);i.userFlatTree=t.flattenTree(n),p()}function h(e){return e._selected}function m(e){delete e._selected}function U(e){e._expanded=!1,_.forEach(e._owns,U)}function y(){switch(_.toLower(i.selectionType)){case s:return s;case u:return u;default:return a}}_.assign(i,{$onInit:function(){i.ngModelController.$render=p},$onChanges:function(e){(e.includeRoot||e.rootUsers||i.hiddenUsers)&&r.then(g)},isSelected:h,isVisible:function(e){return i.searchQuery||0===_.get(e,"_depth")||_.get(e,"_owner._expanded")},toggleSelection:function(e){(h(e)?m:e=>{y()===s&&_(i.userFlatTree).filter(h).forEach(m),e._selected=!0})(e);(()=>{var e=d[_.toLower(i.modelType)]||d[l],n=_(i.userFlatTree).filter(h).map(e).value();!(n=y()===s?_.first(n)||null:n)&&i.defaultUser&&(n=e(i.defaultUser)),i.ngModelController.$setViewValue(n)})()},toggleExpanded:function(e){e._expanded=!e._expanded,e._expanded||U(e)},onSearchQuery:function(e){i.userFlatTree=[],_.isEmpty(e)?f():f({username:e});r.then(g)},shouldShowWarning:function(){var e=!1;{var n;o&&(n=o.totalPages,e=1<n)}return e},userDepth:function(e){return i.searchQuery?20:20+30*e._depth},loading:!1}),f()}e.$inject=["c8yUser","c8yUserUtil"],angular.module("c8y.ui").component("c8yUiUserPicker",{templateUrl:":::PLUGIN_PATH:::/ui/user/userPicker.html",require:{ngModelController:"ngModel"},bindings:{modelType:"@",selectionType:"@",includeRoot:"<",rootUsers:"<",hiddenUsers:"<",defaultUser:"<"},controller:e,controllerAs:"vm"})})();