#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("deneditor", "Den Editor", 450,520, 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);
					}
				}

				return true;
			}
		}

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


	gge::Main.Run();

	return 0;
}
