use std::path::PathBuf;
use std::io::{self, Write};
use fren_core::FileRename;

pub fn list_files(files: &[PathBuf]) {
    println!("Found {} matching file(s):", files.len());
    for file in files {
        println!("  {}", file.display());
    }
}

pub fn display_preview(renames: &[FileRename]) {
    println!("{:<40} -> {:<40}", "Old Name", "New Name");
    println!("{:-<40}----{:-<40}", "", "");
    
    for rename in renames {
        let old = rename.old_path.file_name().and_then(|n| n.to_str()).unwrap_or("?");
        let new = &rename.new_name;
        
        if new.trim().is_empty() {
            println!("{:<40} -> {:<40}", old, "[ERROR: EMPTY NAME]");
        } else {
            println!("{:<40} -> {:<40}", old, new);
        }
    }
}

pub fn confirm_renames() -> bool {
    print!("\nProceed with renaming? (y/N): ");
    io::stdout().flush().unwrap();
    
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input.trim().to_lowercase() == "y"
}

pub fn confirm_undo_conflicts(safe_count: usize) -> bool {
    print!("\nProceed with undoing {} safe renames? (y/N): ", safe_count);
    io::stdout().flush().unwrap();
    
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input.trim().to_lowercase() == "y"
}
