class BuildingWindow
{
    constructor( sparrowUI )
    {
        this.ui = sparrowUI;

        this.building = null;
        
        this.wnd_bg = this.ui.add( new Sparrow.UI.Window( "Building Window" , { x: 200 , y: 200 , width: 280 , height: 230 , backgroundColor: "#ccaa88" , borderColor: "#554433" , textPadding: 5 , textColor: "#ffffff" } ) );
        this.wnd_bg.b_visible = false;

        var yPos = 30;
        this.lbl_line1 = this.wnd_bg.addChild( new Sparrow.UI.Label( "Line 1" , { x: 5 , y: yPos , width: 270 , font: "sans-serif" } ) );
        yPos += 25;
        this.lbl_line2 = this.wnd_bg.addChild( new Sparrow.UI.Label( "Line 2" , { x: 5 , y: yPos , width: 270 , font: "sans-serif" } ) );
        yPos += 25;
        this.lbl_line3 = this.wnd_bg.addChild( new Sparrow.UI.Label( "Line 3" , { x: 5 , y: yPos , width: 270 , font: "sans-serif" } ) );
        yPos += 25;
        this.lbl_line4 = this.wnd_bg.addChild( new Sparrow.UI.Label( "Line 4" , { x: 5 , y: yPos , width: 270 , font: "sans-serif" } ) );
        yPos += 25;
        this.lbl_line5 = this.wnd_bg.addChild( new Sparrow.UI.Label( "Line 5" , { x: 5 , y: yPos , width: 270 , font: "sans-serif" } ) );
        yPos += 30;

        this.btn_upgrade = this.wnd_bg.addChild( new Sparrow.UI.Button( "Upgrade" , { x: 5 , y: yPos , backgroundColor: "#554433" , textColor: "#ffffff" , hover: { backgroundColor: "#776655" } } ) );
        this.btn_upgrade.onclick = () => {
            this.building.upgrade();
        };
        yPos += 35;
        this.btn_demolish = this.wnd_bg.addChild( new Sparrow.UI.Button( "Demolish" , { x: 5 , y: yPos , backgroundColor: "#554433" , textColor: "#ffffff" , hover: { backgroundColor: "#776655" } } ) );
        this.btn_demolish.onclick = () => {
            this.building.demolish();
            game.buildingManager.demolish( this.building );
            this.wnd_bg.b_visible = false;
        };
        yPos += 25;
    }

    update()
    {
        if ( this.wnd_bg.b_visible )
        {
            this.show( this.building );
        }
    }

    show( building )
    {
        this.building = building;
        this.showAllLines();
        if ( building.type === BuildingType.HOUSE )
        {
            if ( building.level === 0 ) this.wnd_bg.setStr( "Mouse Camp" );
            else if ( building.level === 1 ) this.wnd_bg.setStr( "Mouse House" );
            else if ( building.level === 2 ) this.wnd_bg.setStr( "Mouse Apartment" );
            else if ( building.level === 3 ) this.wnd_bg.setStr( "Mouse Tower" );
            this.lbl_line1.setStr( "Level: "+building.level+"/"+building.maxLevel );
            this.lbl_line2.setStr( "Beds: "+building.beds );
            this.lbl_line3.setStr( "Total Beds: "+game.beds );
            this.lbl_line4.setStr( "Homeless: "+game.homeless );
            this.lbl_line5.b_visible = false;
            if ( building.level === 0 ) this.btn_upgrade.setStr( "Upgrade ("+Config.HOUSE_UPGRADE_PRICE_1+")" );
            else if ( building.level === 1 ) this.btn_upgrade.setStr( "Upgrade ("+Config.HOUSE_UPGRADE_PRICE_2+")" );
            else if ( building.level === 2 ) this.btn_upgrade.setStr( "Upgrade ("+Config.HOUSE_UPGRADE_PRICE_3+")" );
            else this.btn_upgrade.b_visible = false;
        }
        else if ( building.type === BuildingType.WATER )
        {
            this.wnd_bg.setStr( "Dew Collector" );
            this.lbl_line1.setStr( "Level: "+building.level+"/"+building.maxLevel );
            this.lbl_line2.setStr( "Production: "+building.waterProduction );
            this.lbl_line3.setStr( "Total Production: "+game.waterProduction );
            this.lbl_line4.setStr( "Storage: "+building.waterStorage );
            this.lbl_line5.setStr( "Total Storage: "+game.waterStorage );
            if ( building.level === 0 ) this.btn_upgrade.setStr( "Upgrade ("+Config.WATER_UPGRADE_PRICE_1+")" );
            else if ( building.level === 1 ) this.btn_upgrade.setStr( "Upgrade ("+Config.WATER_UPGRADE_PRICE_2+")" );
            else this.btn_upgrade.b_visible = false;
        }
        else if ( building.type === BuildingType.FARM )
        {
            this.wnd_bg.setStr( "Farm" );
            this.lbl_line1.setStr( "Level: "+building.level+"/"+building.maxLevel );
            this.lbl_line2.setStr( "Production: "+building.foodProduction );
            this.lbl_line3.setStr( "Total Production: "+game.foodProduction );
            this.lbl_line4.setStr( "Storage: "+building.foodStorage );
            this.lbl_line5.setStr( "Total Storage: "+game.foodStorage );
            if ( building.level === 0 ) this.btn_upgrade.setStr( "Upgrade ("+Config.FARM_UPGRADE_PRICE_1+")" );
            else if ( building.level === 1 ) this.btn_upgrade.setStr( "Upgrade ("+Config.FARM_UPGRADE_PRICE_2+")" );
            else this.btn_upgrade.b_visible = false;
        }
        else if ( building.type === BuildingType.POLICE )
        {
            this.wnd_bg.setStr( "Police" );
            this.lbl_line1.setStr( "Level: "+building.level+"/"+building.maxLevel );
            this.lbl_line2.setStr( "Police Presence: "+building.policeLevel );
            this.lbl_line3.setStr( "Total Police Presence: "+game.policeLevel );
            this.lbl_line4.b_visible = false;
            this.lbl_line5.b_visible = false;
            if ( building.level === 0 ) this.btn_upgrade.setStr( "Upgrade ("+Config.POLICE_UPGRADE_PRICE_1+")" );
            else if ( building.level === 1 ) this.btn_upgrade.setStr( "Upgrade ("+Config.POLICE_UPGRADE_PRICE_2+")" );
            else this.btn_upgrade.b_visible = false;
        }
        else if ( building.type === BuildingType.COMMUNITY_CENTER )
        {
            this.wnd_bg.setStr( "Community Center" );
            this.lbl_line1.setStr( "A source of community and" );
            this.lbl_line2.setStr( "some basic amenities." );
            this.lbl_line3.b_visible = false;
            this.lbl_line4.b_visible = false;
            this.lbl_line5.b_visible = false;
            this.btn_upgrade.b_visible = false;
            this.btn_demolish.b_visible = false;
        }
        this.wnd_bg.b_visible = true;
    }

    showAllLines()
    {
        this.lbl_line1.b_visible = true;
        this.lbl_line2.b_visible = true;
        this.lbl_line3.b_visible = true;
        this.lbl_line4.b_visible = true;
        this.lbl_line5.b_visible = true;
        this.btn_upgrade.b_visible = true;
        this.btn_demolish.b_visible = true;
    }
}