#include <vector>
#include <string>
#include <Engine/GGEMain.h>
#include <Widgets/Main.h>
#include <algorithm>
#include <Utils/Random.h>
#include <Widgets/Basic/WidgetLayer.h>
#include <Widgets/WidgetRegistry.h>
#include <Resource/FontTheme.h>
#include <Widgets/FullscreenPanel.h>
#include "../Common/FileHandling.h"
#include <Widgets/Panel.h>
#include <Widgets/Tabpanel.h>
#include "UI.h"


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("tileeditor", "Tile Editor", 600, 500, 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);
					}
				}

				ui.BeginImport();

				return true;
			}
		}

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


	gge::Main.Run();

	return 0;
}

const char* Rolee::Names[]={
	"Regular",
	"Single 1",
	"Single 2",
	"Single 3",
	"Single 4",
	"Top left",
	"Top",
	"Top right",
	"Left",
	"Right",
	"Bottom left",
	"Bottom",
	"Bottom right",
	"Diagonal 1", 
	"Diagonal 2", 
	"Diagonal 3", 
	"Diagonal 4", 
	"Random 1",
	"Random 2",
	"Random 3",
	"Random 4",
	"Random 5",
	"Random 6",
};