"use strict";

exports.__esModule = true;
exports.hasReaderPermissions = exports.hasAdministratorPermissions = exports.hasEditorPermissions = exports.selectGroupRolesClaims = exports.selectRolesClaims = exports.selectCurrentUsername = void 0;

var _reselect = require("reselect");

var _constants = require("./../constants");

var _navigation = require("./navigation");

(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 = (0, _reselect.createSelector)(authData, function (data) {
  return data.get("name");
});
exports.selectCurrentUsername = selectCurrentUsername;
var selectRolesClaims = (0, _reselect.createSelector)(authData, function (data) {
  return data.get("rolesClaimsValues");
});
exports.selectRolesClaims = selectRolesClaims;

var selectGroupRolesClaims = function selectGroupRolesClaims(roleGroup) {
  return (0, _reselect.createSelector)(selectRolesClaims, function (rolesClaims) {
    return rolesClaims.get(roleGroup) || null;
  });
};

exports.selectGroupRolesClaims = selectGroupRolesClaims;

var hasEditorPermissions = function hasEditorPermissions(roleGroup) {
  return (0, _reselect.createSelector)(selectGroupRolesClaims(roleGroup), _navigation.getCurrentScope, function (appRolesClaims, currentScope) {
    if (appRolesClaims != null) {
      return !!appRolesClaims.getIn(["*", _constants.platformRoles.Editor]) || !!appRolesClaims.getIn([currentScope, _constants.platformRoles.Editor]);
    }

    return false;
  });
};

exports.hasEditorPermissions = hasEditorPermissions;

var hasAdministratorPermissions = function hasAdministratorPermissions(roleGroup) {
  return (0, _reselect.createSelector)(selectGroupRolesClaims(roleGroup), _navigation.getCurrentScope, function (appRolesClaims, currentScope) {
    if (appRolesClaims != null) {
      return !!appRolesClaims.getIn(["*", _constants.platformRoles.Administrator]) || !!appRolesClaims.getIn([currentScope, _constants.platformRoles.Administrator]);
    }

    return false;
  });
};

exports.hasAdministratorPermissions = hasAdministratorPermissions;

var hasReaderPermissions = function hasReaderPermissions(roleGroup) {
  return (0, _reselect.createSelector)(selectGroupRolesClaims(roleGroup), _navigation.getCurrentScope, function (appRolesClaims, currentScope) {
    if (appRolesClaims != null) {
      console.log("appRolesClaims", appRolesClaims);
      return !!appRolesClaims.getIn(["*", _constants.platformRoles.Reader]) || !!appRolesClaims.getIn([currentScope, _constants.platformRoles.Reader]);
    }

    return false;
  });
};

exports.hasReaderPermissions = hasReaderPermissions;
;

(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(hasEditorPermissions, "hasEditorPermissions", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasAdministratorPermissions, "hasAdministratorPermissions", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasReaderPermissions, "hasReaderPermissions", "/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(hasEditorPermissions, "hasEditorPermissions", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasAdministratorPermissions, "hasAdministratorPermissions", "/home/vsts/work/1/s/src/selectors/authentication.js");
  reactHotLoader.register(hasReaderPermissions, "hasReaderPermissions", "/home/vsts/work/1/s/src/selectors/authentication.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();