"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.formatDate = formatDate;
exports.urlSearchData = urlSearchData;
exports.isAndroid = isAndroid;
exports.isIOS = isIOS;
exports.getUser = getUser;

var _index = require("../api/index");

function formatDate(T) {
  var month = T.getMonth() + 1,
      day = T.getDate(),
      hour = T.getHours(),
      min = T.getMinutes();
  month > 9 ? "" : month = "0" + month;
  day > 9 ? "" : day = "0" + day;
  hour > 9 ? "" : hour = "0" + hour;
  min > 9 ? "" : min = "0" + min;
  return {
    D: [T.getFullYear(), month, day],
    T: [hour, min]
  };
}

function urlSearchData() {
  var TextSearch = location ? location.href : "",
      search = {};
  var rex = new RegExp("https?://" + location.host + "/", "g");
  TextSearch = TextSearch.replace(rex, "").split("?");

  for (var i = 0; i < TextSearch.length; i++) {
    if (!TextSearch[i]) continue;
    var vs = TextSearch[i].split("=");
    if (!vs[1]) continue;
    var v = vs[1].split("#/")[0];
    search[vs[0]] = v;
  }

  return search;
}

function isAndroid() {
  /* istanbul ignore next */
  return /android/.test(navigator.userAgent.toLowerCase());
}

function isIOS() {
  /* istanbul ignore next */
  return /ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase());
}

function getUser() {
  var search, loginName, APPToken, APPUserDetail;
  return regeneratorRuntime.async(function getUser$(_context) {
    while (1) {
      switch (_context.prev = _context.next) {
        case 0:
          search = urlSearchData(); // if (!search.ticket) return;

          _context.next = 3;
          return regeneratorRuntime.awrap((0, _index.getAPPUser)({
            ticket: search.ticket || "-7903797332285897452"
          }));

        case 3:
          loginName = _context.sent;
          _context.next = 6;
          return regeneratorRuntime.awrap((0, _index.getAPPToken)("rest/63bada00-7d01-4acc-ab2b-df8061eeeb8f"));

        case 6:
          APPToken = _context.sent;
          _context.next = 9;
          return regeneratorRuntime.awrap((0, _index.getAPPUserDetail)({
            loginName: loginName
          }));

        case 9:
          APPUserDetail = _context.sent;
          APPToken = JSON.parse(APPToken || "{}");
          localStorage.token = APPToken.id || "";
          return _context.abrupt("return", APPUserDetail || "{}");

        case 13:
        case "end":
          return _context.stop();
      }
    }
  });
}