use crate::state::types::AppMode;
use crate::state::{AppState, Focus};
#[must_use]
pub fn filtered_recent_indices(app: &AppState) -> Vec<usize> {
let apply =
matches!(app.focus, Focus::Recent) && app.pane_find.as_ref().is_some_and(|s| !s.is_empty());
let recents = if matches!(app.app_mode, AppMode::News) {
app.news_recent_values()
} else {
app.recent_values()
};
if !apply {
return (0..recents.len()).collect();
}
let pat = app
.pane_find
.as_ref()
.expect("pane_find should be Some when apply is true")
.to_lowercase();
recents
.iter()
.enumerate()
.filter_map(|(i, s)| {
if s.to_lowercase().contains(&pat) {
Some(i)
} else {
None
}
})
.collect()
}
#[must_use]
pub fn filtered_install_indices(app: &AppState) -> Vec<usize> {
let apply = matches!(app.focus, Focus::Install)
&& app.pane_find.as_ref().is_some_and(|s| !s.is_empty());
if !apply {
return (0..app.install_list.len()).collect();
}
let pat = app
.pane_find
.as_ref()
.expect("pane_find should be Some when apply is true")
.to_lowercase();
app.install_list
.iter()
.enumerate()
.filter_map(|(i, p)| {
let name = p.name.to_lowercase();
let desc = p.description.to_lowercase();
if name.contains(&pat) || desc.contains(&pat) {
Some(i)
} else {
None
}
})
.collect()
}