use ratatui::{style::Stylize, widgets::{List, Paragraph}, Frame};

use crate::{AppState, Chip8Computer, CHIP8_REGISTER_COUNT, CHIP8_VIDEO_MEMORY};


pub fn render_cpu_state(cpu_state: Chip8Computer, frame: &mut Frame) {
    let mut area = frame.area();

    let mut current_state: Vec<String> = vec![];

    current_state.push(format!("Delay Timer {:X}", cpu_state.delay_timer));
    current_state.push(format!("Sound Timer {:X}", cpu_state.sound_timer));
    current_state.push(format!("PC {:X}", cpu_state.pc));
    for i in 0 .. CHIP8_REGISTER_COUNT {
        current_state.push(format!("V{}: {}", i, cpu_state.registers[i as usize]));
    }

    frame.render_widget(
        List::new(current_state).blue().on_white(), area)
}

pub fn render_menu_list(state: AppState, frame: &mut Frame) {
    let mut area = frame.area();

    frame.render_widget(List::new(state.menu_items).blue().on_white(), area);
}

pub fn render_hello_world(frame: &mut Frame) {
    let area = frame.area();
    frame.render_widget(
        Paragraph::new("Hello Ratatui! (press 'q' to quit)")
            .white()
            .on_blue(),
        area,
    );
}

pub fn render_video_state(video_memory: [bool; CHIP8_VIDEO_MEMORY], frame: &mut Frame) {
    
}