use crate::game_logic::state::GameOverMenu;
use crate::graphics::menus::main_menu::Button;
use crate::graphics::menus::utils_layout::{
frame_vertically_centered_rect, render_full_centered_paragraph,
};
use ratatui::style::Color;
use ratatui::text::{Line, Span, Text};
use ratatui::widgets::Paragraph;
use ratatui::Frame;
pub const SNAKE_LOGO: &str = "\
███████╗ ███╗ ██╗ █████╗ ██╗ ██╗ ███████╗
██╔════╝ ████╗ ██║ ██╔══██╗ ██║ ██╔╝ ██╔════╝
███████╗ ██╔██╗ ██║ ███████║ █████╔╝ █████╗
╚════██║ ██║╚██╗██║ ██╔══██║ ██╔═██╗ ██╔══╝
███████║ ██║ ╚████║ ██║ ██║ ██║ ██╗ ███████╗
╚══════╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝";
pub const CONTROLS_TABLE: &str = "\
+--------+------+------+-------+-----+-------+
|Controls| ←↕→ | Q | P / ⎵ | M | R |
+--------+------+------+-------+-----+-------+
|Effects | Move | Quit | Pause | Menu| Start |
+--------+------+------+-------+-----+-------+";
const GAME_OVER_TEXT: &str = "\n\
██████╗ █████╗ ███╗ ███╗███████╗ ██████╗ ██╗ ██╗███████╗██████╗ \n\
██╔═══ ██╔══██╗████╗ ████║██╔════╝ ██╔═══██╗██║ ██║██╔════╝██╔══██╗\n\
██║ ████║███████║██╔████╔██║█████╗ ██║ ██║██║ ██║█████╗ ██████╔╝\n\
██║ ██║██╔══██║██║╚██╔╝██║██╔══╝ ██║ ██║██║ ██║██╔══╝ ██╔══██╗\n\
╚██████╔╝██║ ██║██║ ╚═╝ ██║███████╗ ╚██████╔╝╚██████╔╝███████╗██║ ██║\n\
╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝";
const PAUSE_TEXT: &str = "\n\
██████╗ █████╗ ██╗ ██╗███████╗███████╗\n\
██╔══██╗██╔══██╗██║ ██║██╔════╝██╔════╝\n\
██████╔╝███████║██║ ██║███████╗█████╗ \n\
██╔═══╝ ██╔══██║██║ ██║╚════██║██╔══╝ \n\
██║ ██║ ██║╚██████╔╝███████║███████╗\n\
╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚══════╝";
const MENU_TEXT: &str = "\n\
███╗ ███╗███████╗███╗ ██╗██╗ ██╗
████╗ ████║██╔════╝████╗ ██║██║ ██║
██╔████╔██║█████╗ ██╔██╗ ██║██║ ██║
██║╚██╔╝██║██╔══╝ ██║╚██╗██║██║ ██║
██║ ╚═╝ ██║███████╗██║ ╚████║╚██████╔╝
╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝ ╚═════╝ ";
const FAREWELL_TEXT: &str = "\n\
██████╗ ██╗ ██╗███████╗ ██████╗ ██╗ ██╗███████╗
██╔══██╗╚██╗ ██╔╝██╔════╝ ██╔══██╗╚██╗ ██╔╝██╔════╝
██████╔╝ ╚████╔╝ █████╗█████╗██████╔╝ ╚████╔╝ █████╗
██╔══██╗ ╚██╔╝ ██╔══╝╚════╝██╔══██╗ ╚██╔╝ ██╔══╝
██████╔╝ ██║ ███████╗ ██████╔╝ ██║ ███████╗
╚═════╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═╝ ╚══════╝";
const RESTART_TEXT: &str = "\n\
██████╗ ███████╗███████╗████████╗ █████╗ ██████╗ ████████╗
██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔══██╗██╔══██╗╚══██╔══╝
██████╔╝█████╗ ███████╗ ██║ ███████║██████╔╝ ██║
██╔══██╗██╔══╝ ╚════██║ ██║ ██╔══██║██╔══██╗ ██║
██║ ██║███████╗███████║ ██║ ██║ ██║██║ ██║ ██║
╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ";
pub fn pause_paragraph(frame: &mut Frame) {
render_full_centered_paragraph(frame, PAUSE_TEXT, None);
}
pub fn byebye_paragraph(frame: &mut Frame) {
render_full_centered_paragraph(frame, FAREWELL_TEXT, Some(Color::DarkGray));
}
pub fn restart_paragraph(frame: &mut Frame) {
render_full_centered_paragraph(frame, RESTART_TEXT, Some(Color::LightYellow));
}
pub fn menu_paragraph(frame: &mut Frame) {
render_full_centered_paragraph(frame, MENU_TEXT, Some(Color::Gray));
}
pub fn game_over_paragraph(
frame: &mut Frame,
selection: &GameOverMenu,
score: u32,
rank: Option<usize>,
) {
let mut lines = vec![];
for logo_line in GAME_OVER_TEXT.lines() {
lines.push(Line::from(logo_line).style(ratatui::style::Style::default().fg(Color::Red)));
}
lines.push(Line::default());
lines.push(Line::from(vec![
Span::raw("Score: "),
Span::styled(
format!("{score}"),
ratatui::style::Style::default().fg(Color::Yellow),
),
]));
if let Some(r) = rank {
lines.push(Line::from(vec![
Span::raw("Ranking: "),
Span::styled(
format!("#{r}"),
ratatui::style::Style::default().fg(Color::Green),
),
Span::raw(" among top 10!"),
]));
}
lines.push(Line::default());
let mut restart_button = Button::new("Restart 🎮");
let mut menu_button = Button::new("Menu 🗺");
let mut quit_button = Button::new("Quit ");
restart_button.selected(selection == &GameOverMenu::Restart);
menu_button.selected(selection == &GameOverMenu::Menu);
quit_button.selected(selection == &GameOverMenu::Quit);
let mut combined_spans: Vec<Span> = restart_button.to_spans();
combined_spans.extend(menu_button.to_spans());
combined_spans.extend(quit_button.to_spans());
lines.push(Line::from(combined_spans));
let nb_lines = lines.len();
frame.render_widget(
Paragraph::new(Text::from(lines)).centered(),
frame_vertically_centered_rect(frame.area(), nb_lines),
);
frame.render_widget(ratatui::widgets::Block::default(), frame.area());
}