use crate::effects::star_field;
use crate::slide::Slide;
use crate::slide_show_config::Context;
use crate::utils::screen_center;
use macroquad::color::BLACK;
use macroquad::prelude::*;

#[derive(Debug, Default)]
pub struct Demo {
    camera_angle: f32,
}

impl Demo {
    pub fn new() -> Box<Self> {
        Box::new(Self::default())
    }
}

impl Slide for Demo {
    fn display(&mut self, ctx: &Context<'_>) {
        clear_background(BLACK);
        star_field();

        push_camera_state();

        let camera_x = self.camera_angle.sin() * 20.0;
        let camera_z = self.camera_angle.cos() * 20.0;
        set_camera(&Camera3D {
            position: vec3(camera_x, 15., camera_z),
            up: vec3(0., 1., 0.),
            target: vec3(0.0, 0.0, 0.0),
            ..Default::default()
        });

        draw_sphere_wires(vec3(0.0, 0.0, 0.0), 6.0, None, RED);

        draw_sphere_wires(vec3(15.0, 0.0, 0.0), 2.0, None, RED);

        draw_sphere_wires(vec3(0.0, 0.0, 15.0), 2.0, None, RED);

        draw_sphere_wires(vec3(-15.0, 0.0, 0.0), 2.0, None, RED);

        draw_sphere_wires(vec3(0.0, 0.0, -15.0), 2.0, None, RED);

        draw_sphere_wires(vec3(15.0, 0.0, 0.0), 2.0, None, RED);

        let diff = 1.0 * get_frame_time();
        self.camera_angle = (self.camera_angle + diff) % 360.0;

        pop_camera_state();

        ctx.slide_show_theme
            .heading_config
            .draw_text("This Ain't No Powerpoint", screen_center());
    }
}
