#ifndef LEVEL_EDITOR_HPP
#define LEVEL_EDITOR_HPP

#include <view_layer.hpp>

#include <open_engine.hpp>

class LevelEditor : public ViewLayer
{
    public:
        LevelEditor()
            : ViewLayer("level_editor", (float)OpenEngine::Application::Get().GetWindow().GetWidth() /
                    OpenEngine::Application::Get().GetWindow().GetHeight(), 1.0f)
        {
        }

        void OnAttach() override
        {
            OpenEngine::FramebufferSpecification specs;
            specs.width = 1280;
            specs.height = 720;

            GetFramebuffer() = OpenEngine::FrameBuffer::Create(specs);

        };

        void OnUpdate() override
        {
            {
                OE_PROFILE_SCOPE("Setting up Rendering");
                GetCamera().OnUpdate();
                GetFramebuffer()->Bind();
            }

            OpenEngine::RenderCommand::SetClearColor({0.11f, 0.11f, 0.15f, 1.0f});
            OpenEngine::RenderCommand::Clear();

            OpenEngine::Renderer2D::BeginScene(GetCamera().GetCamera());

            for (float y = -5.0f; y < 5.0f; y += 0.5f) {
                for (float x = -5.0f; x < 5.0f; x += 0.5f) {

                    glm::vec4 gradient_color = {(x + 5.0f) / 10.0f, 0.3f, (y + 5.0f) / 10.0f, 1.0f};
                    //OpenEngine::Renderer2D::DrawQuad({{x, y, 0.0f}, glm::vec3(0.45f, 0.45f, 0.0f)}, gradient_color);

                }
            }

            auto& cursor = GetCursorPos();
            OpenEngine::Transform tr5 = {glm::vec3(cursor.x, cursor.y, 0.9f), glm::vec3(0.1f, 0.1f, 0.0f), 0.0f};
            //OpenEngine::Renderer2D::DrawQuad(tr5, {1, 1, 1, 1});

            OpenEngine::Renderer2D::EndScene();

            GetFramebuffer()->Unbind();
        };

        void OnEvent(OpenEngine::Event& event) override
        {
            OE_PROFILE_FUNCTION();
            GetCamera().OnEvent(event);
        };

        void OnDetach() override {};

    private:
};

#endif // LEVEL_EDITOR_HPP
