"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.hasWebHead = exports.getVersion = exports.getUserInfo = exports.getUploadMaxSize = exports.getTenantInfo = exports.getSource = exports.getOkrAdvancedSetting = exports.getBSGlobal = exports.getAppHead = exports.formatNum = exports["default"] = exports.VERSION_MAP = void 0;
exports.isWx = isWx;

var getUserInfo = function getUserInfo() {
  var _window$BSGlobal;

  return ((_window$BSGlobal = window.BSGlobal) === null || _window$BSGlobal === void 0 ? void 0 : _window$BSGlobal.loginUserInfo) || {};
};

exports.getUserInfo = getUserInfo;

var getTenantInfo = function getTenantInfo() {
  var _window$BSGlobal2;

  return ((_window$BSGlobal2 = window.BSGlobal) === null || _window$BSGlobal2 === void 0 ? void 0 : _window$BSGlobal2.tenantInfo) || {};
};

exports.getTenantInfo = getTenantInfo;

var getBSGlobal = function getBSGlobal(key) {
  return window.BSGlobal && window.BSGlobal[key];
};

exports.getBSGlobal = getBSGlobal;

var getOkrAdvancedSetting = function getOkrAdvancedSetting() {
  var _window$BSGlobal3;

  return ((_window$BSGlobal3 = window.BSGlobal) === null || _window$BSGlobal3 === void 0 ? void 0 : _window$BSGlobal3.OkrAdvancedSetting) || {};
}; // version 1 试用版


exports.getOkrAdvancedSetting = getOkrAdvancedSetting;

var getVersion = function getVersion() {
  var _window$BSGlobal$tena;

  return (_window$BSGlobal$tena = window.BSGlobal.tenantAuthentication) === null || _window$BSGlobal$tena === void 0 ? void 0 : _window$BSGlobal$tena.Version;
};

exports.getVersion = getVersion;

var getSource = function getSource() {
  var _getTenantInfo;

  return (_getTenantInfo = getTenantInfo()) === null || _getTenantInfo === void 0 ? void 0 : _getTenantInfo.Source;
};

exports.getSource = getSource;

var getUploadMaxSize = function getUploadMaxSize() {
  var _info$tenantSetting;

  var info = getBSGlobal('tenantInfo');
  if ((_info$tenantSetting = info.tenantSetting) !== null && _info$tenantSetting !== void 0 && _info$tenantSetting.allowUploadAttachmentSize) return info.tenantSetting.allowUploadAttachmentSize;
  if (info.Id === 352728) return 150;
  var isDingDing = info.Source === 861;
  var isDingZhi = window.dingZhiSize && window.dingZhiSize.indexOf(info.Id) !== -1;
  if (isDingDing) return 20;
  if (isDingZhi) return 100;
  return 50;
};

exports.getUploadMaxSize = getUploadMaxSize;

function isWx() {
  var _getTenantInfo2, _getTenantInfo3;

  return ((_getTenantInfo2 = getTenantInfo()) === null || _getTenantInfo2 === void 0 ? void 0 : _getTenantInfo2.Source) === 860 && ((_getTenantInfo3 = getTenantInfo()) === null || _getTenantInfo3 === void 0 ? void 0 : _getTenantInfo3.corpCreateType) !== 2;
}
/*
 *通过AppId,来查询是否开通这个产品
 */


var getAppHead = function getAppHead(appId) {
  var appHead = getBSGlobal('WebHead');
  var apps = getBSGlobal('apps');
  if (!appHead && apps) return undefined;
  var app = appHead && appHead.AppHead || apps && apps || [];
  var appItem = app.find(function (item) {
    return item.AppId === appId;
  });
  return appItem;
}; // number初始化成k、w


exports.getAppHead = getAppHead;

var formatNum = function formatNum(num) {
  if (num < 1e3) {
    return num;
  }

  if (num >= 1e3 && num < 1e4) {
    return "".concat((num / 1e3).toFixed(1), "k");
  }

  return "".concat((num / 1e4).toFixed(1), "w");
}; // 看是否有okr 任务 项目等等等东西


exports.formatNum = formatNum;

var hasWebHead = function hasWebHead(webHeadName) {
  var _window$BSGlobal4, _window$BSGlobal4$Web;

  var webHeadMap = {
    task: '1',
    okr: '113',
    project: '112',
    apply: '907',
    kaohe: '403'
  };
  var webHead = ((_window$BSGlobal4 = window.BSGlobal) === null || _window$BSGlobal4 === void 0 ? void 0 : (_window$BSGlobal4$Web = _window$BSGlobal4.WebHead) === null || _window$BSGlobal4$Web === void 0 ? void 0 : _window$BSGlobal4$Web.AppHead) || [];
  return webHead.findIndex(function (a) {
    return a.AppId === webHeadMap[webHeadName];
  }) !== -1;
}; // 版本判断


exports.hasWebHead = hasWebHead;
var VERSION_MAP = {
  1: '试用版',
  2: '标准版',
  3: '个人版',
  6: '旗舰版',
  8: '考核版',
  9: '专业版',
  10: 'OKR版',
  100: 'OKR模板购买'
};
exports.VERSION_MAP = VERSION_MAP;
var _default = {
  hasWebHead: hasWebHead
};
exports["default"] = _default;