var EHDI = EHDI || Object.create(null);

EHDI.popup = EHDI.popup || Object.create(null);

EHDI.popup.ConfirmationPopup = function(onClickYes, onClickNo) {
    EHDI.aka.Container.call(this);
    this.confirmationContainer,this.overlay = null, this.btnYes, this.btnNo;
    this.headerTxt = null;
    this.confirmTxt = null;
    this.interactive = true;
    this.onYesClick = onClickYes || null;
    this.onNoClick = onClickNo || null;
};

EHDI.popup.ConfirmationPopup.prototype = Object.create(EHDI.aka.Container.prototype);

EHDI.popup.ConfirmationPopup.prototype.popUpWillAppear = function() {
    this.overlay = new EHDI.aka.Graphics();
    this.overlay.beginFill(0x000000);
    this.overlay.drawRect(0, 0, EHDI.GAME.sceneManager.getStageWidth(), EHDI.GAME.sceneManager.getStageHeight());
    this.overlay.alpha = 0.5;
    this.overlay.visible = false;

    this.confirmationContainer = new EHDI.aka.Sprite(EHDI.Assets.images["gfx_pop2"]);
    this.confirmationContainer.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.5, EHDI.GAME.sceneManager.getStageHeight() * 0.5);
    this.confirmationContainer.anchor.set(0.5,0.5);

    this.btnYes = new EHDI.displays.Button(EHDI.Assets.images["check-button1"], EHDI.Assets.images["check-button2"]);
    this.btnYes.setOnClickFunction(this.btnYesClick.bind(this));
    this.btnYes.x = (this.confirmationContainer.x + (this.confirmationContainer.width * 0.25));
    this.btnYes.y = (this.confirmationContainer.y);

    this.btnNo = new EHDI.displays.Button(EHDI.Assets.images["x-button1"], EHDI.Assets.images["x-button2"]);
    this.btnNo.setOnClickFunction(this.btnNoClick.bind(this));
    this.btnNo.x = (this.confirmationContainer.x - (this.confirmationContainer.width * 0.25));
    this.btnNo.y = (this.confirmationContainer.y);

    this.addChild(this.overlay);
    this.addChild(this.confirmationContainer);
};

EHDI.popup.ConfirmationPopup.prototype.popUpDidAppear = function() {
    //this.overlay.alpha = 0.5;


    // this.headerTxt = new EHDI.aka.PixiText("ARE YOU SURE?", {fontFamily: "Exo-Bold", fill: 0xFFFFFF, fontSize : 40});
    this.headerTxt = new EHDI.displays.TextSprite(EHDI.GAME.JSONMgr.getLocale("LBL_CONFIRM_HEADER"));
    this.headerTxt.anchor.set(0.5, 0.5);
    this.headerTxt.position.set(-this.confirmationContainer.width * 0.2, -this.confirmationContainer.width * 0.18);

    this.confirmationContainer.addChild(this.headerTxt);

    this.overlay.visible = true;
    this.addChild(this.btnYes);
    this.addChild(this.btnNo);

};

EHDI.popup.ConfirmationPopup.prototype.btnYesClick = function(){
    EHDI.GAME.soundManager.playSFX("button_sfx");
    if(this.onYesClick){
        this.onYesClick();
        EHDI.GAME.sceneManager.popPopUp();
    }else{
        EHDI.GAME.sceneManager.popPopUp();
    }
};

EHDI.popup.ConfirmationPopup.prototype.btnNoClick = function(){
    EHDI.GAME.soundManager.playSFX("button_sfx");
    if(this.onNoClick){
        this.onNoClick();
    }else{
        EHDI.GAME.sceneManager.popPopUp();
    }
};

EHDI.popup.ConfirmationPopup.prototype.setHeader = function(format){
    this.headerTxt = new EHDI.displays.TextSprite(format);
    this.headerTxt.anchor.set(0.5,0.5);
};

EHDI.popup.ConfirmationPopup.prototype.setMessage = function(format){
    this.confirmTxt = new EHDI.displays.TextSprite(format);
    this.confirmTxt.anchor.set(0.5,1);
    this.confirmTxt.y = -10;
};

EHDI.popup.ConfirmationPopup.prototype.popUpDidDisappear = function(){
  this.btnYes.dispose();
  delete this.btnYes;
  this.btnNo.dispose();
  delete this.btnNo;
  this.overlay.destroy();
  delete this.overlay;
  this.confirmationContainer.destroy({children: true});
  delete this.confirmationContainer;
  delete this.onClickYes;
  delete this.onClickNo;
  this.destroy({children: true});
};