"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _renderAuthorize = require("./renderAuthorize");

var checkPermissions = function checkPermissions(authority, flatMenu, currentAuthority, target, Exception) {
  var filterPath = [{
    name: '/',
    path: '/'
  }, {
    name: '/',
    path: "/?client=".concat(window.globalConfig.client || 'city')
  }, {
    name: 'civbase',
    path: "/civbase/?client=".concat(window.globalConfig.client || 'city')
  }, {
    name: 'industry',
    path: '/industry'
  }, {
    name: 'civweb4',
    path: "/civweb4/"
  }, {
    name: 'civweb4',
    path: "/civweb4/?client=".concat(window.globalConfig.client || 'city')
  }, {
    name: '404',
    path: '/404'
  }, {
    name: '403',
    path: '/403'
  }, {
    name: '500',
    path: '/500'
  }];

  if (!authority) {
    return target;
  }

  if (Array.isArray(flatMenu)) {
    var data = flatMenu.concat(filterPath);

    if (/web_console/.test(authority.path)) {
      return {
        target: target,
        validate: true
      };
    }

    var findIndex = data.findIndex(function (item) {
      return item.path === authority.path;
    });

    if (findIndex > -1) {
      return {
        target: target,
        validate: true
      };
    }

    return {
      target: Exception,
      validate: false
    };
  }

  throw new Error('unsupported parameters');
};

function check(authority, flatMenu, target, Exception) {
  return checkPermissions(authority, flatMenu, _renderAuthorize.CURRENT, target, Exception);
}

var _default = check;
exports["default"] = _default;