function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,r){var t;if(e)return"string"==typeof e?_arrayLikeToArray(e,r):"Map"===(t="Object"===(t={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:t)||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(e,r):void 0}function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayLikeToArray(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}(()=>{function e(e,t){var n=this;function r(e,r){return e[r]=!0,e}function o(e){return n.selectedPermissions&&n.availableRoles&&_(n.availableRoles).map("id").filter(a(e)).every(function(e){return n.selectedPermissions[e]})}function a(e){var r=new RegExp("".concat(e,"$"));return function(e){return r.test(e)}}_.assign(n,{$onChanges:function(e){e.availableRoles&&(n.groupedPermissions=_.map(_.groupBy(n.availableRoles,"category"),function(e,r){return{category:r,permissions:e}}));e.inputSelectedRoles&&(n.selectedPermissions=_.reduce(n.inputSelectedRoles,r,{}))},permissionId:function(e,r){e=_.find(e,{access:r});return e&&e.id},categoryLabel:function(e){var e=e.category,r=t.STRINGS.PERMISSIONS_GLOBAL_LABELS;e=r[e]||_.capitalize((e||"").toLowerCase().replace(/_/g," "));return e},hasPermission:function(e,r){return _.some(e,{access:r})},hasPermissionWithAccess:function(e){return n.availableRoles&&_(n.availableRoles).map("id").some(a(e))},allSelected:o,selectAll:function(e){var r=n.selectedPermissions||{},t=!o(e);_(n.availableRoles).map("id").filter(a(e)).forEach(function(e){r[e]=t}),n.selectedPermissions=r},STRINGS:t.STRINGS}),e.$watch("vm.selectedPermissions",function(){n.onSelectedRolesChange({selectedRoles:_.reduce(n.selectedPermissions,function(e,r,t){return r?[].concat(_toConsumableArray(e),[t]):e},[])})},!0)}e.$inject=["$scope","c8yRolesUi"],angular.module("c8y.ui").component("c8yRolesMatrix",{templateUrl:":::PLUGIN_PATH:::/ui/roles/roles-matrix.html",bindings:{availableRoles:"<",inputSelectedRoles:"<selectedRoles",onSelectedRolesChange:"&",readOnly:"<"},controllerAs:"vm",controller:e})})();