#include <vector>
#include <string>
#include <Engine/GGEMain.h>
#include <Widgets/Main.h>

#include "UI.h"

using namespace gge;

const std::string chartype::Names[]={
	"Base model",
	"Wildling",
	"Armor",
	"Weapon",
	"Shield",
	"Hat",
	"Hair",
	"Projectile",
	"Obstacle",
	"Town building",
	"Military building",
	"Den",
	"System"
};


int Application(std::vector<std::string> &args) {
	gge::os::IconHandle icon=0;
	gge::resource::Image iconimage;
	if(iconimage.ImportPNG("cup.png")==gge::resource::Image::NoError)
		icon=gge::os::IconFromImage(iconimage);


	gge::widgets::InitializeApplication("animedit", "LPC Animation Importer", 670, 594, icon);



	UI ui;


	widgets::WidgetLayer filedrop;
	Main.Add(filedrop);

	filedrop.MouseCallback.SetLambda([&](input::mouse::Event::Type event, utils::Point location) -> bool {
		using namespace gge::input::mouse;
		if(event==Event::DragOver || event==Event::DragMove) {
			if(GetDraggedObject().TypeID()==FileListDragData::type) {
				return true;
			}
		}
		else if(event==Event::DragDrop) {
			if(GetDraggedObject().TypeID()==FileListDragData::type) {
				auto &data=dynamic_cast<FileListDragData&>(GetDraggedObject());
				for(auto it=data.data.begin();it!=data.data.end();++it) {
					if(gge::os::filesystem::IsDirectoryExists(*it)) {
						ui.SetDirectory(*it);
					}
					else if(it->substr(it->length()-3)=="png" || it->substr(it->length()-3)=="PNG") {
						ui.FilesToImport.push_back(*it);
					}
					else if(it->substr(it->length()-3)=="wav" || it->substr(it->length()-3)=="WAV") {
						ui.AddSound(*it);
					}
				}

				ui.BeginImport();
				return true;
			}
		}

		return false;
	}, input::mouse::Event::AllButOverCheck);


	gge::Main.Run();

	return 0;
}
