/* CALC1 platform adapter — free_forever direct offline. Placeholder unlock only. No live payment. */
(function () {
  'use strict';
  var CART_ID = 'CALC1';
  var NS = 'occ_cartridge::' + CART_ID + '::';
  function k(key) { return NS + key; }
  function lsGet(key) { try { return localStorage.getItem(k(key)); } catch (e) { return null; } }
  function lsSet(key, val) { try { localStorage.setItem(k(key), val); return true; } catch (e) { return false; } }
  window.CartridgePlatform = {
    getDistributionMode: function () { return 'direct_web_offline'; },
    getBillingMode: function () { return 'none_free_forever'; },
    getLanguage: function () { var l = lsGet('lang'); return (l === 'en' || l === 'es') ? l : 'en'; },
    setLanguage: function (l) { if (l === 'en' || l === 'es') lsSet('lang', l); return this.getLanguage(); },
    requestUnlock: function () {
      return Promise.resolve({
        status: 'free_forever',
        unlocked: true,
        mode: 'none_free_forever',
        message: 'CALC1 is free forever. No unlock required.'
      });
    },
    getReferralCode: function () { return null; },
    getGoldenTicket: function () { return null; },
    getMemberId: function () { return null; },
    saveLocalData: function (key, val) { return lsSet(key, val); },
    loadLocalData: function (key) { return lsGet(key); },
    exportUserData: function () {
      var out = {}, i, key;
      try {
        for (i = 0; i < localStorage.length; i++) {
          key = localStorage.key(i);
          if (key && key.indexOf(NS) === 0) out[key.slice(NS.length)] = localStorage.getItem(key);
        }
      } catch (e) {}
      return out;
    },
    resetLocalData: function () {
      var rm = [], i, key;
      try {
        for (i = 0; i < localStorage.length; i++) {
          key = localStorage.key(i);
          if (key && key.indexOf(NS) === 0) rm.push(key);
        }
        rm.forEach(function (x) { localStorage.removeItem(x); });
      } catch (e) {}
      return true;
    }
  };
})();
