function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}(()=>{function e(i,u,t,s,c,n,e,r,o,a,l,f,d,y){return w.$inject=["options","$uibModalInstance"],{askForPassword:function(){try{return i.get("c8yPasswordConfirm").confirmPassword().toPromise()}catch(e){return u.resolve(!0)}},currentPassword:function(){return i.get("c8yPasswordConfirm").currentPassword().toPromise().then(function(e){return null===e?u.reject():u.resolve(e)})},warnIfPasswordExpiresSoon:function(){var e="passwordExpirationAlertsDisplayed";function a(e,t){return!e||moment(e).isBefore(moment(t))}return c.current().then(function(o){return"OAUTH2"===_.get(o,"customProperties.userOrigin")?u.resolve():u.all({expirationAlertsDisplayedPreference:n.get(e),validityLimitInDays:r.detailValue({category:"password",key:"limit.validity"},0)}).then(function(e){var t,n,r=e.expirationAlertsDisplayedPreference,e=e.validityLimitInDays,r=r||{LESS_THAN_WEEK:null,LESS_THAN_DAY:null};return 0!==e&&(e=moment(o.lastPasswordChange).add(e,"days"),n=!1,(t=moment.duration(e.diff(moment())).asDays())<=1&&a(r.LESS_THAN_DAY,o.lastPasswordChange)?(n=!0,r.LESS_THAN_DAY=moment().format(s.dateFullFormat)):t<=7&&a(r.LESS_THAN_WEEK,o.lastPasswordChange)&&(n=!0,r.LESS_THAN_WEEK=moment().format(s.dateFullFormat)),n)&&l.warning(d.getString("Your password will expire {{expirationTime | relativeDate}}. Consider changing password now.",{expirationTime:e})),r}).then(_.partial(n.set,e))})},createUserFlatTree:function(e){return g(m(e))},buildUserTree:m,flattenTree:g,search:function(e,t){var n=["userName","lastName","firstName","email","phone"],r=_.constant(!0),o=_.constant(!0);{var a;e&&(a=new RegExp(e,"i"),r=function(t){return _.some(n,function(e){return a.test(t[e])})})}{var i;t&&t.length&&(i=_.reduce(t,function(e,t){return e[t.id]=!0,e},{}),o=function(e){return _.some(e.groups.references,function(e){return i[_.get(e,"group.id")]})})}return function(e){return r(e)&&o(e)}},selectUserDialog:function(e){return t.open({templateUrl:":::PLUGIN_PATH:::/ui/user/selectUser.modal.html",controllerAs:"vm",ariaLabelledBy:"modal-title",ariaDescribedBy:"modal-body",controller:w,resolve:{options:_.constant(e)}}).result},userHierarchyActive:_.once(function(){return e.listByUser().then(function(e){return!!_.find(e,{key:"c8y-feature-user-hierarchy"})})}),hideUsers:function(e,t){function n(){var t=_.keyBy(r,"id");return _.filter(e,function(e){return t[e.owner]&&!t[e.id]})}var r=_(_.isArray(t)?t:[t]).map(p(e)).value();for(;n().length;)r=_.union(r,n());return _.uniq(r)},mapToUsersInMemory:p,canUserManageTenant:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.user,n=e.tenant,r=e.mustBeTopTenant,o=i.get("c8yPermissions"),a=i.get("c8yTenant");return u.all({user:t||c.current(),tenant:n||a.current()}).then(function(e){var t=a.isTopTenant(e.tenant.name),n=_.get(e.tenant,"allowCreateTenants");return o.hasRole(e.user,"ROLE_TENANT_MANAGEMENT_READ")&&(r?t:t||n)})},requireLogout:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:angular.noop;return a({title:f("Logout required"),body:f("You must log out to apply your changes. Do you want to proceed?"),status:"warning",labels:{ok:f("Confirm and log out"),cancel:f("Cancel")},dismissValue:"canceled"}).then(e).then(h)},logoutAndReloadPage:h};function m(t){e=t,n=_.keyBy(e,"id");var n,e=_.reject(e,function(e){return e.owner&&!n[e.owner]&&delete e.owner,e.owner}),r=_.keyBy(t,"id");return _.forEach(t,function(e){e._owns=_.filter(t,{owner:e.id}),e._owner=_.get(r,e.owner)}),e}function p(n){return function(e){var t;return"string"==typeof e&&(t=e),"object"===_typeof(e)&&(t=e.userName),_.find(n,{userName:t})}}function g(e,t,n){var n=n||[],e=_.sortBy(e,["id","lastName"]),r=t||0;return _.reduce(e,function(e,t){return t._depth=r,e.push(t),g(t._owns,r+1,e)},n)}function w(e,t){_.assign(this,{textOk:f("Select"),textCancel:f("Cancel")},e,t)}function h(){return o.logout().then(function(e){e&&e.url?y.location.href=e.url:y.location.reload()})}}e.$inject=["$injector","$q","$uibModal","c8yBase","c8yUser","c8yUserPreferences","c8yApplication","c8ySettings","c8yAuth","c8yModal","c8yAlert","gettext","gettextCatalog","$window"],angular.module("c8y.ui").factory("c8yUserUtil",e)})();