use bevy::prelude::*;

use crate::state::AppState;

pub struct StarMapPlugin;

impl Plugin for StarMapPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(OnEnter(AppState::InGame), setup_star_map)
            .add_systems(OnExit(AppState::InGame), despawn_star_map);
        // .add_systems(
        //     Update,
        //     (/* update systems: pan/zoom, hover, click star systems */)
        //         .run_if(in_state(AppState::InGame)),
        // );
    }
}

// ── Markers ─────────────────────────────────────────────────────────────────

#[derive(Component)]
pub struct StarMapUi;

#[derive(Component)]
pub struct StarMapCamera;

#[derive(Component)]
pub struct StarSystemNode;

// ── Systems ─────────────────────────────────────────────────────────────────

fn setup_star_map(_commands: Commands) {
    // TODO: spawn star map (star systems, hyperspace lanes, viewport camera, HUD)
}

fn despawn_star_map(
    mut commands: Commands,
    query: Query<Entity, Or<(With<StarMapUi>, With<StarMapCamera>, With<StarSystemNode>)>>,
) {
    for entity in &query {
        commands.entity(entity).despawn();
    }
}
