export class MainMenuScene extends Phaser.Scene {
  constructor() { super('MainMenuScene'); }

  create() {
    const save = this.registry.get('save');
    const { width, height } = this.scale;

    // Background
    this.add.rectangle(width / 2, height / 2, width, height, 0x0d1b2a);

    // Decorative elements
    this.add.rectangle(width / 2, height / 2, width, 2, 0x1a3a5c).setAlpha(0.5);

    // Title
    this.add.text(width / 2, 120, "TYRANT'S EDGE", {
      fontSize: '72px',
      color: '#d4af37',
      stroke: '#000000',
      strokeThickness: 6
    }).setOrigin(0.5);

    this.add.text(width / 2, 190, 'A Collectible Card Game', {
      fontSize: '24px', color: '#888888'
    }).setOrigin(0.5);

    // Gold display
    this.goldText = this.add.text(width - 30, 30, `Gold: ${save.gold}`, {
      fontSize: '24px', color: '#ffd700'
    }).setOrigin(1, 0);

    // Version
    this.add.text(20, height - 20, 'v1.0', {
      fontSize: '14px', color: '#444444'
    }).setOrigin(0, 1);

    const buttons = [
      { label: 'Campaign', scene: 'CampaignScene' },
      { label: 'Skirmish', scene: 'BattleScene', data: { skirmish: true } },
      { label: 'Deck Builder', scene: 'DeckBuilderScene' },
      { label: 'Collection', scene: 'CollectionScene' },
      { label: 'Store', scene: 'StoreScene' },
      { label: 'Fusion Lab', scene: 'FusionScene' }
    ];

    const startY = 310;
    const spacing = 90;

    buttons.forEach((btn, i) => {
      this._makeButton(width / 2, startY + i * spacing, btn.label, () => {
        this.scene.start(btn.scene, btn.data || {});
      });
    });
  }

  _makeButton(x, y, label, callback) {
    const bg = this.add.rectangle(x, y, 400, 65, 0x1a3a5c)
      .setInteractive({ useHandCursor: true })
      .setStrokeStyle(2, 0x4488ff);

    const text = this.add.text(x, y, label, {
      fontSize: '28px', color: '#ffffff'
    }).setOrigin(0.5);

    bg.on('pointerover', () => bg.setFillStyle(0x2a5a8c));
    bg.on('pointerout', () => bg.setFillStyle(0x1a3a5c));
    bg.on('pointerdown', callback);

    return { bg, text };
  }
}
