use ratatui::prelude::*;
use ratatui::widgets::{Block, Padding, Paragraph};
use crate::frontend::App;
use super::{
chat_list_widget::ChatListWidget, chat_messages_widget::ChatMessagesWidget,
help_section_widget::HelpSectionWidget, input_bar_widget::InputBarWidget,
};
pub fn ui(f: &mut ratatui::Frame, area: Rect, app: &mut App) {
let [main_area, bottom_area] = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Min(0), Constraint::Length(2), ])
.areas(area);
let [chat_area, right_area] = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Percentage(80), Constraint::Percentage(20), ])
.areas(main_area);
let [chat_messages, input_area] = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Min(0), Constraint::Length(8)])
.spacing(0)
.areas(chat_area);
app.chat_messages_max_lines = chat_messages.height;
ChatMessagesWidget::render(f, app, chat_messages);
let [chat_list, help_area] =
Layout::vertical([Constraint::Min(10), Constraint::Length(20)]).areas(right_area);
ChatListWidget::render(f, app, chat_list);
if app.input_width.is_none() {
app.input_width = Some(input_area.width);
}
InputBarWidget::render(f, app, input_area);
HelpSectionWidget::render(f, app, help_area);
let branch_name = app
.current_chat()
.branch_name
.as_deref()
.unwrap_or("not yet named");
Paragraph::new(Line::from(vec![Span::raw(format!(
"uuid: {} branch-name: {}",
app.current_chat_uuid, branch_name
))]))
.style(Style::default().fg(Color::DarkGray).italic())
.block(Block::default().padding(Padding::right(1)))
.alignment(Alignment::Right)
.render(bottom_area, f.buffer_mut());
}