/*
PolyGun

Copyright (c) 2023 kacperks https://kacperks.cubesoftware.xyz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef POLYGUN_GUI_COMPONENT_HPP
#define POLYGUN_GUI_COMPONENT_HPP

#include <glm/glm.hpp>
#include <string>

namespace polygun::renderer {
	class GUIRenderer;
}

namespace polygun::window {
	struct Event;
}

namespace polygun::xml {
	class XMLNode;
}

namespace polygun::gui {
	class Constraint;
	class Container;

	class Component {
	public:
		Component(Constraint* x, Constraint* y, Constraint* width, Constraint* height, const std::string& id);
		Component(xml::XMLNode* node);
		virtual ~Component();

		void set_x(Constraint* x);
		void set_y(Constraint* y);
		void set_width(Constraint* width);
		void set_height(Constraint* height);
		void set_next_component(Component* component) { m_next_component = component; }
		void set_prev_component(Component* component) { m_prev_component = component; }
		void set_parent(Container* parent);
		float get_x() const;
		float get_y() const;
		float get_width() const;
		float get_height() const;
		float get_right() const { return get_x()+get_width(); }
		float get_bottom() const { return get_y()+get_height(); }
		Component* get_next_component() { return m_next_component; }
		Component* get_prev_component() { return m_prev_component; }
		const std::string& get_id() const { return m_id; }
		bool is_inactive() const { return m_inactive; }
		bool is_highlighted() const { return m_highlighted; }
		float get_top_margin() const { return m_top_margin; }
		float get_bottom_margin() const { return m_bottom_margin; }
		float get_left_margin() const { return m_left_margin; }
		float get_right_margin() const { return m_right_margin; }

		virtual void set_inactive(bool inactive) { m_inactive = inactive; }
		virtual void set_highlighted(bool highlighted) { m_highlighted = highlighted; }
		virtual void render(renderer::GUIRenderer* renderer) = 0;
		virtual bool update(const window::Event& event) = 0;

	private:
		Constraint* m_x;
		Constraint* m_y;
		Constraint* m_width;
		Constraint* m_height;
		Component* m_next_component;
		Component* m_prev_component;

	protected:
		Container* m_parent;
		std::string m_id;
		bool m_inactive;
		bool m_highlighted;
		float m_top_margin;
		float m_bottom_margin;
		float m_left_margin;
		float m_right_margin;
	};
}


#endif // POLYGUN_GUI_COMPONENT_HPP
