use crate::frontend::render::{bar, body, flows, footer, header, help, settings, tabs};
use crate::frontend::tui_app::TuiApp;
use ratatui::layout::{Constraint, Direction, Layout};
use ratatui::Frame;
pub fn render(f: &mut Frame<'_>, app: &mut TuiApp) {
let constraints = if app.trace_info.len() > 1 {
LAYOUT_WITH_TABS.as_slice()
} else if app.show_flows {
LAYOUT_WITH_FLOWS.as_slice()
} else {
LAYOUT_WITHOUT_TABS.as_slice()
};
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints(constraints.as_ref())
.split(f.area());
header::render(f, app, chunks[0]);
if app.trace_info.len() > 1 {
tabs::render(f, chunks[1], app);
body::render(f, chunks[2], app);
footer::render(f, chunks[3], app);
bar::render(f, chunks[4], app);
} else if app.show_flows {
flows::render(f, chunks[1], app);
body::render(f, chunks[2], app);
footer::render(f, chunks[3], app);
bar::render(f, chunks[4], app);
} else {
body::render(f, chunks[1], app);
footer::render(f, chunks[2], app);
bar::render(f, chunks[3], app);
}
if app.show_settings {
settings::render(f, app);
} else if app.show_help {
help::render(f, app);
}
}
const LAYOUT_WITHOUT_TABS: [Constraint; 4] = [
Constraint::Length(4),
Constraint::Min(10),
Constraint::Length(6),
Constraint::Length(1),
];
const LAYOUT_WITH_TABS: [Constraint; 5] = [
Constraint::Length(4),
Constraint::Length(3),
Constraint::Min(10),
Constraint::Length(6),
Constraint::Length(1),
];
const LAYOUT_WITH_FLOWS: [Constraint; 5] = [
Constraint::Length(4),
Constraint::Length(6),
Constraint::Min(10),
Constraint::Length(6),
Constraint::Length(1),
];