"use strict";

exports.__esModule = true;
exports.selectRolesClaims = exports.selectGroupRolesClaims = exports.selectCurrentUsername = exports.hasReaderPermissionsForScope = exports.hasReaderPermissions = exports.hasPermissionsForRoleAndScope = exports.hasPermissionsForRole = exports.hasEditorPermissionsForScope = exports.hasEditorPermissions = exports.hasAdministratorPermissionsForScope = exports.hasAdministratorPermissions = void 0;
var _reselect = require("reselect");
var _constants = require("./../constants");
var _navigation = require("./navigation");
var _scope = require("./scope");
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var authData = function authData(state) {
  return state.get("authentication");
};
var selectCurrentUsername = exports.selectCurrentUsername = (0, _reselect.createSelector)(authData, function (data) {
  return data.get("name");
});
var selectRolesClaims = exports.selectRolesClaims = (0, _reselect.createSelector)(authData, function (data) {
  return data.get("rolesClaimsValues");
});
var selectGroupRolesClaims = exports.selectGroupRolesClaims = function selectGroupRolesClaims(roleGroup) {
  return (0, _reselect.createSelector)(selectRolesClaims, function (rolesClaims) {
    return rolesClaims.get(roleGroup) || null;
  });
};
var _hasRolePermissions = function hasRolePermissions(appRolesClaims, scopeId, role, scopes) {
  if (appRolesClaims != null && scopeId != null) {
    var allowed = !!appRolesClaims.getIn(["*", role]) || !!appRolesClaims.getIn([scopeId, role]);
    if (!allowed) {
      var _scopes$get$toJS$pare, _scopes$get;
      var parentScopeId = (_scopes$get$toJS$pare = (_scopes$get = scopes.get(scopeId)) == null || (_scopes$get = _scopes$get.toJS()) == null ? void 0 : _scopes$get.parentScopeId) != null ? _scopes$get$toJS$pare : null;
      return _hasRolePermissions(appRolesClaims, parentScopeId, role, scopes);
    }
    return allowed;
  }
  return false;
};
var hasEditorPermissions = exports.hasEditorPermissions = function hasEditorPermissions(roleGroup) {
  return (0, _reselect.createSelector)(selectGroupRolesClaims(roleGroup), _navigation.getCurrentScope, _scope.getScopesSelector, function (appRolesClaims, currentScope, scopes) {
    return _hasRolePermissions(appRolesClaims, currentScope, _constants.platformRoles.Editor, scopes);
  });
};
var hasEditorPermissionsForScope = exports.hasEditorPermissionsForScope = function hasEditorPermissionsForScope(scope, roleGroup) {
  return (0, _reselect.createSelector)(selectGroupRolesClaims(roleGroup), _scope.getScopesSelector, function (appRolesClaims, scopes) {
    return _hasRolePermissions(appRolesClaims, scope, _constants.platformRoles.Editor, scopes);
  });
};
var hasPermissionsForRole = exports.hasPermissionsForRole = function hasPermissionsForRole(roleGroup, role) {
  return (0, _reselect.createSelector)(selectGroupRolesClaims(roleGroup), _navigation.getCurrentScope, _scope.getScopesSelector, function (appRolesClaims, currentScope, scopes) {
    return _hasRolePermissions(appRolesClaims, currentScope, role, scopes);
  });
};
var hasPermissionsForRoleAndScope = exports.hasPermissionsForRoleAndScope = function hasPermissionsForRoleAndScope(scope, roleGroup, role) {
  return (0, _reselect.createSelector)(selectGroupRolesClaims(roleGroup), _scope.getScopesSelector, function (appRolesClaims, scopes) {
    return _hasRolePermissions(appRolesClaims, scope, role, scopes);
  });
};
var hasAdministratorPermissions = exports.hasAdministratorPermissions = function hasAdministratorPermissions(roleGroup) {
  return (0, _reselect.createSelector)(selectGroupRolesClaims(roleGroup), _navigation.getCurrentScope, _scope.getScopesSelector, function (appRolesClaims, currentScope, scopes) {
    return _hasRolePermissions(appRolesClaims, currentScope, _constants.platformRoles.Administrator, scopes);
  });
};
var hasAdministratorPermissionsForScope = exports.hasAdministratorPermissionsForScope = function hasAdministratorPermissionsForScope(scope, roleGroup) {
  return (0, _reselect.createSelector)(selectGroupRolesClaims(roleGroup), _scope.getScopesSelector, function (appRolesClaims, scopes) {
    return _hasRolePermissions(appRolesClaims, scope, _constants.platformRoles.Administrator, scopes);
  });
};
var hasReaderPermissions = exports.hasReaderPermissions = function hasReaderPermissions(roleGroup) {
  return (0, _reselect.createSelector)(selectGroupRolesClaims(roleGroup), _navigation.getCurrentScope, _scope.getScopesSelector, function (appRolesClaims, currentScope, scopes) {
    return _hasRolePermissions(appRolesClaims, currentScope, _constants.platformRoles.Reader, scopes);
  });
};
var hasReaderPermissionsForScope = exports.hasReaderPermissionsForScope = function hasReaderPermissionsForScope(scope, roleGroup) {
  return (0, _reselect.createSelector)(selectGroupRolesClaims(roleGroup), _scope.getScopesSelector, function (appRolesClaims, scopes) {
    return _hasRolePermissions(appRolesClaims, scope, _constants.platformRoles.Reader, scopes);
  });
};
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(authData, "authData", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(selectCurrentUsername, "selectCurrentUsername", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(selectRolesClaims, "selectRolesClaims", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(selectGroupRolesClaims, "selectGroupRolesClaims", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(_hasRolePermissions, "hasRolePermissions", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasEditorPermissions, "hasEditorPermissions", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasEditorPermissionsForScope, "hasEditorPermissionsForScope", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasPermissionsForRole, "hasPermissionsForRole", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasPermissionsForRoleAndScope, "hasPermissionsForRoleAndScope", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasAdministratorPermissions, "hasAdministratorPermissions", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasAdministratorPermissionsForScope, "hasAdministratorPermissionsForScope", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasReaderPermissions, "hasReaderPermissions", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasReaderPermissionsForScope, "hasReaderPermissionsForScope", "/home/vsts/work/1/s/src/selectors/authentication.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(authData, "authData", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(selectCurrentUsername, "selectCurrentUsername", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(selectRolesClaims, "selectRolesClaims", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(selectGroupRolesClaims, "selectGroupRolesClaims", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(_hasRolePermissions, "hasRolePermissions", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasEditorPermissions, "hasEditorPermissions", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasEditorPermissionsForScope, "hasEditorPermissionsForScope", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasPermissionsForRole, "hasPermissionsForRole", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasPermissionsForRoleAndScope, "hasPermissionsForRoleAndScope", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasAdministratorPermissions, "hasAdministratorPermissions", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasAdministratorPermissionsForScope, "hasAdministratorPermissionsForScope", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasReaderPermissions, "hasReaderPermissions", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasReaderPermissionsForScope, "hasReaderPermissionsForScope", "/home/vsts/work/1/s/src/selectors/authentication.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();