use super::{ComponentInspector, InspectorContext, impl_simple_inspector};
use nightshade::ecs::bounding_volume::components::BoundingVolume;
use nightshade::prelude::*;

fn bounding_volume_ui(
    world: &mut World,
    entity: Entity,
    ui: &mut egui::Ui,
    _context: &mut InspectorContext,
) {
    if let Some(volume) = world.core.get_bounding_volume_mut(entity) {
        ui.label(egui::RichText::new("OBB").strong());

        ui.horizontal(|ui| {
            ui.label("Center:");
            ui.add(
                egui::DragValue::new(&mut volume.obb.center.x)
                    .speed(0.1)
                    .prefix("X: "),
            );
            ui.add(
                egui::DragValue::new(&mut volume.obb.center.y)
                    .speed(0.1)
                    .prefix("Y: "),
            );
            ui.add(
                egui::DragValue::new(&mut volume.obb.center.z)
                    .speed(0.1)
                    .prefix("Z: "),
            );
        });

        ui.horizontal(|ui| {
            ui.label("Half Extents:");
            ui.add(
                egui::DragValue::new(&mut volume.obb.half_extents.x)
                    .speed(0.1)
                    .range(0.0..=f32::MAX)
                    .prefix("X: "),
            );
            ui.add(
                egui::DragValue::new(&mut volume.obb.half_extents.y)
                    .speed(0.1)
                    .range(0.0..=f32::MAX)
                    .prefix("Y: "),
            );
            ui.add(
                egui::DragValue::new(&mut volume.obb.half_extents.z)
                    .speed(0.1)
                    .range(0.0..=f32::MAX)
                    .prefix("Z: "),
            );
        });

        ui.separator();

        ui.horizontal(|ui| {
            ui.label("Sphere Radius:");
            ui.add(
                egui::DragValue::new(&mut volume.sphere_radius)
                    .speed(0.1)
                    .range(0.0..=f32::MAX),
            );
        });
    }
}

impl_simple_inspector!(
    BoundingVolumeInspector,
    "Bounding Volume",
    entity_has_bounding_volume,
    set_bounding_volume,
    remove_bounding_volume,
    BoundingVolume::default(),
    bounding_volume_ui
);
