export var SALES_SDK_SAVE_CONFIRM_PREFERENCES_KEY = 'pisell.sales-sdk.save-confirm-preferences';
var LEGACY_ADJUST_TIME_PREFERENCES_KEY = 'pisell.adjust-time.modal-preferences';
/**
 * 读取 SalesSdk 保存确认偏好；兼容旧加时弹窗写入的跳过确认记录。
 */
export var readSalesSdkSaveConfirmPreferences = function readSalesSdkSaveConfirmPreferences() {
  if (typeof window === 'undefined') return undefined;
  try {
    var _window$localStorage, _window$localStorage2;
    var raw = (_window$localStorage = window.localStorage) === null || _window$localStorage === void 0 ? void 0 : _window$localStorage.getItem(SALES_SDK_SAVE_CONFIRM_PREFERENCES_KEY);
    if (raw) {
      var parsed = JSON.parse(raw);
      return {
        skipSaveConfirm: parsed.skipSaveConfirm === true
      };
    }
    var legacyRaw = (_window$localStorage2 = window.localStorage) === null || _window$localStorage2 === void 0 ? void 0 : _window$localStorage2.getItem(LEGACY_ADJUST_TIME_PREFERENCES_KEY);
    if (!legacyRaw) return undefined;
    var legacyParsed = JSON.parse(legacyRaw);
    return {
      skipSaveConfirm: legacyParsed.skipSaveConfirm === true
    };
  } catch (error) {
    return undefined;
  }
};

/** 单独写入通用保存确认偏好，避免影响其他业务草稿缓存。 */
export var writeSalesSdkSkipSaveConfirm = function writeSalesSdkSkipSaveConfirm(skipSaveConfirm) {
  if (typeof window === 'undefined') return;
  try {
    var _window$localStorage3;
    (_window$localStorage3 = window.localStorage) === null || _window$localStorage3 === void 0 || _window$localStorage3.setItem(SALES_SDK_SAVE_CONFIRM_PREFERENCES_KEY, JSON.stringify({
      skipSaveConfirm: skipSaveConfirm
    }));
  } catch (error) {
    // localStorage 可能被浏览器策略禁用，失败时不阻断保存流程。
  }
};

/** 当前保存入口是否需要直接跳过二次确认。 */
export var shouldSkipSalesSdkSaveConfirm = function shouldSkipSalesSdkSaveConfirm() {
  var _readSalesSdkSaveConf;
  return ((_readSalesSdkSaveConf = readSalesSdkSaveConfirmPreferences()) === null || _readSalesSdkSaveConf === void 0 ? void 0 : _readSalesSdkSaveConf.skipSaveConfirm) === true;
};