1
//! The filter builder overlay: its rows and the cursor.
2

            
3
use ratatui::text::{Line, Text};
4
use tvui::{Role, Theme};
5

            
6
use crate::modal::FilterBuilder;
7

            
8
/// The body and the line the cursor is on.
9
3
pub(super) fn content(builder: &FilterBuilder, theme: &Theme) -> (Text<'static>, usize) {
10
3
    let view = builder.view();
11
3
    let mut lines = vec![Line::from(view.heading)];
12
3
    if let Some(notice) = view.notice {
13
4
        lines.extend(notice.lines().map(|line| Line::from(line.to_string())));
14
1
    }
15
3
    if let Some(error) = &builder.error {
16
        lines.push(Line::from(format!("! {error}")));
17
3
    }
18
3
    lines.push(Line::from(""));
19
3
    let first = lines.len();
20
3
    if view.rows.is_empty() {
21
2
        lines.push(Line::from("  (no rows)"));
22
1
    }
23
3
    lines.extend(view.rows.iter().enumerate().map(|(index, row)| {
24
2
        if index == view.selected {
25
1
            Line::styled(format!("> {row}"), theme.style(Role::DialogFocus))
26
        } else {
27
1
            Line::from(format!("  {row}"))
28
        }
29
2
    }));
30
3
    (Text::from(lines), first + view.selected)
31
3
}