#include "Lod.hpp"
#include "LodSettings.hpp"
#include "Renderable.hpp"
#include "../ui/ComponentRegistration.hpp"
#include "../ui/LodEditor.hpp"
#include "../ui/LodSettingsEditor.hpp"

// Register LodSettings component
REGISTER_COMPONENT("LOD Settings", LodSettingsComponent, LodSettingsEditor)
{
	registry.registerComponent<LodSettingsComponent>(
		"LOD Settings",
		std::make_unique<LodSettingsEditor>(),
		// Adder
		[sceneMgr](flecs::entity e) {
			if (!e.has<LodSettingsComponent>()) {
				auto settings = LodSettingsComponent();
				// Create default LOD levels
				settings.createDefaultLevels();
				e.set<LodSettingsComponent>(settings);
			}
		},
		// Remover
		[sceneMgr](flecs::entity e) {
			if (e.has<LodSettingsComponent>()) {
				e.remove<LodSettingsComponent>();
			}
		}
	);
}

// Register Lod component
REGISTER_COMPONENT("LOD", LodComponent, LodEditor)
{
	registry.registerComponent<LodComponent>(
		"LOD",
		std::make_unique<LodEditor>(),
		// Adder
		[sceneMgr](flecs::entity e) {
			if (!e.has<LodComponent>()) {
				// LOD requires Renderable
				if (!e.has<RenderableComponent>()) {
					// Auto-add renderable if missing (will need mesh assignment later)
					e.set<RenderableComponent>({});
				}
				e.set<LodComponent>({});
			}
		},
		// Remover
		[sceneMgr](flecs::entity e) {
			if (e.has<LodComponent>()) {
				e.remove<LodComponent>();
			}
		}
	);
}
