//! Up/down arrow scroll indicators for bounded lists.

use ratatui::layout::Rect;
use ratatui::style::{Color, Style};
use ratatui::widgets::Paragraph;
use ratatui::Frame;

/// Horizontal alignment for scroll indicators.
pub enum IndicatorAlign {
    Center,
    Right,
}

/// Render up/down scroll arrows when content overflows.
pub fn render_scroll_indicators(
    frame: &mut Frame,
    area: Rect,
    offset: usize,
    visible: usize,
    total: usize,
    color: Color,
    align: IndicatorAlign,
) {
    let style = Style::new().fg(color);

    match align {
        IndicatorAlign::Center => {
            if offset > 0 {
                let indicator = Paragraph::new("▲")
                    .style(style)
                    .alignment(ratatui::layout::Alignment::Center);
                frame.render_widget(indicator, Rect { height: 1, ..area });
            }
            if offset + visible < total {
                let y = area.y + area.height.saturating_sub(1);
                let indicator = Paragraph::new("▼")
                    .style(style)
                    .alignment(ratatui::layout::Alignment::Center);
                frame.render_widget(indicator, Rect { y, height: 1, ..area });
            }
        }
        IndicatorAlign::Right => {
            let x = area.x + area.width.saturating_sub(1);
            if offset > 0 {
                let indicator = Paragraph::new("▲").style(style);
                frame.render_widget(indicator, Rect::new(x, area.y, 1, 1));
            }
            if offset + visible < total {
                let indicator = Paragraph::new("▼").style(style);
                frame.render_widget(
                    indicator,
                    Rect::new(x, area.y + area.height.saturating_sub(1), 1, 1),
                );
            }
        }
    }
}
