use super::*;
pub use avian3d::prelude::*;

/// 3D Physics systems, resources, events, etc.
pub struct Physics3dPlugin;

impl Plugin for Physics3dPlugin {
    fn build(&self, app: &mut App) {
        app.add_plugins((PhysicsDebugPlugin, PhysicsPlugins::default()))
            .add_systems(
                Update,
                toggle_physics_debug_render.run_if(state_changed::<DebuggingState>),
            );
    }
}

fn toggle_physics_debug_render(
    state: Res<State<DebuggingState>>,
    mut config_store: ResMut<GizmoConfigStore>,
) {
    let (_, config) = config_store.config_mut::<PhysicsGizmos>();
    *config = match state.get() {
        // TODO: Not all, don't want to hide mesh
        DebuggingState::On => PhysicsGizmos::all(),
        DebuggingState::Off => PhysicsGizmos::none(),
    };
}
