//! Banner display and boot-step formatting for the CLI.

use roboticus_core::style::Theme;

pub(crate) const BANNER: &str = include_str!("../banner.txt");

pub(crate) fn print_banner(t: &Theme) {
    use roboticus_core::style::sleep_ms;

    let version = env!("CARGO_PKG_VERSION");
    let p = t.accent();
    let d = t.dim();
    let r = t.reset();
    let scan = if t.colors_enabled() { 55 } else { 0 };

    eprintln!();
    for line in BANNER.lines() {
        if line.contains("I R O N C L A D") {
            let (art, _) = line
                .split_once("I R O N C L A D")
                .expect("guarded by contains()");
            eprint!("{p}{art}{r}");
            t.typewrite_line(&format!("{p}I R O N C L A D{r}"), 35);
        } else if line.contains("Autonomous Agent Runtime") {
            let (art, _) = line
                .split_once("Autonomous Agent Runtime")
                .expect("guarded by contains()");
            eprint!("{p}{art}{r}");
            t.typewrite_line(&format!("{d}Autonomous Agent Runtime v{version}{r}"), 18);
        } else {
            eprintln!("{p}{line}{r}");
            sleep_ms(scan);
        }
    }
    eprintln!();
}

pub(crate) fn step(t: &Theme, n: u32, total: u32, msg: &str) {
    let (d, b, r) = (t.dim(), t.bold(), t.reset());
    let ok = t.icon_ok();
    t.typewrite_line(&format!("  {ok} {d}[{n:>2}/{total}]{r} {b}{msg}{r}"), 4);
}

pub(crate) fn step_warn(t: &Theme, n: u32, total: u32, msg: &str) {
    let (d, r) = (t.dim(), t.reset());
    let warn = t.icon_warn();
    t.typewrite_line(&format!("  {warn} {d}[{n:>2}/{total}]{r} {msg}"), 4);
}

pub(crate) fn step_detail(t: &Theme, label: &str, value: &str) {
    let (d, a, r) = (t.dim(), t.accent(), t.reset());
    let detail = t.icon_detail();
    t.typewrite_line(&format!("       {detail} {d}{label}: {a}{value}{r}"), 4);
}
