use ratatui::{
style::{Color, Style},
text::Span,
widgets::{Cell, Row},
};
use crate::models::ProblemSummary;
pub fn render_problem_row(p: &ProblemSummary) -> Row<'static> {
let diff_color = match p.difficulty {
1 => Color::Green,
2 => Color::Yellow,
_ => Color::Red,
};
let id_cell = Cell::from(Span::styled(
format!("[{}]", p.id),
Style::default().fg(diff_color),
));
let name_cell = Cell::from(Span::styled(
p.title.clone(),
Style::default().fg(diff_color),
));
let acceptance_text = format!("{:.1}%", p.acceptance * 100.0);
let acceptance_cell = Cell::from(acceptance_text);
let done_text = if let Some(status) = &p.status {
match status.as_str() {
"ac" => "\u{f00c}",
"notac" => "\u{eabc}",
_ => "",
}
} else {
""
};
let done_cell = match done_text {
"\u{f00c}" => Cell::from(done_text).style(Style::default().fg(Color::Green)),
_ => Cell::from(done_text).style(Style::default().fg(Color::White)),
};
let premium_text = if p.is_paid { "" } else { "" };
let premium_cell = Cell::from(premium_text).style(Style::default().fg(Color::Red));
let topics_text = p
.topics
.first()
.map(|t| t.as_str())
.unwrap_or("")
.to_string();
let topics_cell = Cell::from(topics_text);
Row::new(vec![
id_cell,
name_cell,
acceptance_cell,
topics_cell,
premium_cell,
done_cell,
])
}