"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getModuleEntities = exports.getEntityUrl = exports.getEntityLabelHeading = exports.getEntityDescription = exports.getAccessibleEntities = void 0;
var _enums = require("../constants/enums");
var _wrapperService = require("./wrapperService");
const baseUrl = process.env.REACT_APP_BASE_URL;
/*
 current module name Admin
   current entity name Roles
    entity Name Users
      localUrl + entityUrl

    entity Name Roles
      baseUrl + entityUrl
      
    current entity name Users
       entity Name Roles
  
    current entity Name Dashboard
*/
const getEntityUrl = (entityName, selectedModuleName, selectedEntityName) => {
  let entityUrl = undefined;
  //let localUrl = getUrl("/manage");
  let isReactUrl = true;
  let completeUrl = "";
  switch (entityName) {
    case _enums.entityNames.DASHBOARD:
      {
        entityUrl = _enums.endPoints.CALL_BACK_DASHBOARD_URL;
        isReactUrl = false;
        break;
      }
    case _enums.entityNames.OASTATUS:
      {
        entityUrl = _enums.endPoints.CALL_BACK_OASTATUS_URL;
        isReactUrl = false;
        break;
      }
    case _enums.entityNames.OAMENUSTATUS:
      {
        entityUrl = _enums.endPoints.CALL_BACK_OAMENUSTATUS_URL;
        isReactUrl = false;
        break;
      }
    case _enums.entityNames.OAREFUNDS:
      {
        entityUrl = _enums.endPoints.CALL_BACK_OAREFUNDS_URL;
        isReactUrl = false;
        break;
      }
    case _enums.entityNames.PRICINGGROUP:
      {
        entityUrl = _enums.endPoints.CALL_BACK_BRIDGE_PRICINGGROUPS_URL;
        break;
      }
    case _enums.entityNames.MYRESTAURANTS:
      {
        entityUrl = _enums.endPoints.CALL_BACK_BRIDGE_MYRESTAURANTS_URL;
        break;
      }
    case _enums.entityNames.PRICEENTRY:
      {
        entityUrl = _enums.endPoints.CALL_BACK_BRIDGE_PRICEENTRY_URL;
        break;
      }
    case _enums.entityNames.SMARTSELLDMALEADERBOARD:
      {
        entityUrl = _enums.endPoints.CALL_BACK_SMARTSELLDMALEADERBOARD_URL;
        break;
      }
    case _enums.entityNames.SMARTSELLENTITYLEADERBOARD:
      {
        entityUrl = _enums.endPoints.CALL_BACK_SMARTSELLENTITYLEADERBOARD_URL;
        break;
      }
    case _enums.entityNames.ROLEMANAGEMENT:
      {
        entityUrl = _enums.endPoints.CALL_BACK_BRIDGE_ROLES_URL;
        break;
      }
    case _enums.entityNames.USERMANAGEMENT:
      {
        entityUrl = _enums.endPoints.CALL_BACK_BRIDGE_USERS_URL;
        break;
      }
    case "Groups":
    case _enums.entityNames.GROUPMANAGEMENT:
      {
        entityUrl = _enums.endPoints.CALL_BACK_BRIDGE_GROUPS_URL;
        break;
      }
    case _enums.entityNames.HOURSOPERATION:
      {
        entityUrl = _enums.endPoints.CALL_BACK_BRIDGE_HOOPS_URL;
        break;
      }
    default:
      {
        break;
      }
  }
  completeUrl = baseUrl + entityUrl;
  return completeUrl;
};
exports.getEntityUrl = getEntityUrl;
const getModuleEntities = (privileges, mName) => {
  let values = privileges.filter(x => x.moduleName === mName && x.showInMenu === true);
  values = values.sort((a, b) => a.order - b.order);
  return values;
};
exports.getModuleEntities = getModuleEntities;
const getEntityLabelHeading = entityName => {
  switch (entityName) {
    case _enums.entityNames.USERMANAGEMENT:
      return "Restaurant Users Management";
    case _enums.entityNames.HOURSOPERATION:
      return "Hours of Operation";
    case _enums.entityNames.MYRESTAURANTS:
      return "Revenue Management";
    case _enums.entityNames.PRICEENTRY:
    case _enums.entityNames.GROUPMANAGEMENT:
      return "Restaurant Groups Management";
    case _enums.entityNames.ROLEMANAGEMENT:
    default:
      return "Restaurant Roles Management";
  }
};
exports.getEntityLabelHeading = getEntityLabelHeading;
const getAccessibleEntities = (privileges, mName) => {
  let moduleEntities = getModuleEntities(privileges, mName);
  let accessibleEntities = moduleEntities.filter(x => x.showInMenu === true && x.canRead === true);
  return accessibleEntities;
};
exports.getAccessibleEntities = getAccessibleEntities;
const getEntityDescription = (privileges, entityName) => {
  let description = "";
  if (privileges !== undefined && privileges !== null && privileges.length > 0) {
    let found = privileges.find(x => x.entityName === entityName);
    if (found !== null && found !== undefined) {
      description = found.entityDescription;
    }
  }
  return description;
};
exports.getEntityDescription = getEntityDescription;
const getOldState = arr => {
  let value = _enums.TriStateValue.UNCHECKED;
  let foundValue = false;
  if (arr !== null && arr !== undefined && arr.length > 0) {
    for (let c = 0; c < arr.length; c++) {
      let obj = arr[c];
      if (obj.Value !== _enums.TriStateValue.CHECKED && obj.Value !== _enums.TriStateValue.PARTIAL) {} else if (c === arr.length - 1) {
        value = _enums.TriStateValue.UNCHECKED;
        foundValue = true;
      }
    }
    if (foundValue === false) {
      for (let c = 0; c < arr.length; c++) {
        let obj = arr[c];
        if (obj.Value !== _enums.TriStateValue.UNCHECKED && obj.Value !== _enums.TriStateValue.CHECKED) {} else if (c === arr.length - 1) {
          value = _enums.TriStateValue.PARTIAL;
          foundValue = true;
        }
      }
    }
    if (foundValue === false) {
      for (let c = 0; c < arr.length; c++) {
        let obj = arr[c];
        if (obj.Value !== _enums.TriStateValue.PARTIAL && obj.Value !== _enums.TriStateValue.UNCHECKED) {} else if (c === arr.length - 1) {
          value = _enums.TriStateValue.CHECKED;
          foundValue = true;
        }
      }
    }
  }
  return value;
};