use crate::core::wave::BubbleWaves;
use bevy::prelude::*;

#[derive(Component)]
struct WaveText;

fn setup_ui(mut commands: Commands) {
    commands.spawn((
        Text::new("Waves : "),
        TextFont { font_size: 32.0, ..default() },
        TextLayout::new_with_justify(Justify::Left),
        WaveText,
    ));
}

fn update_score_text(bubble_wave: Res<BubbleWaves>, text_single: Single<&mut Text, With<WaveText>>) {
    if !bubble_wave.is_changed() {
        return;
    }
    let mut text = text_single.into_inner();
    **text = format!("Wave : {}", bubble_wave.current_wave);
    println!("ui text {:?}", text);
}

pub struct UIPlugin;

impl Plugin for UIPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(Startup, setup_ui).add_systems(Update, update_score_text);
    }
}
