use super::*;
pub use avian2d::prelude::*;

/// 2D Physics systems, resources, events, etc.
pub struct Physics2dPlugin;

impl Plugin for Physics2dPlugin {
    fn build(&self, app: &mut App) {
        app.add_plugins((PhysicsPlugins::default(), PhysicsDebugPlugin))
            .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::default(),
        DebuggingState::Off => PhysicsGizmos::none(),
    };
}
