(()=>{function e(i,e,r,n,a,s,t,u,o,c,l,g,d,f){var p=e.userId,v={REQUIRED:{type:"required",text:c("This field is required.")},EMAIL:{type:"email",text:c("Invalid email address.")}};function h(e){a.checkIfCurrent(e).then(function(e){i.isCurrent=e}),i.user=e,i._groups={},(e.groups&&e.groups.references||[]).forEach(function(e){e=e.group.id;i._groups[e]=!0})}function m(e){i.groups=e}function y(){p?a.detail(p).then(function(e){return e.data}).then(h):h({enabled:i.isNew=!0})}i.saving=!1,i.cancel=function(){r.path("/deviceusers")},i.save=function(e){if(i.saving=!0,i.userForm.$valid){var r=_.keys(i._groups).filter(function(e){return i._groups[e]}).map(function(e){return parseInt(e,10)});try{var t=a.save(e,i.isCurrent).then(function(e){e=e.data;return p=e.userName,e.id=p,e}).then(function(e){return s.updateGroups(e,r)}).then(d.triggerEvent("dmCredentialManagement",{action:"assignRole",name:"role"})).then(angular.bind({},y)).then(_.partial(u.success,c("Device updated.")));t.finally(function(){i.saving=!1}),t.then(function(){n.history.back()})}catch(e){u.danger(e.message),i.saving=!1}}},i.invalid=angular.bind(t,t.invalid,i,"userForm"),i.$watch("user.userName",function(e){e&&o.changeTitle({title:e},{skipTitleTranslation:!0})}),i.getErrorFeedback=function(e){var t=i.userForm[e]||{},n=[];return _.forEach(t.$error||{},function(e,r){e&&!t.$pristine&&n.push(l.getString(v[r.toUpperCase()].text))}),n.join(" ")},i.getGroupName=f.getName,y(),s.list(void 0).then(m)}e.$inject=["$scope","$routeParams","$location","$window","c8yUser","c8yUserGroup","c8yBase","c8yAlert","c8yTitle","gettext","gettextCatalog","c8yConfig","c8yGainsightService","c8yPropertyValueTransformService"],angular.module("c8y.parts.deviceUsers").controller("deviceUserDetailCtrl",e)})();