// Preload — load assets with a progress bar.
window.PreloadScene = class PreloadScene extends Phaser.Scene {
  constructor() { super('Preload'); }

  preload() {
    const W = window.GAME.WIDTH, H = window.GAME.HEIGHT;
    const accent = Phaser.Display.Color.HexStringToColor(window.GAME.ACCENT).color;

    // ---- progress bar UI ----
    const barW = W * 0.6, barH = 22;
    const barX = (W - barW) / 2, barY = H / 2;
    const box = this.add.graphics();
    const bar = this.add.graphics();
    box.fillStyle(0x222233, 0.9).fillRoundedRect(barX - 4, barY - 4, barW + 8, barH + 8, 8);
    const label = this.add.text(W / 2, barY - 36, 'LOADING', {
      fontFamily: 'Arial', fontSize: '20px', color: '#ffffff', fontStyle: 'bold',
    }).setOrigin(0.5);
    const pct = this.add.text(W / 2, barY + barH + 24, '0%', {
      fontFamily: 'Arial', fontSize: '16px', color: '#9aa',
    }).setOrigin(0.5);

    this.load.on('progress', (v) => {
      bar.clear();
      bar.fillStyle(accent, 1).fillRoundedRect(barX, barY, barW * v, barH, 6);
      pct.setText(Math.round(v * 100) + '%');
    });
    this.load.on('complete', () => { box.destroy(); bar.destroy(); label.destroy(); pct.destroy(); });

    // =========================================================
    // ASSET LIST  ——  EDIT POINT #1 (assets)
    // Replace these with the images gen-assets.mjs produced.
    // The template ships with no image files so it can run
    // standalone; if a file is missing Phaser just skips it.
    // =========================================================
    // this.load.image('bg',   'assets/bg.png');
    // this.load.image('hero', 'assets/hero.png');
    // this.load.image('good', 'assets/good.png');
    // this.load.image('bad',  'assets/bad.png');

    // Tiny fake load so the bar always animates even with no assets.
    for (let i = 0; i < 8; i++) {
      this.load.image('__warm' + i,
        'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+M8AAAMBAQDJ/pLvAAAAAElFTkSuQmCC');
    }
  }

  create() {
    this.scene.start('Menu');
  }
};
