use ratatui::{
layout::Rect,
style::{Color, Style},
text::{Line, Span},
widgets::{Block, Borders, Paragraph, Wrap},
Frame,
};
use crate::models::KanbanItem;
pub fn draw_ticket(f: &mut Frame, item: &KanbanItem, area: Rect, is_selected: bool) {
let base_style = if is_selected {
Style::default().fg(Color::Black).bg(Color::Yellow)
} else {
Style::default().fg(Color::White)
};
let meta_style = if is_selected {
Style::default().fg(Color::Black).bg(Color::Yellow)
} else {
Style::default().fg(Color::Gray)
};
let mut lines = Vec::new();
let mut title_line = vec![
Span::styled(format!(" [{}] ", item.short_code()), meta_style),
Span::styled(item.title().to_string(), base_style),
];
if let Some(ref risk_complexity) = item.risk_complexity {
title_line.insert(0, Span::styled(format!("{} ", risk_complexity), meta_style));
}
lines.push(Line::from(title_line));
if !item.blocked_by().is_empty() {
let info_line = vec![Span::styled(
format!("🚫 {}", item.blocked_by().join(", ")),
if is_selected {
Style::default().fg(Color::Red).bg(Color::Yellow)
} else {
Style::default().fg(Color::Red)
},
)];
lines.push(Line::from(info_line));
}
if let Some(ref parent_title) = item.parent_title() {
lines.push(Line::from(vec![Span::styled(
format!("→ {}", parent_title),
meta_style,
)]));
}
if !item.prelude.is_empty() {
lines.push(Line::from(vec![Span::styled(&item.prelude, meta_style)]));
}
let ticket_block = Block::default()
.borders(Borders::ALL)
.border_style(if is_selected {
Style::default().fg(Color::Yellow)
} else {
Style::default().fg(Color::Gray)
});
let paragraph = Paragraph::new(lines)
.block(ticket_block)
.wrap(Wrap { trim: true });
f.render_widget(paragraph, area);
}