#pragma once
#include <Widgets/Listbox.h>
#include <string>
#include <Widgets/Organizers/LinearOrganizer.h>
#include <Widgets/Button.h>
#include <Widgets/Numberbox.h>
#include <Widgets/Combobox.h>
#include <Utils/StringEnum.h>

class chartype {
public:
	enum Type {
		BaseModel,
		Monster,
		Armor,
		Weapon,
		Shield,
		Hat,
		Hair,
		Projectile,
		Obstacle,
		TownBuilding,
		MilitaryBuilding,
		Den,
		System,
		end
	};

	static const std::string Names[];
};

typedef gge::utils::StringEnum<chartype> CharType;

class CharList {
	friend class UI;
public:
	void SetPanel(widgets::Panel &panel) {
		this->panel=&panel;
		panel.SetOrganizer(organizer);

		organizer.Spacing=1;
		organizer.ButtonAlign=TextAlignment::Center;

		Characters.SetHeight(168);
		Characters.ItemClickedEvent.RegisterLambda([&]{
			DeleteChar.Enable();
			RenameChar.Enable();

			ShowAnims();
		});

		attach.Value=utils::Point(32,64);
		CharType::AddAll(Type);
		Type.SetValue(CharType::end);
		Type.SetValue(CharType::BaseModel);
		BaseColor.UseHex=true;
		BaseColor.Value=0xfff3c3a3;
		//ColorList.Text="fff3c3a3,ffffd3b3,ffffe3c3,fffee3d3,fff0e8d8,fff0b393,ffeece84,ffeede84,ff806030,ff604224";
		SecondColor.UseHex=true;
		SecondColor.Value=0xff50d4ec;

		NewChar.Text="New";
		DeleteChar.Text="Delete";
		DeleteChar.SetWidth(80);
		DeleteChar.Disable();
		RenameChar.Text="Rename";
		RenameChar.SetWidth(80);
		RenameChar.Disable();


		Animations.SetHeight(120);

		Animations.ItemClickedEvent.RegisterLambda([&]{
			DeleteAnim.Enable();
			RenameAnim.Enable();
		});

		NewAnim.Text="New";
		DeleteAnim.Text="Delete";
		DeleteAnim.SetWidth(80);
		DeleteAnim.Disable();
		RenameAnim.Text="Rename";
		RenameAnim.SetWidth(80);
		RenameAnim.Disable();

		organizer
			<<Characters<<organizer.nextline
			<<"Type: "<<Type<<organizer.nextline
			<<"Base color:"<<BaseColor<<organizer.nextline
			<<"Second color:"<<SecondColor<<organizer.nextline
			//<<"Color list: "<<ColorList<<organizer.nextline
			<<"Attachment: "<<attach<<organizer.nextline
			<<NewChar<<organizer.nextline
			<<RenameChar<<DeleteChar<<organizer.nextline
		;

		organizer.NextLine(7);
		organizer.NextLine();

		organizer
			<<Animations<<organizer.nextline
			<<NewAnim<<organizer.nextline
			<<RenameAnim<<DeleteAnim<<organizer.nextline
		;

		organizer.NextLine(10);
		organizer.NextLine();

	}

	void NewFile() {
		Characters.DeleteAll();
		Animations.DeleteAll();
		DeleteChar.Disable();
		RenameChar.Disable();
		DeleteAnim.Disable();
		RenameAnim.Disable();
		HideAnims();
	}

	void HideAnims() {
		Animations.Hide();
		NewAnim.Hide();
		DeleteAnim.Hide();
		RenameAnim.Hide();
	}

	void ShowAnims() {
		Animations.Show();
		NewAnim.Show();
		DeleteAnim.Show();
		RenameAnim.Show();
	}

	~CharList() {
		panel->RemoveOrganizer();
	}


protected:
	widgets::Listbox<std::string> Characters;
	widgets::Listbox<std::string> Animations;


	widgets::Button NewChar;
	widgets::Button RenameChar;
	widgets::Button DeleteChar;

	widgets::Button NewAnim;
	widgets::Button RenameAnim;
	widgets::Button DeleteAnim;
	
	widgets::Combobox<CharType::Type, &CharType::ConvertToString> Type;
	widgets::Numberbox<gge::graphics::RGBint, widgets::FixNumberString<int> > BaseColor;
	widgets::Numberbox<gge::graphics::RGBint, widgets::FixNumberString<int> > SecondColor;
	widgets::Textbox ColorList;

	widgets::LinearOrganizer organizer;
	widgets::Panel *panel;

	widgets::Numberbox<utils::Point> attach;
};
