use ratatui::style::Color;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]
pub(super) enum ThemeName {
    #[default]
    Default,
    Dracula,
    Nord,
    Solarized,
    Gruvbox,
    TokyoNight,
    Catppuccin,
    OneDark,
    Monokai,
    Ayu,
    RosePine,
    Kanagawa,
    GithubLight,
}

#[derive(Debug, Clone, Copy)]
pub(super) struct Palette {
    pub header_fg: Color,
    pub header_bg: Color,
    pub accent: Color,
    pub muted: Color,
    pub focus_border: Color,
    pub blur_border: Color,
    pub highlight: Color,
    pub tab_active: Color,
    pub tab_inactive: Color,
}

impl ThemeName {
    pub(super) fn label(self) -> &'static str {
        match self {
            ThemeName::Default => "Default",
            ThemeName::Dracula => "Dracula",
            ThemeName::Nord => "Nord",
            ThemeName::Solarized => "Solarized",
            ThemeName::Gruvbox => "Gruvbox",
            ThemeName::TokyoNight => "Tokyo Night",
            ThemeName::Catppuccin => "Catppuccin Mocha",
            ThemeName::OneDark => "One Dark",
            ThemeName::Monokai => "Monokai",
            ThemeName::Ayu => "Ayu Dark",
            ThemeName::RosePine => "Rosé Pine",
            ThemeName::Kanagawa => "Kanagawa Wave",
            ThemeName::GithubLight => "GitHub Light",
        }
    }

    pub(super) const ALL: [ThemeName; 13] = [
        ThemeName::Default,
        ThemeName::Dracula,
        ThemeName::Nord,
        ThemeName::Solarized,
        ThemeName::Gruvbox,
        ThemeName::TokyoNight,
        ThemeName::Catppuccin,
        ThemeName::OneDark,
        ThemeName::Monokai,
        ThemeName::Ayu,
        ThemeName::RosePine,
        ThemeName::Kanagawa,
        ThemeName::GithubLight,
    ];

    pub(super) fn palette(self) -> Palette {
        match self {
            ThemeName::Default => Palette {
                header_fg: Color::White,
                header_bg: Color::Blue,
                accent: Color::Cyan,
                muted: Color::DarkGray,
                focus_border: Color::Cyan,
                blur_border: Color::DarkGray,
                highlight: Color::DarkGray,
                tab_active: Color::Yellow,
                tab_inactive: Color::DarkGray,
            },
            ThemeName::Dracula => Palette {
                header_fg: Color::Rgb(248, 248, 242),
                header_bg: Color::Rgb(98, 114, 164),
                accent: Color::Rgb(189, 147, 249),
                muted: Color::Rgb(98, 114, 164),
                focus_border: Color::Rgb(255, 121, 198),
                blur_border: Color::Rgb(68, 71, 90),
                highlight: Color::Rgb(68, 71, 90),
                tab_active: Color::Rgb(255, 184, 108),
                tab_inactive: Color::Rgb(98, 114, 164),
            },
            ThemeName::Nord => Palette {
                header_fg: Color::Rgb(236, 239, 244),
                header_bg: Color::Rgb(59, 66, 82),
                accent: Color::Rgb(136, 192, 208),
                muted: Color::Rgb(76, 86, 106),
                focus_border: Color::Rgb(143, 188, 187),
                blur_border: Color::Rgb(76, 86, 106),
                highlight: Color::Rgb(67, 76, 94),
                tab_active: Color::Rgb(235, 203, 139),
                tab_inactive: Color::Rgb(76, 86, 106),
            },
            ThemeName::Solarized => Palette {
                header_fg: Color::Rgb(253, 246, 227),
                header_bg: Color::Rgb(7, 54, 66),
                accent: Color::Rgb(38, 139, 210),
                muted: Color::Rgb(101, 123, 131),
                focus_border: Color::Rgb(42, 161, 152),
                blur_border: Color::Rgb(88, 110, 117),
                highlight: Color::Rgb(7, 54, 66),
                tab_active: Color::Rgb(181, 137, 0),
                tab_inactive: Color::Rgb(101, 123, 131),
            },
            ThemeName::Gruvbox => Palette {
                header_fg: Color::Rgb(235, 219, 178),
                header_bg: Color::Rgb(60, 56, 54),
                accent: Color::Rgb(131, 165, 152),
                muted: Color::Rgb(146, 131, 116),
                focus_border: Color::Rgb(184, 187, 38),
                blur_border: Color::Rgb(80, 73, 69),
                highlight: Color::Rgb(80, 73, 69),
                tab_active: Color::Rgb(250, 189, 47),
                tab_inactive: Color::Rgb(146, 131, 116),
            },
            ThemeName::TokyoNight => Palette {
                header_fg: Color::Rgb(192, 202, 245),
                header_bg: Color::Rgb(26, 27, 38),
                accent: Color::Rgb(122, 162, 247),
                muted: Color::Rgb(86, 95, 137),
                focus_border: Color::Rgb(187, 154, 247),
                blur_border: Color::Rgb(52, 59, 88),
                highlight: Color::Rgb(41, 46, 66),
                tab_active: Color::Rgb(224, 175, 104),
                tab_inactive: Color::Rgb(86, 95, 137),
            },
            ThemeName::Catppuccin => Palette {
                header_fg: Color::Rgb(205, 214, 244),
                header_bg: Color::Rgb(30, 30, 46),
                accent: Color::Rgb(137, 180, 250),
                muted: Color::Rgb(108, 112, 134),
                focus_border: Color::Rgb(203, 166, 247),
                blur_border: Color::Rgb(69, 71, 90),
                highlight: Color::Rgb(49, 50, 68),
                tab_active: Color::Rgb(249, 226, 175),
                tab_inactive: Color::Rgb(108, 112, 134),
            },
            ThemeName::OneDark => Palette {
                header_fg: Color::Rgb(171, 178, 191),
                header_bg: Color::Rgb(40, 44, 52),
                accent: Color::Rgb(97, 175, 239),
                muted: Color::Rgb(92, 99, 112),
                focus_border: Color::Rgb(198, 120, 221),
                blur_border: Color::Rgb(59, 64, 72),
                highlight: Color::Rgb(50, 55, 65),
                tab_active: Color::Rgb(229, 192, 123),
                tab_inactive: Color::Rgb(92, 99, 112),
            },
            ThemeName::Monokai => Palette {
                header_fg: Color::Rgb(248, 248, 242),
                header_bg: Color::Rgb(39, 40, 34),
                accent: Color::Rgb(102, 217, 239),
                muted: Color::Rgb(117, 113, 94),
                focus_border: Color::Rgb(249, 38, 114),
                blur_border: Color::Rgb(73, 72, 62),
                highlight: Color::Rgb(62, 61, 50),
                tab_active: Color::Rgb(230, 219, 116),
                tab_inactive: Color::Rgb(117, 113, 94),
            },
            ThemeName::Ayu => Palette {
                header_fg: Color::Rgb(203, 204, 198),
                header_bg: Color::Rgb(10, 14, 20),
                accent: Color::Rgb(57, 186, 230),
                muted: Color::Rgb(61, 66, 77),
                focus_border: Color::Rgb(255, 179, 81),
                blur_border: Color::Rgb(30, 36, 46),
                highlight: Color::Rgb(20, 25, 33),
                tab_active: Color::Rgb(255, 179, 81),
                tab_inactive: Color::Rgb(61, 66, 77),
            },
            ThemeName::RosePine => Palette {
                header_fg: Color::Rgb(224, 222, 244),
                header_bg: Color::Rgb(25, 23, 36),
                accent: Color::Rgb(235, 188, 186),
                muted: Color::Rgb(110, 106, 134),
                focus_border: Color::Rgb(196, 167, 231),
                blur_border: Color::Rgb(64, 61, 82),
                highlight: Color::Rgb(38, 35, 58),
                tab_active: Color::Rgb(246, 193, 119),
                tab_inactive: Color::Rgb(110, 106, 134),
            },
            ThemeName::Kanagawa => Palette {
                header_fg: Color::Rgb(220, 215, 186),
                header_bg: Color::Rgb(31, 31, 40),
                accent: Color::Rgb(126, 156, 216),
                muted: Color::Rgb(114, 115, 126),
                focus_border: Color::Rgb(149, 127, 184),
                blur_border: Color::Rgb(54, 54, 68),
                highlight: Color::Rgb(42, 42, 55),
                tab_active: Color::Rgb(230, 195, 132),
                tab_inactive: Color::Rgb(114, 115, 126),
            },
            ThemeName::GithubLight => Palette {
                header_fg: Color::Rgb(36, 41, 47),
                header_bg: Color::Rgb(221, 244, 255),
                accent: Color::Rgb(9, 105, 218),
                muted: Color::Rgb(101, 109, 118),
                focus_border: Color::Rgb(9, 105, 218),
                blur_border: Color::Rgb(208, 215, 222),
                highlight: Color::Rgb(234, 242, 255),
                tab_active: Color::Rgb(191, 135, 0),
                tab_inactive: Color::Rgb(139, 148, 158),
            },
        }
    }
}
