package game.locations.alarmClock;

import openfl.events.MouseEvent;
import openfl.events.Event;

import game.locations.Location;

import base.GameSprite;
import base.Fade;

class AlarmClock extends Location {
  var alarm: Alarm;

  public function new() {
    super();

    id = 'alarmClock';

    addBmpLayer('bg');

    alarm = new Alarm();
    alarm.x = 70;
    alarm.y = 125;
    alarm.addEventListener('wokeup', function(e: Event) {
      rightLocation = game.locations.elevatorHall.ElevatorHall;
    });
    addChild(alarm);

    var igdcLogo = new GameSprite('assets/intro/igdc_logo.png', false);
    addChild(igdcLogo);

    addChild(new Fade('in', 5));

    timer(7, function() {
      igdcLogo.tween({ alpha: 0 }, 3).then(function() {
        removeChild(igdcLogo);

        var title = new GameSprite('assets/intro/title.png');
        title.alpha = 0;
        addChild(title);

        timer(1, function() {
          title.tween({alpha: 1}, 3).then(function() {
            var playButton = new GameSprite('assets/intro/play.png', true);
            playButton.x = Main.SCREEN_WIDTH / 2;
            playButton.y = Main.SCREEN_HEIGHT / 2;
            playButton.alpha = 0;
            playButton.tween({ alpha: 1 }, 1).then(function() {
              playButton.buttonMode = true;
              playButton.addEventListener(MouseEvent.MOUSE_OUT, function(e: MouseEvent) {
                playButton.alpha = 0.8;
              });

              playButton.addEventListener(MouseEvent.MOUSE_OVER, function(e: MouseEvent) {
                playButton.alpha = 1;
                Game.currentGame.playSound('sound/ui/menu_item.ogg');
              });

              playButton.addEventListener(MouseEvent.MOUSE_DOWN, function(e: MouseEvent) {
                Game.currentGame.playSound('sound/ui/menu_selected.ogg');
                playButton.mouseEnabled = false;

                playButton.tween({ alpha: 0 }, 1);
                title.tween({ alpha: 0 }, 1).then(function() {
                  removeChild(playButton);
                  removeChild(title);
                  alarm.start();
                });
              });
            });
            addChild(playButton);
          });
        });
      });
    });
  }
}
