use epub::doc::EpubDoc;
use std::env;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let args: Vec<String> = env::args().collect();
    let epub_path = if args.len() > 1 {
        &args[1]
    } else {
        "./Crafting Engineering Strategy (for Tr... (Z-Library).epub"
    };

    let chapter_idx: usize = args.get(2).and_then(|s| s.parse().ok()).unwrap_or(2);

    println!("Opening EPUB: {epub_path}");

    let mut doc = EpubDoc::new(epub_path)?;

    println!("Total chapters: {}", doc.get_num_chapters());

    doc.set_current_page(chapter_idx);

    if let Some((content, _mime)) = doc.get_current_str() {
        println!("\n=== CHAPTER {} FULL HTML ===\n", chapter_idx);
        println!("{content}");
    }

    Ok(())
}
