#pragma once

#include "Menu.h"
#include <Utils/Collection.h>
#include <Utils/Size2D.h>
#include <Utils/Point2D.h>
#include <Engine/GGEMain.h>
#include <Widgets/Base/VirtualPanel.h>
#include <Widgets/WidgetRegistry.h>
#include <Effects/Tinting.h>
#include <Widgets/Panel.h>


namespace gaming { namespace menu {

	//Hides a menu using alpha animation
	class AlphaHider : public IHider {
		friend class Menu::Factory;
	public:


		virtual void Setup(Menu&);
		virtual void Hide(bool);
		virtual void Show(bool);

		virtual void Load(gge::resource::DataArray &);


		static IHider *Create() { return new AlphaHider(); }


		~AlphaHider();

	protected:
		AlphaHider();

		Menu *parent;

		int duration;
		gge::graphics::Colorizable2DLayer	layer;
		gge::effects::Tinting				tinting;
		gge::animation::Controller			controller;

		enum {
			None,
			Showing,
			Hiding
		} Operation;


		void animationcomplete();
	};

	//Alpha minimizer
	class AlphaMinimizer : public IMinimizer {
		friend class Menu::Factory;
		friend class Menu;
	public:
		virtual void Setup(Menu& menu);

		virtual void Minimize(bool);;

		virtual void Refresh();

		virtual void Restore (bool);;

		virtual void Load(gge::resource::DataArray &data);


		~AlphaMinimizer() {
			gge::widgets::WR.LoadedEvent.Register(this, &AlphaMinimizer::wr_loaded);
		}

		static IMinimizer *Create() { return new AlphaMinimizer(); }
	protected:
		void restore_click() {
			parent->Restore();
		}

		gge::widgets::VirtualPanel		vp;
		gge::widgets::Button			btn;

		gge::effects::Tinting				btntinting;
		gge::effects::Tinting				mintinting;
		gge::animation::Controller			btncontroller;
		gge::animation::Controller mincontroller;

		int duration;
		bool alwaysvisible;
		bool bp;

		enum {
			None,
			Minimizing,
			Restoring
		} Operation;

		Menu *parent;

		gge::graphics::Colorizable2DLayer minimizerlayer;
		gge::graphics::Colorizable2DLayer buttonlayer;
		void wr_loaded() {
			if(!gge::widgets::WR.Buttons.Decorative || bp) return;

			btn.SetBlueprint(gge::widgets::WR.Buttons.Decorative);
		}


		AlphaMinimizer();

		void animationcomplete();
	};

} }