use crate::slide::Slide;
use crate::slide_show_config::Context;
use macroquad::camera::set_default_camera;
use macroquad::input::{KeyCode, is_key_pressed};

pub mod demo;
pub mod standard_slide;
pub mod title;

pub struct Slideshow<'a> {
    pub current_slide: usize,
    pub slides: Vec<Box<dyn Slide>>,
    pub ctx: Context<'a>,
}

impl<'a> Slideshow<'a> {
    pub fn new(ctx: Context<'a>) -> Self {
        Self {
            current_slide: 0,
            slides: vec![],
            ctx,
        }
    }

    pub fn add_slide(&mut self, slide: Box<dyn Slide>) {
        self.slides.push(slide);
    }

    pub fn handle_slide_show(&mut self) -> bool {
        set_default_camera();
        if is_key_pressed(KeyCode::Escape) {
            return true;
        } else if is_key_pressed(KeyCode::Right) {
            self.current_slide += 1;
        } else if is_key_pressed(KeyCode::Left) {
            self.current_slide = self.current_slide.saturating_sub(1);
        }
        self.current_slide = self.current_slide.clamp(0, self.slides.len() - 1);

        self.slides[self.current_slide].display(&self.ctx);

        false
    }
}
