// src/config/colors/themes.rs
use ratatui::style::Color;
use canvas::canvas::CanvasTheme;

#[derive(Debug, Clone)]
pub struct Theme {
    pub bg: Color,
    pub fg: Color,
    pub accent: Color,
    pub secondary: Color,
    pub highlight: Color,
    pub warning: Color,
    pub border: Color,
    pub highlight_bg: Color,
    pub inactive_highlight_bg: Color,// admin panel no idea what it really is
}

impl Theme {
    pub fn from_str(theme_name: &str) -> Self {
        match theme_name.to_lowercase().as_str() {
            "dark" => Self::dark(),
            "high_contrast" => Self::high_contrast(),
            _ => Self::light(),
        }
    }

    // Default light theme
    pub fn light() -> Self {
        Self {
            bg: Color::Rgb(245, 245, 245), // Light gray
            fg: Color::Rgb(64, 64, 64),    // Dark gray
            accent: Color::Rgb(173, 216, 230), // Pastel blue
            secondary: Color::Rgb(255, 165, 0), // Orange for secondary
            highlight: Color::Rgb(152, 251, 152), // Pastel green
            warning: Color::Rgb(255, 182, 193), // Pastel pink
            border: Color::Rgb(220, 220, 220), // Light gray border
            highlight_bg: Color::Rgb(70, 70, 70), // Darker grey for highlight background
            inactive_highlight_bg: Color::Rgb(50, 50, 50),
        }
    }

    // High-contrast dark theme
    pub fn dark() -> Self {
        Self {
            bg: Color::Rgb(30, 30, 30),     // Dark background
            fg: Color::Rgb(255, 255, 255),  // White text
            accent: Color::Rgb(0, 191, 255), // Bright blue
            secondary: Color::Rgb(255, 215, 0), // Gold for secondary
            highlight: Color::Rgb(50, 205, 50), // Bright green
            warning: Color::Rgb(255, 99, 71), // Bright red
            border: Color::Rgb(100, 100, 100), // Medium gray border
            highlight_bg: Color::Rgb(180, 180, 180), // Lighter grey for highlight background
            inactive_highlight_bg: Color::Rgb(50, 50, 50),
        }
    }

    // High-contrast light theme
    pub fn high_contrast() -> Self {
        Self {
            bg: Color::Rgb(255, 255, 255), // White background
            fg: Color::Rgb(0, 0, 0),       // Black text
            accent: Color::Rgb(0, 0, 255), // Blue
            secondary: Color::Rgb(255, 140, 0), // Dark orange for secondary
            highlight: Color::Rgb(0, 128, 0), // Green
            warning: Color::Rgb(255, 0, 0), // Red
            border: Color::Rgb(0, 0, 0),   // Black border
            highlight_bg: Color::Rgb(180, 180, 180), // Lighter grey for highlight background
            inactive_highlight_bg: Color::Rgb(50, 50, 50),
        }
    }
}

impl Default for Theme {
    fn default() -> Self {
        Self::light() // Default to light theme
    }
}

impl CanvasTheme for Theme {
    fn bg(&self) -> Color {
        self.bg
    }

    fn fg(&self) -> Color {
        self.fg
    }

    fn border(&self) -> Color {
        self.border
    }

    fn accent(&self) -> Color {
        self.accent
    }

    fn secondary(&self) -> Color {
        self.secondary
    }

    fn highlight(&self) -> Color {
        self.highlight
    }

    fn highlight_bg(&self) -> Color {
        self.highlight_bg
    }

    fn warning(&self) -> Color {
        self.warning
    }
}
