use crate::widgets::markdown_widget::foundation::elements::constants::BLOCKQUOTE_MARKER;
use crate::widgets::markdown_widget::foundation::elements::enums::TextSegment;
use crate::widgets::markdown_widget::foundation::elements::methods::helpers::{
render_text_segment, wrap_text,
};
use crate::widgets::markdown_widget::foundation::elements::MarkdownElement;
use ratatui::style::{Color, Style};
use ratatui::text::{Line, Span};
const BLOCKQUOTE_COLOR: Color = Color::Rgb(100, 149, 237);
pub fn render(
_element: &MarkdownElement,
segments: &[TextSegment],
depth: usize,
width: usize,
app_theme: Option<&crate::services::theme::AppTheme>,
) -> Vec<Line<'static>> {
let actual_depth = depth.max(1);
let prefix_char_width = actual_depth * 2;
let content_width = width.saturating_sub(prefix_char_width);
let quote_text_color = app_theme
.map(|t| t.markdown.block_quote)
.unwrap_or(Color::Rgb(180, 180, 200));
let mut content_spans: Vec<Span<'static>> = Vec::new();
let quote_style = Style::default()
.fg(quote_text_color)
.add_modifier(ratatui::style::Modifier::ITALIC);
for segment in segments {
content_spans.push(render_text_segment(segment, quote_style));
}
let plain_text: String = content_spans
.iter()
.map(|s| s.content.to_string())
.collect();
let wrapped = wrap_text(&plain_text, content_width);
let marker_style = Style::default().fg(BLOCKQUOTE_COLOR);
if wrapped.is_empty() {
let mut spans = Vec::new();
for _ in 1..=actual_depth {
spans.push(Span::styled(BLOCKQUOTE_MARKER.to_string(), marker_style));
spans.push(Span::raw(" "));
}
return vec![Line::from(spans)];
}
wrapped
.into_iter()
.map(|line_text| {
let mut spans = Vec::new();
for _ in 1..=actual_depth {
spans.push(Span::styled(BLOCKQUOTE_MARKER.to_string(), marker_style));
spans.push(Span::raw(" "));
}
spans.push(Span::styled(line_text, quote_style));
Line::from(spans)
})
.collect()
}
pub fn create_blockquote_prefix(depth: usize) -> Vec<Span<'static>> {
let marker_style = Style::default().fg(BLOCKQUOTE_COLOR);
let mut spans = Vec::new();
for _ in 1..=depth {
spans.push(Span::styled(BLOCKQUOTE_MARKER.to_string(), marker_style));
spans.push(Span::raw(" "));
}
spans
}
pub fn blockquote_prefix_width(depth: usize) -> usize {
depth * 2 }