use std::collections::HashSet;
use std::path::PathBuf;
use crate::node::TreeNode;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SearchState {
pub query: String,
pub query_lower: String,
pub visible_paths: HashSet<PathBuf>,
pub match_count: usize,
}
pub fn walk_for_search(
node: &TreeNode,
query_lower: &str,
visible: &mut HashSet<PathBuf>,
match_count: &mut usize,
) -> bool {
let basename_lower = node.file_name().to_string_lossy().to_ascii_lowercase();
let self_matches = basename_lower.contains(query_lower);
if self_matches {
*match_count += 1;
}
let mut descendant_matches = false;
for child in &node.children {
if walk_for_search(child, query_lower, visible, match_count) {
descendant_matches = true;
}
}
let has_visible = self_matches || descendant_matches;
if has_visible {
visible.insert(node.path.clone());
}
has_visible
}