use ratatui::{
    style::{Color, Modifier, Style},
    widgets::BorderType,
};

use super::{colour, hex};
use crate::options::config::style::{Styles, themes::hex_colour};

impl Styles {
    pub(crate) fn nord_palette() -> Self {
        let list_colours = vec![
            hex!("#5e81ac"),
            hex!("#81a1c1"),
            hex!("#d8dee9"),
            hex!("#b48ead"),
            hex!("#a3be8c"),
            hex!("#ebcb8b"),
            hex!("#d08770"),
            hex!("#bf616a"),
        ];

        let second_colours_list = vec![
            hex!("#8fbcbb"),
            hex!("#81a1c1"),
            hex!("#d8dee9"),
            hex!("#b48ead"),
            hex!("#a3be8c"),
            hex!("#ebcb8b"),
            hex!("#bf616a"),
        ];

        Self {
            ram_style: hex!("#88c0d0"),
            #[cfg(not(target_os = "windows"))]
            cache_style: hex!("#d8dee9"),
            swap_style: hex!("#d08770"),
            #[cfg(feature = "zfs")]
            arc_style: hex!("#5e81ac"),
            #[cfg(feature = "gpu")]
            gpu_colours: second_colours_list.clone(),
            rx_style: hex!("#88c0d0"),
            tx_style: hex!("#d08770"),
            total_rx_style: hex!("#5e81ac"),
            total_tx_style: hex!("#8fbcbb"),
            all_cpu_colour: hex!("#88c0d0"),
            avg_cpu_colour: hex!("#8fbcbb"),
            cpu_colour_styles: list_colours.clone(),
            temp_graph_colour_styles: list_colours.clone(),
            disk_io_read_colour_styles: list_colours,
            disk_io_write_colour_styles: second_colours_list,
            border_style: hex!("#88c0d0"),
            highlighted_border_style: hex!("#5e81ac"),
            text_style: hex!("#e5e9f0"),
            selected_text_style: hex!("#2e3440").bg(hex_colour!("#88c0d0")),
            table_header_style: hex!("#81a1c1").add_modifier(Modifier::BOLD),
            general_widget_style: Style::default(),
            widget_title_style: hex!("#e5e9f0"),
            graph_style: hex!("#e5e9f0"),
            graph_legend_style: hex!("#e5e9f0"),
            high_battery: hex!("#a3be8c"),
            medium_battery: hex!("#ebcb8b"),
            low_battery: hex!("#bf616a"),
            invalid_query_style: colour!(Color::Red),
            disabled_text_style: hex!("#4c566a"),
            border_type: BorderType::Plain,
            #[cfg(target_os = "linux")]
            thread_text_style: hex!("#a3be8c"),
        }
    }

    pub(crate) fn nord_light_palette() -> Self {
        let list_colours = vec![
            hex!("#5e81ac"),
            hex!("#88c0d0"),
            hex!("#4c566a"),
            hex!("#b48ead"),
            hex!("#a3be8c"),
            hex!("#ebcb8b"),
            hex!("#d08770"),
            hex!("#bf616a"),
        ];

        let second_colours_list = vec![
            hex!("#8fbcbb"),
            hex!("#88c0d0"),
            hex!("#4c566a"),
            hex!("#b48ead"),
            hex!("#a3be8c"),
            hex!("#ebcb8b"),
            hex!("#bf616a"),
        ];

        Self {
            ram_style: hex!("#81a1c1"),
            #[cfg(not(target_os = "windows"))]
            cache_style: hex!("#4c566a"),
            swap_style: hex!("#d08770"),
            #[cfg(feature = "zfs")]
            arc_style: hex!("#5e81ac"),
            #[cfg(feature = "gpu")]
            gpu_colours: second_colours_list.clone(),
            rx_style: hex!("#81a1c1"),
            tx_style: hex!("#d08770"),
            total_rx_style: hex!("#5e81ac"),
            total_tx_style: hex!("#8fbcbb"),
            all_cpu_colour: hex!("#81a1c1"),
            avg_cpu_colour: hex!("#8fbcbb"),
            cpu_colour_styles: list_colours.clone(),
            temp_graph_colour_styles: list_colours.clone(),
            disk_io_read_colour_styles: list_colours,
            disk_io_write_colour_styles: second_colours_list,
            border_style: hex!("#2e3440"),
            highlighted_border_style: hex!("#5e81ac"),
            text_style: hex!("#2e3440"),
            selected_text_style: hex!("#f5f5f5").bg(hex_colour!("#5e81ac")),
            table_header_style: hex!("#5e81ac").add_modifier(Modifier::BOLD),
            general_widget_style: Style::default(),
            widget_title_style: hex!("#2e3440"),
            graph_style: hex!("#2e3440"),
            graph_legend_style: hex!("#2e3440"),
            high_battery: hex!("#a3be8c"),
            medium_battery: hex!("#ebcb8b"),
            low_battery: hex!("#bf616a"),
            invalid_query_style: colour!(Color::Red),
            disabled_text_style: hex!("#d8dee9"),
            border_type: BorderType::Plain,
            #[cfg(target_os = "linux")]
            thread_text_style: hex!("#a3be8c"),
        }
    }
}

#[cfg(test)]
mod tests {
    #[test]
    fn nord_palettes_valid() {
        let _ = super::Styles::nord_palette();
        let _ = super::Styles::nord_light_palette();
    }
}
