import Phaser from 'phaser';
import { sfx } from '../game/audio';

/**
 * Title card, launched as an overlay over the live stage so the dev harness is
 * available underneath from frame one. Click anywhere to begin — that click also
 * unblocks audio, so the shamisen sting lands on entry.
 */
export class Title extends Phaser.Scene {
  constructor() {
    super('title');
  }

  create(): void {
    const W = this.scale.width, H = this.scale.height;
    this.add.rectangle(W / 2, H / 2, W, H, 0x0a0705, 0.82);

    if (this.textures.exists('title_art')) {
      this.add.image(W / 2, H * 0.38, 'title_art').setScale(0.62).setDepth(1);
    }

    this.add.text(W / 2, H * 0.66, 'サンドニエット', { fontFamily: 'serif', fontSize: '56px', color: '#efe4cb' })
      .setOrigin(0.5).setDepth(1);
    this.add.text(W / 2, H * 0.72, 'S A N D O N I E T T E', { fontFamily: 'serif', fontSize: '20px', color: '#c8a24a' })
      .setOrigin(0.5).setDepth(1);

    const shout = this.add.text(W / 2, H * 0.85, 'SHUBATTO!!  SANDONIETTE!!!', {
      fontFamily: 'serif', fontSize: '22px', color: '#e8b84a', fontStyle: 'bold',
    }).setOrigin(0.5).setDepth(1);
    this.tweens.add({ targets: shout, scale: 1.12, duration: 600, yoyo: true, repeat: -1, ease: 'Sine.inOut' });

    const hint = this.add.text(W / 2, H * 0.93, 'click to begin', { fontFamily: 'serif', fontSize: '15px', color: '#9a8a6a' })
      .setOrigin(0.5).setDepth(1);
    this.tweens.add({ targets: hint, alpha: 0.3, duration: 900, yoyo: true, repeat: -1 });

    this.input.once('pointerdown', () => {
      sfx.enable();
      sfx.gong();
      sfx.shamisen();
      this.scene.stop();
    });
  }
}
