use owo_colors::Style;

pub struct Styles {
    pub green: Style,
    pub red: Style,
    pub cyan: Style,
    pub dim: Style,
    pub bold: Style,
    pub yellow: Style,
}

impl Styles {
    pub fn new() -> Self {
        if no_color() {
            Self {
                green: Style::new(),
                red: Style::new(),
                cyan: Style::new(),
                dim: Style::new(),
                bold: Style::new(),
                yellow: Style::new(),
            }
        } else {
            Self {
                green: Style::new().green().bold(),
                red: Style::new().red().bold(),
                cyan: Style::new().bright_cyan().bold(),
                dim: Style::new().dimmed(),
                bold: Style::new().bold(),
                yellow: Style::new().yellow().bold(),
            }
        }
    }
}

impl Default for Styles {
    fn default() -> Self {
        Self::new()
    }
}

fn no_color() -> bool {
    // Check our global flag first (set from --no-color or NO_COLOR env var),
    // fall back to checking the env var directly for code that runs before main.
    crate::NO_COLOR
        .get()
        .copied()
        .unwrap_or_else(|| std::env::var_os("NO_COLOR").is_some())
}
