(()=>{function e(n,e,i,t,o,r,c,s,a,d,u){var l,v=this,h=d("Enable/disable owner"),w=d("You don't have permission to admin this device.");function g(){r.hasId(v.device)&&(v.ownerInfoFetched=!1,o.canAdminMOs([v.device]).then(function(e){return v.canAdminDevice=e,v.canAdminDevice?n.resolve():(c.danger(w),n.reject())}).then(f).finally(function(){v.ownerInfoFetched=!0}))}function f(){return b(!1),i.getOwnerObject(_.get(v,"device.id"),{silentError:!0}).then(function(e){v.owner=e}).catch(function(e){e.serviceUser&&b(e.serviceUser),e.accessDenied&&(v.errorTooltipMessage=d("You don't have permission to enable/disable this owner user.")),e.notFound&&!e.serviceUser&&c.danger(u.getString('Device owner not found for device "{{name}}".',v.device)),e.accessDenied||e.notFound||e.serviceUser||c.danger(r.getResErrorMessage(e))})}function m(){v.isEditMode?v.isEditMode=!1:(v.isEditMode=!0,l=_.get(v,"device.owner"))}function b(e){_.set(v,"serviceUserDevice",e)}function y(){var e,n;v.device.owner?(n=d("Change owner`owner may be a human or system user`"),e=d("Change owner`owner may be a human or system user`"),n={status:"warning",title:n,body:u.getString('You are about to change the owner of this device to "{{ owner }}" user. Unless the credentials on the device are changed accordingly this may interrupt the communication between this device and the platform. Do you want to proceed?',{owner:v.device.owner}),size:"sm",labels:{ok:e,cancel:d("Cancel")}},s(n).then(function(){m(),t.detail(_.get(v,"device.owner"),{silentError:!0}).then(function(){return i.save(_.pick(v.device,["id","owner"]))}).then(function(){c.success(d("Device owner updated."))}).then(function(){g()}).catch(function(){var e=v.device.owner;D(l),c.danger(u.getString('Could not find user "{{errorUser}}". Device owner reverted to "{{owner}}".',{errorUser:e,owner:v.device.owner}))})}).catch(function(){p()})):p()}function p(){m(),D(l)}function D(e){_.set(v,"device.owner",e)}_.assign(v,{$onChanges:function(e){e.device.currentValue&&g()},toggleOwner:function(e){function n(){v.owner.enabled=!t}var t=e.target.checked,o=_.get(v,"device.id");o&&v.canAdminDevice||n();var e=d(t?"Enable owner":"Disable owner"),r=d(t?"You are about to enable this device owner. Do you want to proceed?":"You are about to disable this device owner, this user will be locked and logged out of the platform. Do you want to proceed?"),r={title:e,body:r,status:"danger",size:"sm",labels:{ok:e,cancel:d("Cancel")}};s(r).then(function(){return i.setOwnerEnabled(o,t).then(function(e){v.owner=e,c.success(d("Owner status updated."))}).catch(n)}).catch(n)},toggleEdit:m,getTooltip:function(){return v.errorTooltipMessage?"":h},keyPressHandler:function(e){return a.handle(e,y,p)},save:y,cancel:p,shouldShowToggle:function(){return!v.isEditMode&&v.ownerInfoFetched&&!v.serviceUserDevice}})}e.$inject=["$q","$scope","c8yInventory","c8yUser","c8yPermissions","c8yBase","c8yAlert","c8yModal","keyboardKeyHandler","gettext","gettextCatalog"],angular.module("c8y.deviceStatus").component("ownerStatus",{controller:e,controllerAs:"vm",templateUrl:":::PLUGIN_PATH:::/ownerStatus.html",bindings:{device:"<"}})})();