//! Game-specific [`ActorInspectorSection`] implementations (ADR 0007 dogfood).

use bevy::prelude::*;
use bevy_egui::egui;
use shared::{LevelObject, WeaponSpawn};

use super::extensibility::{register_actor_inspector_section, ActorInspectorSection};

/// Registers inspector sections declared in [`game::editor_ext::actor_inspector_section_ids`].
pub fn register_game_inspector_sections(app: &mut App) {
    for id in game::editor_ext::actor_inspector_section_ids() {
        match *id {
            "game.fps_weapon_stats" => {
                register_actor_inspector_section(app, Box::new(FpsWeaponStatsSection));
            }
            other => {
                warn!("unknown game actor inspector section id: {other}");
            }
        }
    }
}

struct FpsWeaponStatsSection;

impl ActorInspectorSection for FpsWeaponStatsSection {
    fn id(&self) -> &str {
        "game.fps_weapon_stats"
    }

    fn title(&self) -> &str {
        "Weapon Stats (Demo)"
    }

    fn order(&self) -> i32 {
        200
    }

    fn applies_to(&self, world: &World, entity: Entity) -> bool {
        world
            .get_entity(entity)
            .is_ok_and(|e| e.contains::<LevelObject>() && e.contains::<WeaponSpawn>())
    }

    fn ui(&self, _world: &mut World, ui: &mut egui::Ui, entity: Entity) {
        ui.collapsing(self.title(), |ui| {
            ui.label(format!("Entity {entity:?}"));
            ui.small("Registered from `game::editor_ext` — extend with gameplay fields.");
        });
    }
}
