(()=>{function e(e,n,r,o,i,t,c,u,a,s,d,p,l,g){var h,v=this,m="c8y_DeviceGroup",f="c8y_IsDeviceGroup";function y(){return i.directParentAssets(h,m,f,{withChildren:!1}).then(G)}function G(e){v.currentGroups=e,i.clearBreadcrumbsCache(h),t.$emit("update")}function A(){return y().then(function(){return c.success(s("Device added to group"))})}_.assign(v,{group:{},$onInit:function(){_.get(v.config,"device.id")&&(h=_.get(v.config,"device.id"),y(),d.hasAnyRole(["ROLE_INVENTORY_ADMIN","ROLE_INVENTORY_CREATE","ROLE_MANAGED_OBJECT_ADMIN","ROLE_MANAGED_OBJECT_CREATE"]).then(function(e){v.isCreateNewGroupAllowed=e}))},addToGroup:function(e){return(e=>{var t;return(e=>!_.isUndefined(e.newGroup))(e)?(t=e.name,r({title:s("Create new group and assign device"),body:l.getString('You are about to create a new group "{{name}}" and assign the device to it. Do you want to proceed?',{name:t}),labels:{ok:s("Create and assign")},status:"warning",size:"sm"}).then(function(){return e={name:t},p.create(e).then(u.getResData);var e}).then(function(e){return g.addGroupNavigation(e),e})):n.resolve(e)})(e).then(function(e){return t=e,i.detailCached(h).then(function(e){e=e.data;return o.addChildAsset(t,e)});var t}).then(A)},removeFromGroup:function(t){return i.detailCached(h).then(function(e){e=e.data;return a.unassignDevice(t,e)}).then(y).then(function(){return c.success(s("Device removed from group."))})},isCreateNewGroupAllowed:!1})}function t(n,e,t,r,o){var i=[];function c(e){return t.detail(e).then(function(e){var t=e.data;return r.getGroupItems(t).then(function(e){n.items=e,i.push(t)})})}n.title=o("Select group"),n.drillDown=c,n.upToGroup=function(e){for(;i[i.length-1]!==e;)i.pop();i.pop(),c(e.id)},n.select=e.close,n.dismiss=e.dismiss,n.isGroup=r.isGroup,r.getTopLevelGroups().then(function(e){n.items=e}),n.breadcrumbs=i,n.currentManagedObjectId=n.device.id}e.$inject=["$scope","$q","c8yModal","c8yInventory","c8yDevices","c8yBreadcrumbs","c8yAlert","c8yBase","groupsHierarchySvc","gettext","c8yPermissions","c8yDeviceGroup","gettextCatalog","groupTypesHierarchyNavigator"],t.$inject=["$scope","$uibModalInstance","c8yInventory","c8yGroups","gettext"],angular.module("c8y.deviceGroupAssignment").controller("GroupSelectModalCtrl",t).component("groupAssignment",{controller:e,controllerAs:"vm",templateUrl:":::PLUGIN_PATH:::/groupAssignment.component.html",bindings:{config:"<"}})})();