use bevy::prelude::*;

use crate::resources::{AppState, Easy};

use super::title::Title;

#[derive(Clone, Copy, Debug)]
pub struct TitlePlugin;

impl Plugin for TitlePlugin {

    fn build(&self, app: &mut App) {
        app
            .add_systems(
                OnEnter(AppState::Title),
                Title::load,
            )
            .add_systems(
                OnExit(AppState::Title),
                Title::unload,
            )
            .add_systems(
                Update,
                Title::key_events.run_if(in_state(AppState::Title)),
            )
            .add_systems(
                Update,
                Title::update_easy_item.run_if(
                    in_state(AppState::Title)
                        .and(resource_changed::<Easy>)
                ),
            )
        ;
    }
}
