(()=>{function e(s,n,o,r,t,e,i,u,a,l,c,g){var f,d=this;function h(e){return f=e?[]:d.users,d.users=[],o.list((e=_.get(d.filters,"text"),n=(n=_.map(_.get(d.filters,"globalRoles"),"id")).length?n.join(","):void 0,{withSubusersCount:!0,username:e,groups:n,withApps:!1,withGroups:!1,withRoles:!1,onlyRoots:_.isEmpty(e)})).then(p);var n}function p(e){E(e),d.users.paging=e.paging}function E(e){var n=d.users,t=n.paging,r=o.getTfaStrategy();_.forEach(e,function(t){var e=_.find(f,{id:t.id});t.twoFactorAuthenticationEnabled||s.all({enforced:o.isTfaActive(t),strategy:r}).then(function(e){var n=e.enforced,e=e.strategy;"SMS"!==e&&e||n&&(t.twoFactorAuthenticationEnabled=n)}),e&&(t._expanded=e._expanded),_.some(n,{id:t.id})||(n=n.concat([t]))}),n.paging=t,d.users=n}function R(e){d.globalRoles=e}function A(e){return e._globalRoles=_.map(_.get(e,"groups.references"),function(e){return _.find(d.globalRoles,{id:e.group.id})}),e}function U(){o.current().then(function(e){d.canAddUser=o.hasRole(e,"ROLE_USER_MANAGEMENT_ADMIN")||d.FEATURE_USER_HIERARCHY&&o.hasRole(e,"ROLE_USER_MANAGEMENT_CREATE"),d.canRevokeTokens=o.hasRole(e,"ROLE_USER_MANAGEMENT_ADMIN")})}function v(e){return f=d.users,o.listAll({owner:e.id,withSubusersCount:!0}).then(E)}_.assign(d,{ROUTE_NEW_USER:t.ROUTE_NEW_USER,$onInit:function(){s.all([h(),e.global.list({pageSize:1e4}).then(R)]).then(function(){return _.forEach(d.users,A)}),t.userHierarchyActive().then(function(e){d.FEATURE_USER_HIERARCHY=e}).then(U)},loadMore:function(){d.users.paging.loading=!0,d.users.paging.next().then(p).finally(function(){d.users.paging.loading=!1})},loadUsers:h,loadSubusers:v,changeUser:function(s,e){var n="changeGlobalRoles"===e.name;return t.warnAboutUserLogOutIfNeeded(s,{rolesChanged:n}).then(function(){return t.changeUser(s,e)}).then(function(e){var n,t,r=s;return(e=e||{}).removeUser&&(d.users=_.reject(d.users,{id:r.id}),t=_.get(r,"_owner.id"),d.users=_.map(d.users,function(e){return t&&t===e.id?(e.subusersCount--,angular.copy(e)):e})),e.refresh||e.removeUser||(n=o.list({username:r.id,withSubusersCount:!0}).then(_.first).then(function(t){var r=t.id,e=_.map(d.users,function(e){var n=r===e.id;return n&&(t._expanded=e._expanded),n?A(t):e});_.assign(e,_.pick(d.users,["statistics","paging"])),d.users=e})),n=e.refresh?h():n})},showExpandCollapse:function(){return d.FEATURE_USER_HIERARCHY&&_.some(d.users,function(e){return 0<e.subusersCount||_.get(e,"_owns.length")})},collapseAll:function(){t.collapseAll(d.users)},expandAll:function(){t.expandAll(d.users),s.all(_.map(d.users,function(e){return e.subusersCount>e._owns.length?v(e).then(function(){return!0}):s.resolve(!1)})).then(function(e){_.some(e)&&n(d.expandAll)})},filters:{},applyFilters:function(){h(!0)},clearFilters:function(){d.filters={},h(!0)},isAnyFilterSelected:function(){return _.some(d.filters,_.identity)},refresh:function(){return h(!0).then(function(){return _.forEach(d.users,A)})},revokeTokens:function(){function e(){return o.current().then(function(e){return t(e)}).then(function(e){return e?r.logoutAndReloadPage():s.resolve()})}var n=g.get("c8yAuthBridgeService").getPreferredLoginOption(),t=function(e){return!(!o.hasExternalOrigin(e)&&"BASIC"===n.type)};i({title:l("Confirm log out all users?"),body:c.getString('You are about to log out all users currently logged with "OAI-Secure" or "Single sign-on redirect". The JWT tokens retrieved by all devices in the current tenant will also be invalidated. Do you want to proceed?'),status:"warning",size:"sm",labels:{ok:l("Confirm")}}).then(function(){return o.revokeTokens()}).then(e).then(function(){return u.success(l("Logged out all users and invalidated tokens."))}).catch(function(e){e&&u.danger(a.getResErrorMessage(e))})}})}e.$inject=["$q","$timeout","c8yUser","c8yUserUtil","c8yUsersUi","c8yRoles","c8yModal","c8yAlert","c8yBase","gettext","gettextCatalog","$injector"],angular.module("c8y.users").component("c8yUserListView",{templateUrl:":::PLUGIN_PATH:::/userListView/userListView.html",controller:e,controllerAs:"vm"})})();