use super::{ComponentInspector, InspectorContext, impl_simple_inspector};
use nightshade::ecs::mesh::components::InstancedMesh;
use nightshade::prelude::*;

fn add_instanced_mesh(world: &mut World, entity: Entity) {
    world
        .core
        .add_components(entity, nightshade::ecs::world::INSTANCED_MESH);
    world
        .core
        .set_instanced_mesh(entity, InstancedMesh::new("Cube"));
}

fn instanced_mesh_ui(
    world: &mut World,
    entity: Entity,
    ui: &mut egui::Ui,
    _context: &mut InspectorContext,
) {
    if let Some(mesh) = world.core.get_instanced_mesh_mut(entity) {
        ui.horizontal(|ui| {
            ui.label("Mesh Name:");
            ui.text_edit_singleline(&mut mesh.mesh_name);
        });

        ui.horizontal(|ui| {
            ui.label("Instance Count:");
            ui.label(mesh.instance_count().to_string());
        });
    }
}

impl_simple_inspector!(
    InstancedMeshInspector,
    "Instanced Mesh",
    entity_has_instanced_mesh,
    remove_instanced_mesh,
    instanced_mesh_ui,
    custom_add => add_instanced_mesh
);
