use bevy::{input::gamepad::GamepadEvent, prelude::*};

pub struct GamepadPlugin;

impl Plugin for GamepadPlugin {
	fn build(&self, app: &mut App) {
		app.add_systems(Startup, setup);
	}
}

#[derive(Debug, Resource)]
pub struct GamepadOne(pub Gamepad);

fn setup(
	commands: Commands,
	gamepad1: Option<Res<GamepadOne>>,
	mut gamepad_events: EventReader<GamepadEvent>,
) {
	for event in gamepad_events.read() {
		let GamepadEvent::Connection(conn) = event
		else {
			continue;
		};

		// match &conn.connection {
		// 	GamepadConnection::Connected(_) => {
		// 		if gamepad1.is_none() {
		// 			commands.insert_resource(GamepadOne(conn.gamepad));
		// 		}
		// 	}
		// 	GamepadConnection::Disconnected => {
		// 		if let Some(GamepadOne(id)) = gamepad1.as_deref() {
		// 			if *id == conn.gamepad {
		// 				commands.remove_resource::<GamepadOne>();
		// 			}
		// 		}
		// 	}
		// }
	}
}
