/******************************************************************************
*	File		-	map_editor.h
*	Author		-	Joey Pollack
*	Date		-	2022/01/31 (y/m/d)
*	Mod Date	-	2022/01/31 (y/m/d)
*	Description	-	The tile map editor tool. Controls subwindows/panels.
******************************************************************************/

#ifndef MAP_EDITOR_H_
#define MAP_EDITOR_H_

#include <vector>
#include <map>
#include <string>
#include <utils/op_res.h>
#include "../../panel_manager.h"
#include <editor/contents/definitions.h>

namespace lunarium {
    class IGraphics;

    namespace gui {
    class Panel;
    }

namespace editor 
{
    class TileMap;
    class TileSet;
    class Editor;
    class MapEditor
    {
    public:
        MapEditor();

        OpRes Initialize(Editor* editor);
        void Shutdown();
        void OnTick(double delta);
        bool OnRender(lunarium::IGraphics* g);

        void Open();
        void Close();
        bool IsOpen() const;

        void NewMap();
        OpRes LoadMap(std::string map);
        void SaveMap();
        bool IsMapLoaded() const;

        const std::map<int, TileSet*>* GetTileSets() const;

        void ChangeSelectedTile(TileRef tile);

        
    private:
        bool mIsOpen;
        bool mMapLoaded;
        TileMap* mpMap;
        Editor* mpEditor;
        
        PanelManager mPanelManager;
        struct
        {
            uint32_t MapCanvas;
            uint32_t TileSetView;
        } mPanels;

        int mTileSetNextID;
        std::map<int, TileSet*> mTileSets;

        // Menu Events
        bool mImportTileSet;

    private:
        void DoMenu();
        void HandleMenuEvents();
    };
}}

#endif  // MAP_EDITOR_H_