use crate::client::tui::app::App;
use ratatui::{
    Frame,
    layout::Rect,
    style::{Color, Modifier, Style},
    text::{Line, Span},
    widgets::{Block, Borders, Paragraph},
};

pub fn render(frame: &mut Frame, area: Rect, app: &App) {
    let connection = if app.connected {
        Span::styled("● 已连接", Style::default().fg(Color::Green))
    } else {
        Span::styled("● 已断开", Style::default().fg(Color::Red))
    };
    let pending = if app.pending_responses > 0 {
        format!(" · {} 个请求处理中", app.pending_responses)
    } else {
        String::new()
    };
    frame.render_widget(
        Paragraph::new(Line::from(vec![
            Span::styled(
                " PicoBot ",
                Style::default()
                    .fg(Color::Cyan)
                    .add_modifier(Modifier::BOLD),
            ),
            Span::raw(format!("{}  ", app.current_title())),
            connection,
            Span::styled(pending, Style::default().fg(Color::DarkGray)),
        ]))
        .block(Block::default().borders(Borders::ALL)),
        area,
    );
}
