use crate::AppModel;
use crate::cli_outbound::Cli;
use crate::keymap::CenterTab;
use super::ShellState;
pub(super) fn focus(model: &AppModel, state: &mut ShellState, tab: CenterTab) {
super::focus::center(state, tab);
if tab == CenterTab::Config {
state.focus_wall(model.focused_workspace());
state.wall.brazen.open();
state.config.open(model.focused_workspace());
}
}
pub(super) fn render(
ui: &mut egui::Ui,
model: &mut AppModel,
state: &mut ShellState,
lernie: &Cli,
bl: &Cli,
bz: &Cli,
) {
let answer = model.found();
let searching = model.searching();
let offered = searching || !answer.is_empty();
if state.center == CenterTab::Search && !offered {
super::focus::center(state, CenterTab::Conversation);
}
strip(ui, model, state, offered);
match state.center {
CenterTab::Conversation => super::workspace::center(ui, model, state, lernie, bl, bz),
CenterTab::Config => super::config_edit::center(ui, model, state, lernie, bl),
CenterTab::Login => {
let state_root = model.state_root().to_path_buf();
super::login_pane::login_section(ui, &mut state.wall.login, bz, &state_root);
}
CenterTab::Search => super::search_pane::pane(ui, model, state, &answer, searching),
}
}
pub(super) fn conversation_open(state: &ShellState) -> bool {
state.center == CenterTab::Conversation
}
fn strip(ui: &mut egui::Ui, model: &AppModel, state: &mut ShellState, search: bool) {
let mut pick = None;
super::row::peers(ui, |ui| {
for tab in CenterTab::all() {
if tab == CenterTab::Search && !search {
continue;
}
if ui
.selectable_label(tab == state.center, tab.label())
.on_hover_text(tab.focus_hover())
.clicked()
{
pick = Some(tab);
}
}
});
if let Some(tab) = pick {
focus(model, state, tab);
}
ui.separator();
}