mod cli;
pub mod watcher;

use clap::Parser;
use cli::{Cli, Commands};
use watcher::FileWatcher;

#[tokio::main]
async fn main() {
    let cli = Cli::parse();

    match cli.command {
        Commands::Serve {
            interface,
            port,
            open,
        } => {
            println!("Starting server on {}:{}", interface, port);
            if open {
                println!("Browser will open automatically");
            }

            // Initialize file watcher
            let mut watcher = FileWatcher::new().expect("Failed to create file watcher");

            // Watch current directory
            watcher
                .watch(".")
                .expect("Failed to watch current directory");

            // Add event handler
            watcher
                .on_change(|event| {
                    println!("File change detected: {:?}", event);
                    println!("  Paths: {:?}", event.paths);
                    println!("  Kind: {:?}", event.kind);
                })
                .await;

            println!("Watching for file changes...");
            println!("Press Ctrl+C to stop");

            // Keep the server running
            tokio::signal::ctrl_c()
                .await
                .expect("Failed to listen for Ctrl+C");

            println!("\nShutting down...");
        }
    }
}
