use std::collections::HashMap;
use std::path::PathBuf;
use chrono::{DateTime, Local};
use crate::domain::repo::{GitInfo, Repo, RepoKind};
use crate::tui::presentation::{IconSet, status_text};
pub fn effective_info(repo: &Repo, example_mode: bool) -> Option<&GitInfo> {
if example_mode {
repo.example_git_info.as_ref()
} else {
repo.git_info.as_ref()
}
}
pub fn branch_text(info: Option<&GitInfo>) -> String {
match info {
None => "\u{2026}".to_string(),
Some(info) => info
.current_branch_name
.clone()
.unwrap_or_else(|| "-".to_string()),
}
}
pub fn github_text(info: Option<&GitInfo>) -> String {
info.and_then(|info| info.github_repo_name.clone())
.unwrap_or_else(|| "-".to_string())
}
pub fn status_display(info: Option<&GitInfo>, icons: &IconSet) -> String {
match info {
None => "\u{2026}".to_string(),
Some(info) if info.is_path_missing() => "-".to_string(),
Some(info) => status_text(info, icons),
}
}
pub fn zip_date_text(
repo: &Repo,
icons: &IconSet,
zip_backups: &HashMap<PathBuf, DateTime<Local>>,
) -> String {
if !repo.include_in_backup {
return icons.excluded.to_string();
}
zip_backups
.get(&repo.path)
.map_or_else(|| "-".to_string(), |dt| dt.format("%Y-%m-%d").to_string())
}
pub fn git_marker_errored(repo: &Repo, example_mode: bool) -> bool {
match repo.kind {
RepoKind::Git if example_mode => repo.example_error().is_some(),
RepoKind::Git => repo.entry_error().is_some(),
RepoKind::Path => false,
}
}