use super::ComponentInspector;
use nightshade::prelude::*;

pub struct MeshInspector;

const MESH_TYPES: &[&str] = &["Cube", "Sphere", "Plane", "Cylinder", "Cone", "Torus"];

impl ComponentInspector for MeshInspector {
    fn name(&self) -> &str {
        "Mesh"
    }

    fn has_component(&self, world: &World, entity: Entity) -> bool {
        world.entity_has_render_mesh(entity)
    }

    fn add_component(&self, world: &mut World, entity: Entity) {
        world.set_render_mesh(entity, RenderMesh::default());
    }

    fn remove_component(&self, world: &mut World, entity: Entity) {
        world.remove_render_mesh(entity);
    }

    fn ui(&mut self, world: &mut World, entity: Entity, ui: &mut egui::Ui) {
        if let Some(mesh) = world.get_render_mesh_mut(entity) {
            ui.label("Mesh Type:");
            egui::ComboBox::from_id_salt("mesh_type")
                .selected_text(&mesh.name)
                .show_ui(ui, |ui| {
                    for mesh_type in MESH_TYPES {
                        ui.selectable_value(&mut mesh.name, mesh_type.to_string(), *mesh_type);
                    }
                });
        }
    }
}
