#![forbid(unsafe_code)]

use anyhow::Result;
use clap::Parser;
use lore_tui::LaunchOptions;

/// Terminal UI for Gitlore — explore GitLab issues, MRs, and search locally.
#[derive(Parser, Debug)]
#[command(name = "lore-tui", version, about)]
struct TuiCli {
    /// Path to lore config file (default: ~/.config/lore/config.json).
    #[arg(short, long, env = "LORE_CONFIG_PATH")]
    config: Option<String>,

    /// Run a sync before launching the TUI.
    #[arg(long)]
    sync: bool,

    /// Clear cached state and start fresh.
    #[arg(long)]
    fresh: bool,

    /// Render mode: "crossterm" (default) or "native".
    #[arg(long, default_value = "crossterm")]
    render_mode: String,

    /// Use ASCII-only drawing characters (no Unicode box drawing).
    #[arg(long)]
    ascii: bool,

    /// Disable alternate screen (render inline).
    #[arg(long)]
    no_alt_screen: bool,
}

fn main() -> Result<()> {
    let cli = TuiCli::parse();

    let options = LaunchOptions {
        config_path: cli.config,
        sync_on_start: cli.sync,
        fresh: cli.fresh,
        render_mode: cli.render_mode,
        ascii: cli.ascii,
        no_alt_screen: cli.no_alt_screen,
    };

    if options.sync_on_start {
        lore_tui::launch_sync_tui(options)
    } else {
        lore_tui::launch_tui(options)
    }
}
