'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
var _createClass = require('@babel/runtime/helpers/createClass');
var storage_persistData = require('../storage/persist-data.js');
require('../env/env.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);

var LocationStorage = /*#__PURE__*/function () {
  function LocationStorage() {
    _classCallCheck__default["default"](this, LocationStorage);
  }
  return _createClass__default["default"](LocationStorage, null, [{
    key: "getLocationFromSessionStorage",
    value:
    // 从sessionStorage获取缓存位置信息
    function getLocationFromSessionStorage() {
      var storageSession = window.sessionStorage.getItem('position');
      if (storageSession) {
        try {
          var location = JSON.parse(storageSession);
          return location;
        } catch (_a) {
          return null;
        }
      }
      return null;
    }
    // 从localStorage获取缓存位置信息
  }, {
    key: "getLocationFromLocalStorage",
    value: function getLocationFromLocalStorage() {
      var persistPosition = storage_persistData.getPersist('position');
      if (persistPosition) {
        try {
          var location = JSON.parse(persistPosition);
          return location;
        } catch (_a) {
          return null;
        }
      }
      return null;
    }
    // 存储缓存位置信息到sessionStorage和localStorage
  }, {
    key: "setLocationToStorage",
    value: function setLocationToStorage(location, expireMS) {
      window.sessionStorage.setItem('position', JSON.stringify(location));
      storage_persistData.savePersist('position', JSON.stringify(location), expireMS);
    }
  }]);
}();

exports["default"] = LocationStorage;
