(()=>{function e(e,n){var o=this,t=[],i=[];function r(){t=_.clone((o.assignedRoles||{}).roles)||[]}function l(e){return _(e).sortBy(y).map(y).value().join(", ")}function s(e){return _.some(t,{id:e.id})||d(e)}function d(e){return _.some(i,{id:e.id})}function c(){return e("filter")(o.inventoryRoles,o.roleTextFilter)}function u(){var e=c().filter(g);return _.every(e,s)}function a(){return t.filter(g)}function g(e){return!o.ownerAllowedRoles||_.some(o.ownerAllowedRoles,{id:e.id})}function f(){var e=_.sortBy(_.map((o.assignedRoles||{}).roles,"id")),n=_.sortBy(_.map(t,"id"));o.isUnchanged=_.isEqual(e,n)}function y(e){return n.getString(e.name)}_.assign(o,{displayTextAssigned:function(){return l((o.assignedRoles||{}).roles)},displayTextInherited:function(){return l(i)},$onChanges:function(e){e.assignedRoles&&r();e.inheritedRoles&&(i=o.inheritedRoles)},toggle:function(e){s(e)?_.remove(t,{id:e.id}):(t.push(e),t=_.uniqBy(t,"id"));f()},toggleSelectAll:function(){u()?t.length=0:t=_.reject(c(),d);f()},allSelected:u,isSelected:s,isInherited:d,filteredAssignedRoles:a,apply:function(){var e=a();o.onApply({roles:e}),o.isDropDownOpen=!1},onToggleDropdown:function(e){e||(r(),o.isUnchanged=!0)},isAllowedByOwner:g,isUnchanged:!0,getFormattedInventoryRoleDescription:_.memoize(function(e){return n.getString(e.trim())}),translateName:y})}e.$inject=["$filter","gettextCatalog"],angular.module("c8y.userRoles").component("c8yInventoryRoleSelector",{bindings:{assignedRoles:"<",inheritedRoles:"<",inventoryRoles:"<",ownerAllowedRoles:"<",disableEditForExternalUsers:"<",onApply:"&"},templateUrl:":::PLUGIN_PATH:::/inventoryRoleSelector/inventoryRoleSelector.html",controller:e,controllerAs:"vm"})})();