use super::{ComponentInspector, InspectorContext, impl_simple_inspector};
use nightshade::prelude::*;

fn render_layer_ui(
    world: &mut World,
    entity: Entity,
    ui: &mut egui::Ui,
    _context: &mut InspectorContext,
) {
    if let Some(layer) = world.core.get_render_layer_mut(entity) {
        ui.label("Render Layer");

        let mut current_layer = layer.0;
        let layer_before = current_layer;

        ui.horizontal(|ui| {
            ui.radio_value(&mut current_layer, RenderLayer::WORLD, "World");
            ui.radio_value(&mut current_layer, RenderLayer::OVERLAY, "Overlay");
        });

        if current_layer != layer_before {
            layer.0 = current_layer;
        }

        ui.add_space(4.0);
        ui.label(
            egui::RichText::new(match current_layer {
                RenderLayer::WORLD => {
                    "Objects in the world layer render normally with depth testing"
                }
                RenderLayer::OVERLAY => {
                    "Objects in the overlay layer always render on top of the world"
                }
                _ => "Custom layer",
            })
            .small()
            .color(egui::Color32::from_gray(150)),
        );
    }
}

impl_simple_inspector!(
    RenderLayerInspector,
    "Render Layer",
    entity_has_render_layer,
    set_render_layer,
    remove_render_layer,
    RenderLayer::default(),
    render_layer_ui
);
