use std::path::PathBuf;

pub const APP_ID: &str = "app.driftwood.Driftwood";
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const GSETTINGS_SCHEMA_DIR: &str = env!("GSETTINGS_SCHEMA_DIR");
pub const SYSTEM_APPIMAGE_DIR: &str = "/opt/appimages";

/// Return the XDG data directory with a proper $HOME-based fallback.
/// Unlike `PathBuf::from("~/.local/share")`, this actually resolves to the
/// user's home directory instead of creating a literal `~` path.
pub fn data_dir_fallback() -> PathBuf {
    dirs::data_dir().unwrap_or_else(|| home_dir().join(".local/share"))
}

/// Return the XDG config directory with a proper $HOME-based fallback.
pub fn config_dir_fallback() -> PathBuf {
    dirs::config_dir().unwrap_or_else(|| home_dir().join(".config"))
}

fn home_dir() -> PathBuf {
    dirs::home_dir()
        .or_else(|| std::env::var("HOME").ok().map(PathBuf::from))
        .unwrap_or_else(|| PathBuf::from("/tmp"))
}
