"use strict";

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

var _uuid = _interopRequireDefault(require("uuid"));

var _tools = require("../../utils/tools");

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }

var cacheStoreName = "okrMap_cache_store";

var getCacheStore = function getCacheStore() {
  var str = localStorage.getItem(cacheStoreName) || "{}";
  return JSON.parse(str);
};

var CacheUtil = /*#__PURE__*/function () {
  function CacheUtil() {
    _classCallCheck(this, CacheUtil);
  }

  _createClass(CacheUtil, null, [{
    key: "getCache",
    value: function getCache() {
      var id = (0, _tools.getQueryString)().cacheId;
      if (!id) return null;
      var store = getCacheStore();
      var cache = store[id];
      if (!cache) return null;
      return cache;
    }
  }, {
    key: "setCache",
    value: function setCache(cache) {
      var id = (0, _tools.getQueryString)().cacheId;

      if (!id) {
        id = (0, _uuid["default"])();
        (0, _tools.changeQueryString)("cacheId", id);
      }

      var store = getCacheStore();
      store[id] = cache;
      localStorage.setItem(cacheStoreName, JSON.stringify(store));
    }
  }, {
    key: "updateCache",
    value: function updateCache(c) {
      var id = (0, _tools.getQueryString)().cacheId;
      var cache = {};
      if (id) cache = this.getCache();
      cache = _objectSpread(_objectSpread({}, cache), c);
      this.setCache(cache);
    }
  }]);

  return CacheUtil;
}();

exports["default"] = CacheUtil;