import _regeneratorRuntime from '@babel/runtime/regenerator';
import { _ as __awaiter } from '../tslib.es6-848120af.js';
import { getGameletPixuiFrame } from './gamelet.mjs';
import { isBrowserInPixui } from './validator.mjs';

/**
 * 读取本地数据，IDE中不生效，在真机上才生效
 * 数据以 app + roleId 为维度隔离存储,。存储的信息如15天不更新，会自动清除。
 * @param key 键
 * @example
 * ```ts
 * const token = await getLocalStorageInPixui('user-token');
 * console.log(token);
 * ```
 */
var getLocalStorageInPixui = function getLocalStorageInPixui(key) {
  return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    return _regeneratorRuntime.wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          if (!isBrowserInPixui()) {
            _context.next = 1;
            break;
          }
          return _context.abrupt("return", localStorage.getItem(key) || '');
        case 1:
          _context.next = 2;
          return getGameletPixuiFrame().GameletAPI.readRoleCookie(key);
        case 2:
          return _context.abrupt("return", _context.sent);
        case 3:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
};
/**
 * 设置本地数据，IDE中不生效，在真机上才生效
 * 数据以 app + roleId 为维度隔离存储,。存储的信息如15天不更新，会自动清除。
 * @param key 键
 * @param value 值
 * @example
 * ```ts
 * await setLocalStorageInPixui('user-token', 'abc123');
 * ```
 */
var setLocalStorageInPixui = function setLocalStorageInPixui(key, value) {
  return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
    return _regeneratorRuntime.wrap(function (_context2) {
      while (1) switch (_context2.prev = _context2.next) {
        case 0:
          if (!isBrowserInPixui()) {
            _context2.next = 1;
            break;
          }
          return _context2.abrupt("return", localStorage.setItem(key, value));
        case 1:
          _context2.next = 2;
          return getGameletPixuiFrame().GameletAPI.writeRoleCookie(key, value);
        case 2:
        case "end":
          return _context2.stop();
      }
    }, _callee2);
  }));
};

export { getLocalStorageInPixui, setLocalStorageInPixui };
