#pragma once
#include <Widgets/Panel.h>
#include <Widgets/Label.h>
#include "../Mechanics/PlayerGame.h"
#include <sstream>
#include "../Assets/Constants.h"

//for vs
#undef interface

namespace interface {

	class Resources : public gge::widgets::Panel {

	public:

		Resources() {
			setshowvscroll(false);
			
			gold.Icon=gge::widgets::WR.Icons("gold");
			gold.SetBlueprint(gge::widgets::WR.Labels.Hint);
			gold.Text=" -- ";
			gold.SetWidth(80);
			gold.SetY(3);
			gold.Autosize=gge::widgets::AutosizeModes::None;
			gold.SetContainer(this);


			population.Icon=gge::widgets::WR.Icons("citizen");
			population.SetBlueprint(gge::widgets::WR.Labels.Hint);
			population.Text=" -- ";
			population.SetWidth(60);
			population.SetY(3);
			population.SetX(gold.GetBounds().Right+ 30);
			population.Autosize=gge::widgets::AutosizeModes::None;
			population.SetContainer(this);

			soldiers.Icon=gge::widgets::WR.Icons("soldier");
			soldiers.SetBlueprint(gge::widgets::WR.Labels.Hint);
			soldiers.Text=" -- ";
			soldiers.SetWidth(60);
			soldiers.SetY(3);
			soldiers.SetX(population.GetBounds().Right+ 30);
			soldiers.Autosize=gge::widgets::AutosizeModes::None;
			soldiers.SetContainer(this);

			happiness.Icon=gge::widgets::WR.Icons("happiness");
			happiness.SetBlueprint(gge::widgets::WR.Labels.Hint);
			happiness.Text=" -- ";
			happiness.SetWidth(50);
			happiness.SetY(3);
			happiness.SetX(soldiers.GetBounds().Right+ 30);
			happiness.Autosize=gge::widgets::AutosizeModes::None;
			happiness.SetContainer(this);

			taxRate.Icon=gge::widgets::WR.Icons("taxrate");
			taxRate.SetBlueprint(gge::widgets::WR.Labels.Hint);
			taxRate.Text=" -- ";
			taxRate.SetWidth(40);
			taxRate.SetY(3);
			taxRate.SetX(happiness.GetBounds().Right+ 30);
			taxRate.Autosize=gge::widgets::AutosizeModes::None;
			taxRate.SetContainer(this);

			time.Icon=gge::widgets::WR.Icons("time");
			time.SetBlueprint(gge::widgets::WR.Labels.Hint);
			time.Text=" -- ";
			time.SetWidth(95);
			time.SetY(3);
			time.SetX(taxRate.GetBounds().Right+ 30);
			time.Autosize=gge::widgets::AutosizeModes::None;
			time.SetContainer(this);

			Padding=2;
			Move(15, -8);
			Resize(550, 40);

			SetContainer(gge::widgets::TopLevel);

			gge::Main.BeforeRenderEvent.Register(this, &Resources::update);
		}

		void update() {
			if(!mechanics::PlayerGame::isInGame()) return;

			std::stringstream ss;
			ss << mechanics::PlayerGame::current().gold();
			if(mechanics::PlayerGame::current().income()>=0)
				ss<<" +"<<mechanics::PlayerGame::current().income();
			else
				ss<<" "<<mechanics::PlayerGame::current().income();

			gold.Text=ss.str();
			ss.str("");

			ss << mechanics::PlayerGame::current().getCitizensAlive() << "/" << mechanics::PlayerGame::current().populationLimit();
			population.Text=ss.str();
			ss.str("");

			ss << mechanics::PlayerGame::current().getUnitCount() << "/" << mechanics::PlayerGame::current().soldierHousing();
			soldiers.Text=ss.str();
			ss.str("");

			ss << (int)mechanics::PlayerGame::current().getCurrentHappiness();
			happiness.Text=ss.str();
			ss.str("");
	
			ss << mechanics::PlayerGame::current().taxRate();
			taxRate.Text=ss.str();
			ss.str("");


			ss << "Day: " << (inGameTime / 86400) + 1  << ", " << std::fixed << std::setw(2) << std::setfill('0') << (inGameTime / 3600) % 24 << ":" << std::fixed << std::setw(2) << std::setfill('0') << (inGameTime / 60) % 60;
			time.Text=ss.str();
			ss.str("");
		}


	protected:
		gge::widgets::Label gold, population, soldiers, happiness, taxRate, time;

	};

};
