use std::{env, path::PathBuf};

const NAME: &str = env!("CARGO_PKG_NAME");

pub fn home() -> PathBuf {
    if let Ok(home) = env::var("HOME") {
        PathBuf::from(home)
    } else {
        PathBuf::new()
    }
}

fn alt_dir() -> PathBuf {
    PathBuf::from(format!("{}/.{}", home().to_string_lossy(), NAME))
}

pub fn data_dir() -> PathBuf {
    if let Ok(base) = env::var("XDG_DATA_HOME") {
        PathBuf::from(base).join(NAME)
    } else {
        alt_dir()
    }
}

pub fn config_dir() -> PathBuf {
    if let Ok(base) = env::var("XDG_CONFIG_HOME") {
        PathBuf::from(base).join(NAME)
    } else {
        alt_dir()
    }
}
