use bevy::prelude::*;

use crate::resources::AppState;

use super::gameplay::Gameplay;

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

impl Plugin for GameplayPlugin {

    fn build(&self, app: &mut App) {
        app
            .add_systems(
                OnEnter(AppState::Gameplay),
                Gameplay::load,
            )
            .add_systems(
                OnExit(AppState::Gameplay),
                Gameplay::unload,
            )
            .add_systems(
                Update,
                Gameplay::update_background.run_if(in_state(AppState::Gameplay)),
            )
            .add_systems(
                Update,
                Gameplay::update_time.run_if(in_state(AppState::Gameplay))
            )
            .add_systems(
                Update,
                Gameplay::check_gameover.run_if(in_state(AppState::Gameplay))
            )
            .add_systems(
                Update,
                Gameplay::watch_click.run_if(in_state(AppState::Gameplay)),
            )
            .add_systems(
                Update,
                Gameplay::watch_focus.run_if(in_state(AppState::Gameplay))
            )
            .add_systems(
                Update,
                Gameplay::key_events.run_if(in_state(AppState::Gameplay)),
            )
        ;
    }
}
