//
// Created by sfd on 25-5-25.
//

#ifndef EDITORLAYER_H
#define EDITORLAYER_H
#include <Hazel.h>

#include "Panels/ContentBroswerPanel.h"
#include "Panels/SceneHierachyPanel.h"

namespace Hazel
{
    class EditorLayer : public Layer
    {
    public:
        EditorLayer();
        virtual ~EditorLayer() = default;

        virtual void OnAttach() override;
        virtual void OnDetech() override;

        virtual void OnUpdate(TimeStep& ts) override;
        virtual void OnImGuiRender() override;
        virtual void OnEvent(SDL_Event& e) override;
    private:
        void UI_ToolBar();

        void OnScenePlay();
        void OnSceneSimulation();
        void OnSceneStop();


        void SaveSceneAs() const;
        void OpenScene();
        void OpenScene(const std::filesystem::path& scenePath);
        void NewScene();
        void SaveScene() const;

        void SerializeScene(Ref<Scene> scene, const std::filesystem::path& scenePath) const;

        void OnDuplicateEntity();

        void ChangeOptMode(unsigned int mode);

        void OnOverLayRender();

    private:
        OrthographicCameraController m_CameraController;

        Ref<Texture2D> m_LogoTexture;
        Ref<Texture2D> m_CheckerBoardTexture;


        Ref<Scene> m_ActiveScene;
        Ref<Scene> m_EditorScene;
        EditorCamera m_EditorCamera;
        std::filesystem::path m_EditorScenePath;

        Entity m_HoveredEntity;

        glm::vec4 m_BackgroundColor = { 0.2f, 0.2f, 0.2f, 1.0f };
        glm::vec4 m_SquareColor = { 0.2f, 0.2f, 0.2f, 1.0f };

        bool m_ViewportFocused = false, m_ViewportHovered = false;
        glm::vec2 m_ViewPortSize = {0, 0};
        glm::vec2 m_ViewPortBounds[2];

        Ref<FrameBuffer> m_FrameBuffer;
        Ref<FrameBuffer> m_RuntimeFrameBuffer;

        SceneHierachyPanel m_SceneHierachyPanel;
        ContentBroswerPanel m_ContentBroswerPanel;

        int m_GizmoType = -1;

        bool m_ShowPhysicsColliders = false;

        enum class SceneState
        {
            Edit = 0, Play = 1, Simulate = 2
        };

        SceneState m_SceneState = SceneState::Edit;

        Ref<Texture2D> m_IconPlay, m_IconStop, m_IconSimulate;
    };
}


#endif //EDITORLAYER_H
