// src/components/common/autocomplete.rs use crate::config::colors::themes::Theme; use ratatui::{ layout::Rect, style::{Color, Modifier, Style}, widgets::{Block, List, ListItem, ListState}, Frame, }; /// Renders an opaque dropdown list for autocomplete suggestions. pub fn render_autocomplete_dropdown( f: &mut Frame, area: Rect, theme: &Theme, suggestions: &[String], selected_index: Option, ) { if suggestions.is_empty() { return; } // Render a solid background block first to ensure opacity let background_block = Block::default().style(Style::default().bg(Color::DarkGray)); f.render_widget(background_block, area); // Create list items, ensuring each has a defined background let items: Vec = suggestions .iter() .enumerate() .map(|(i, s)| { let is_selected = selected_index == Some(i); ListItem::new(s.as_str()).style(if is_selected { // Style for selected item (highlight background) Style::default() .fg(theme.bg) // Text color on highlight .bg(theme.highlight) // Highlight background .add_modifier(Modifier::BOLD) } else { // Style for non-selected items (matching background block) Style::default() .fg(theme.fg) // Text color on gray .bg(Color::DarkGray) // Explicit gray background }) }) .collect(); // Create the list widget (without its own block) let list = List::new(items); // State for managing selection highlight (still needed for logic) let mut list_state = ListState::default(); list_state.select(selected_index); // Render the list statefully *over* the background block f.render_stateful_widget(list, area, &mut list_state); }