use ratatui::Frame;
use ratatui::layout::Rect;
use ratatui::style::Style;
use ratatui::widgets::Padding;
use super::{Cover, center, popup_block, text_rows};
use crate::lang;
use crate::select::TextSelect;
use crate::theme::Colors;
const WIDTH: u16 = 76;
pub(super) fn draw(frame: &mut Frame, area: Rect, select: &mut TextSelect, colors: &Colors) {
let width = WIDTH.min(area.width);
let rows = text_rows(&select.text, width.saturating_sub(4)).max(1);
let height = u16::try_from(rows + 2).unwrap_or(u16::MAX).min(area.height);
let popup = center(area, width, height);
let keys = match select.selecting() {
true => lang::t(" `y` copy · `Esc` cancel "),
false => lang::t(" `v` select · `Esc` close "),
};
let title = lang::t(" Select text ");
let block = popup_block(title, keys, colors).padding(Padding::horizontal(1));
let inner = block.inner(popup);
frame.render_widget(Cover, popup);
frame.render_widget(block, popup);
select
.text
.set_selection_style(Style::new().bg(colors.selection));
select.text.set_cursor_style(Style::new().reversed());
frame.render_widget(&select.text, inner);
}