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

pub struct NameInspector;

impl ComponentInspector for NameInspector {
    fn name(&self) -> &str {
        "Name"
    }

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

    fn add_component(&self, world: &mut World, entity: Entity) {
        world.set_name(entity, Name("New Entity".to_string()));
    }

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

    fn ui(&mut self, world: &mut World, entity: Entity, ui: &mut egui::Ui) {
        if let Some(Name(name)) = world.get_name_mut(entity) {
            ui.label("Name");
            ui.text_edit_singleline(name);
        }
    }
}
