/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

#pragma once

#include "Base/ITickable.hpp"
#include <memory>
#include <vector>

namespace OpenVulkano::Scene::UI
{
	class UiElement : public ITickable
	{
	public:
		std::vector<std::shared_ptr<UiElement>> children;

		~UiElement() override = default;

		void Tick() override {};

		void Render()
		{
			BeginDraw();
			Draw();
			for(const auto& child : children)
			{
				if (child->ShouldDraw())
					child->Render();
			}
			EndDraw();
		}

	protected:
		virtual void BeginDraw() {};

		virtual void Draw() = 0;

		virtual void EndDraw() {};

		virtual bool ShouldDraw() { return true; }
	};

	class Ui : public UiElement
	{
	public:
		virtual void Init() = 0;

		void Draw() override {}
	};

	class SimpleUi : public Ui
	{
	public:
		void Init() override {}

		void AddElement(const std::shared_ptr<UiElement>& element)
		{
			children.push_back(element);
		}
	};
}
