/* sys.magic.module.js — Magic System module (FULL override)
   - Ensures schema/params for K (Repeated Times) = [2,3,4,5,6], default [3], type multi-select
   - Hides (does not define) Proposed-by-Group, Blacklist, Clear
   - Exposes minimal hooks to stay compatible
*/

window.PP = window.PP || {};
PP.Systems = PP.Systems || {};
PP.registerSystem = PP.registerSystem || function (cfg) {
  if (!cfg || !cfg.id) return;
  PP.Systems[cfg.id] = Object.assign({}, PP.Systems[cfg.id] || {}, cfg);
};
PP.getParams = PP.getParams || function (sysId) {
  return (PP.Systems[sysId] && PP.Systems[sysId].params) ? PP.Systems[sysId].params : {};
};
PP.saveParams = PP.saveParams || function (sysId, params) {
  const sys = PP.Systems[sysId];
  if (!sys) return;
  sys.params = Object.assign({}, sys.params || {}, params || {});
};

(function(){
  const MAGIC_ID = 'magic';

  const defaults = {
    repeats: [3]   // default 3x
  };

  // Register/override MAGIC system
  PP.registerSystem({
    id: MAGIC_ID,
    name: 'Magic System',
    // Canonical params schema for UI
    params: Object.assign({
      repeats: {
        type: 'multi-select',
        label: 'Repeated Times (K)',
        options: [2,3,4,5,6],
        default: [3],
        help: 'Select one or more repetition thresholds.'
      }
      // Intentionally NOT defining:
      // - proposedByGroup (checkbox)
      // - blacklist (text)
      // - clear button
    }, PP.getParams(MAGIC_ID)),
    // Hooks (no-op stubs; leave existing engine intact)
    init: function(ctx){ /* keep engine intact */ },
    compute: function(ctx){ /* leave to existing logic if any */ },
    onSpin: function(n, ctx){ /* noop */ }
  });

  // Ensure runtime params exist
  const cur = PP.getParams(MAGIC_ID);
  if (!Array.isArray(cur.repeats) || !cur.repeats.length) {
    PP.saveParams(MAGIC_ID, { repeats: defaults.repeats.slice() });
  }

  // Signal ready
  try{ document.dispatchEvent(new CustomEvent('pp:system:ready', {detail:{system: MAGIC_ID}})); }catch(_){}
})();
