use crate::app::AppState;
use chrono::Local;
pub fn substitute_template(template: &str, state: &AppState, user_message: &str) -> String {
let mut result = template.to_string();
result = result.replace("{message}", user_message);
let branch = if state.current_branch.is_empty() {
"main".to_string()
} else {
state.current_branch.clone()
};
result = result.replace("{branch}", &branch);
let date = Local::now().format("%Y-%m-%d").to_string();
result = result.replace("{date}", &date);
let time = Local::now().format("%H:%M:%S").to_string();
result = result.replace("{time}", &time);
let repo_name = state.repo_path
.split('/')
.last()
.unwrap_or("repo")
.to_string();
result = result.replace("{repo}", &repo_name);
let staged_count = state.status_entries.iter().filter(|e| e.staged).count();
result = result.replace("{files}", &staged_count.to_string());
result
}
pub fn get_template_preview(template: &str, state: &AppState) -> String {
substitute_template(template, state, "{message}")
}