mod config;
mod effects;
mod slide;
mod slide_show_config;
mod slides;
mod text_drawer;
mod utils;

use crate::config::OnDeckConfig;
use crate::slide_show_config::{Context, SlideShowTheme};
use crate::slides::Slideshow;
use crate::slides::config::SlideDeckConfig;
use crate::text_drawer::{Justified, TextConfigBuilder};
use clap::Parser;
use macroquad::prelude::*;
use std::path::PathBuf;

/// OnDeck Slideshow Viewer
#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Args {
    cfg: PathBuf,
    slideshow_path: PathBuf,
}

fn window_conf() -> Conf {
    Conf {
        window_title: "On Deck".to_owned(),
        fullscreen: true,
        platform: miniquad::conf::Platform {
            ..Default::default()
        },
        ..Default::default()
    }
}

#[macroquad::main(window_conf)]
async fn main() {
    let args = Args::parse();

    let heading = load_ttf_font("fonts/BoldPixels.ttf").await.unwrap();
    let body = load_ttf_font("fonts/ByteBounce.ttf").await.unwrap();

    let slide_show_theme = SlideShowTheme {
        title_config: TextConfigBuilder::default()
            .justification(Justified::Center)
            .font_size(250)
            .font(&heading)
            .color(WHITE)
            .build(),
        heading_config: TextConfigBuilder::default()
            .justification(Justified::CenterHorizontal)
            .font(&heading)
            .color(WHITE)
            .font_size(150)
            .build(),
        body_config: TextConfigBuilder::default()
            .justification(Justified::Left)
            .font(&body)
            .font_size(100)
            .color(WHITE)
            .build(),
    };

    let cfg = OnDeckConfig::new(&args.cfg).unwrap();

    let slide_deck = SlideDeckConfig::new(&args.slideshow_path).unwrap();
    let mut slideshow = Slideshow::new(Context::new(slide_show_theme, cfg), slide_deck).await;

    loop {
        if slideshow.handle_slide_show() {
            return;
        }

        next_frame().await;
    }
}
