#pragma once

#include <sstream>

#include <Widgets/Panel.h>
#include <Widgets/Label.h>
#include <Widgets/Organizers/LinearOrganizer.h>
#include <Widgets/Window.h>
#include <Widgets/DialogWindow.h>
#include <Widgets/Listbox.h>

#include "../Assets/Item.h"
#include "../Mechanics/PlayerGame.h"
#include "../Mechanics/Item.h"
#include "Actions.h"
#include <Widgets/LayerWidget.h>

//for vs
#undef interface

namespace interface {

	class EventDisplay : public gge::widgets::DialogWindow {
	public:
		EventDisplay() : ShowingEvent("Showing", this)
		{
			setshowvscroll(false);

			ok.Text="Ok";

			SetDefault(ok);
			SetCancel(ok);

			Resize(280,120);

			text.Resize(240,20);
			text.SetContainer(this);
			text.TextWrap=true;
			text.Autosize=gge::widgets::AutosizeModes::GrowOnly;

			picture.SetContainer(this);

			Title="";

			AddDialogButton(ok);

			Hide();

			ok.ClickEvent.Register(this, &gge::widgets::DialogWindow::Close);

			ClosingEvent.RegisterLambda([&] {
				picture.GetLayer().Clear();
				mechanics::PlayerGame::current().resume();
				cancelCount--;
			});
		}

		virtual void Show(mechanics::MapEvent event) {
			Title=event.title;
			text=event.text;
			if(event.animation) {
				graphics::Animation *anim=dynamic_cast<graphics::Animation*>(event.animation);
				event.animation->setAnimation(North, "");
				picture.Show();
				picture.Resize(anim->getSize());
				anim->draw(picture.GetLayer(), gge::utils::Point(0,0), 1.f);
				text.SetX(picture.GetWidth()+10);
				Resize(text.GetBounds().Right+16, std::max(text.GetHeight(),picture.GetHeight())+80);
			}
			else {
				picture.Hide();
				text.SetX(0);
				Resize(text.GetBounds().Right+16, text.GetHeight()+90);
			}

			ShowingEvent();
			if(!this->IsVisible()) cancelCount++;
			gge::widgets::DialogWindow::Show(true);

			mechanics::PlayerGame::current().pause();
			
			MoveToCenter();
		}



		gge::utils::EventChain<EventDisplay> ShowingEvent;

	protected:
		gge::widgets::Button ok;
		gge::widgets::Label text;
		gge::widgets::LayerWidget picture;

		std::string prev;

	};

}
