"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getTodos = exports.getReplys = exports.getReminds = exports.getMessages = exports.getInforms = exports.getData = exports.getCycleSetting = exports.deleteReply = exports.clearReplys = exports.clearInforms = exports.changeLang = void 0;

var _axios = _interopRequireDefault(require("axios"));

var _request = require("../../utils/request");

var _window$BSGlobal$tena, _window$BSGlobal$logi;

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

// @ts-ignore
var tenantId = window.BSGlobal && ((_window$BSGlobal$tena = window.BSGlobal.tenantInfo) === null || _window$BSGlobal$tena === void 0 ? void 0 : _window$BSGlobal$tena.Id) || 0; // @ts-ignore

var userId = window.BSGlobal && ((_window$BSGlobal$logi = window.BSGlobal.loginUserInfo) === null || _window$BSGlobal$logi === void 0 ? void 0 : _window$BSGlobal$logi.Id) || 0;

var requestDomain = function requestDomain() {
  if (!window.location.hostname.match(/dev/)) return "";
  return "".concat(window.location.protocol, "//www.tita.gift");
};

var getTodos = function getTodos(pageNum) {
  return (0, _request.rget)("v1")("todo/Get?app_type=-1&app_id=-1&page_num=".concat(pageNum, "&page_size=10&status=1"));
};

exports.getTodos = getTodos;

var getData = function getData(url, saveData) {
  return (0, _request.rget)("v1")(url).then(function (res) {
    saveData(res.Data);
  });
};

exports.getData = getData;

var getReplys = function getReplys(pageNum) {
  return (0, _request.rget)("v1")("comment/messages?page_num=".concat(pageNum, "&page_size=10&status=1&clear=0"));
};

exports.getReplys = getReplys;

var getReminds = function getReminds() {
  return (0, _request.rget)("v2")("remind/get");
};

exports.getReminds = getReminds;

var getInforms = function getInforms(pageNum) {
  return (0, _request.rget)("v1")("messages/Get?page_size=10&page_num=".concat(pageNum, "&status=1&app_type=-1&app_id=-1"));
};

exports.getInforms = getInforms;

var clearInforms = function clearInforms() {
  return (0, _request.rdelete)("v1")("Indicator/Clear?message_type=1&indicator_type=undefined");
};

exports.clearInforms = clearInforms;

var clearReplys = function clearReplys() {
  return (0, _request.rdelete)("v1")("Indicator/Clear?message_type=0&indicator_type=mLeaveandComment");
};

exports.clearReplys = clearReplys;

var deleteReply = function deleteReply(msgId) {
  return (0, _request.rpost)("v1")("messages/clear?msgId=".concat(msgId));
};

exports.deleteReply = deleteReply;

var getMessages = function getMessages() {
  var nowTime = new Date();
  var year = nowTime.getFullYear();
  var month = nowTime.getMonth() + 1;
  var date = nowTime.getDate();

  _axios["default"].interceptors.response.use(function (response) {
    return response;
  }, function (error) {
    var _error$response;

    if (error !== null && error !== void 0 && error.response) {
      switch (error === null || error === void 0 ? void 0 : error.response.status) {
        case 401:
          window.location.reload();
      }
    }

    return Promise.reject(error === null || error === void 0 ? void 0 : (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data);
  });

  return _axios["default"].get("".concat(requestDomain(), "/api/v1/").concat(tenantId, "/").concat(userId, "/RemindV2/Get?dateTime=").concat(year, "/").concat(month, "/").concat(date)).then(function (resp) {
    return resp.data;
  });
};

exports.getMessages = getMessages;

var changeLang = function changeLang(lang) {
  return (0, _request.rget)("v1")("multiLange/change?lang=".concat(lang));
};

exports.changeLang = changeLang;

var getCycleSetting = function getCycleSetting() {
  return (0, _request.rget)('v1')('okr/cycleSetting').then(function (res) {
    return res.Data;
  });
};

exports.getCycleSetting = getCycleSetting;