#![allow(dead_code)] // for extra colors we have generated but not used yet

use iced::border::Radius;
use iced::widget::container::Style;
use iced::widget::{button, text, text_input};
use iced::{Background, Border, Color, Shadow, Theme};

// Basic Colors
pub const COLOR_RED: Color = Color::from_rgb(0.9, 0.2, 0.2);
pub const COLOR_GREEN: Color = Color::from_rgb(0.2, 0.8, 0.2);
pub const COLOR_BLUE: Color = Color::from_rgb(0.2, 0.4, 0.9);
pub const COLOR_YELLOW: Color = Color::from_rgb(0.95, 0.9, 0.2);
pub const COLOR_ORANGE: Color = Color::from_rgb(0.95, 0.6, 0.2);
pub const COLOR_PURPLE: Color = Color::from_rgb(0.7, 0.3, 0.9);
pub const COLOR_PINK: Color = Color::from_rgb(0.95, 0.5, 0.7);
pub const COLOR_CYAN: Color = Color::from_rgb(0.2, 0.8, 0.9);

// Pastel Colors
pub const COLOR_PASTEL_BLUE: Color = Color::from_rgb(0.68, 0.85, 0.9);
pub const COLOR_PASTEL_GREEN: Color = Color::from_rgb(0.7, 0.93, 0.77);
pub const COLOR_PASTEL_YELLOW: Color = Color::from_rgb(0.99, 0.96, 0.7);
pub const COLOR_PASTEL_PINK: Color = Color::from_rgb(0.98, 0.8, 0.85);
pub const COLOR_PASTEL_PURPLE: Color = Color::from_rgb(0.8, 0.7, 0.9);
pub const COLOR_PASTEL_ORANGE: Color = Color::from_rgb(0.98, 0.85, 0.7);

// Dark Colors
pub const COLOR_DARK_RED: Color = Color::from_rgb(0.5, 0.1, 0.1);
pub const COLOR_DARK_GREEN: Color = Color::from_rgb(0.1, 0.4, 0.1);
pub const COLOR_DARK_BLUE: Color = Color::from_rgb(0.1, 0.2, 0.5);
pub const COLOR_DARK_GRAY: Color = Color::from_rgb(0.2, 0.2, 0.2);
pub const COLOR_DARK_PURPLE: Color = Color::from_rgb(0.3, 0.1, 0.4);

// Gray Scale
pub const COLOR_GRAY_10: Color = Color::from_rgb(0.1, 0.1, 0.1);
pub const COLOR_GRAY_20: Color = Color::from_rgb(0.2, 0.2, 0.2);
pub const COLOR_GRAY_30: Color = Color::from_rgb(0.3, 0.3, 0.3);
pub const COLOR_GRAY_40: Color = Color::from_rgb(0.4, 0.4, 0.4);
pub const COLOR_GRAY_50: Color = Color::from_rgb(0.5, 0.5, 0.5);
pub const COLOR_GRAY_60: Color = Color::from_rgb(0.6, 0.6, 0.6);
pub const COLOR_GRAY_70: Color = Color::from_rgb(0.7, 0.7, 0.7);
pub const COLOR_GRAY_80: Color = Color::from_rgb(0.8, 0.8, 0.8);
pub const COLOR_GRAY_90: Color = Color::from_rgb(0.9, 0.9, 0.9);

// Vibrant Colors
pub const COLOR_VIBRANT_RED: Color = Color::from_rgb(1.0, 0.0, 0.2);
pub const COLOR_VIBRANT_GREEN: Color = Color::from_rgb(0.0, 1.0, 0.3);
pub const COLOR_VIBRANT_BLUE: Color = Color::from_rgb(0.0, 0.5, 1.0);
pub const COLOR_VIBRANT_MAGENTA: Color = Color::from_rgb(1.0, 0.0, 1.0);
pub const COLOR_VIBRANT_CYAN: Color = Color::from_rgb(0.0, 1.0, 1.0);
pub const COLOR_VIBRANT_YELLOW: Color = Color::from_rgb(1.0, 1.0, 0.0);

// A dictionary of colors to use for names of other nodes
pub const COLOR_DICTIONARY: [Color; 15] = [
    COLOR_RED,
    COLOR_GREEN,
    COLOR_BLUE,
    COLOR_CYAN,
    COLOR_PINK,
    COLOR_YELLOW,
    COLOR_GREEN,
    COLOR_ORANGE,
    COLOR_PURPLE,
    COLOR_VIBRANT_BLUE,
    COLOR_VIBRANT_MAGENTA,
    COLOR_PASTEL_BLUE,
    COLOR_PASTEL_GREEN,
    COLOR_PASTEL_PINK,
    COLOR_PASTEL_PURPLE,
];

pub const TEXT_INPUT_BACKGROUND: Background =
    Background::Color(Color::from_rgba(0.25, 0.25, 0.25, 1.0));

const TEXT_INPUT_R: f32 = 20.0;

const RADIUS_2: Radius = Radius {
    top_left: 2.0,
    top_right: 2.0,
    bottom_right: 2.0,
    bottom_left: 2.0,
};

const RADIUS_4: Radius = Radius {
    top_left: 4.0,
    top_right: 4.0,
    bottom_right: 4.0,
    bottom_left: 4.0,
};

pub const NO_SHADOW: Shadow = Shadow {
    color: Color::TRANSPARENT,
    offset: iced::Vector { x: 0.0, y: 0.0 },
    blur_radius: 0.0,
};

pub const NO_BORDER: Border = Border {
    color: Color::TRANSPARENT,
    width: 0.0,
    radius: RADIUS_2,
};

pub const RADIUS_12: Radius = Radius {
    top_left: 12.0,
    top_right: 12.0,
    bottom_right: 12.0,
    bottom_left: 12.0,
};

pub const TOOLTIP_BORDER: Border = Border {
    color: Color::WHITE,
    width: 1.0,
    radius: RADIUS_4,
};

pub const VIEW_BUTTON_BORDER: Border = Border {
    color: Color::TRANSPARENT,
    width: 2.0,
    radius: TEXT_INPUT_RADIUS,
};

const TEXT_INPUT_RADIUS: Radius = Radius {
    top_left: TEXT_INPUT_R,
    top_right: TEXT_INPUT_R,
    bottom_right: TEXT_INPUT_R,
    bottom_left: TEXT_INPUT_R,
};

pub const CYAN: Color = Color::from_rgba(0.0, 0.8, 0.8, 1.0);

const TEXT_INPUT_BORDER_ACTIVE: Border = Border {
    radius: TEXT_INPUT_RADIUS, // rounded corners
    width: 2.0,
    color: CYAN,
};

const TEXT_INPUT_BORDER: Border = Border {
    radius: TEXT_INPUT_RADIUS, // rounded corners
    width: 2.0,
    color: Color::WHITE,
};

const TEXT_INPUT_BORDER_DISABLED: Border = Border {
    radius: TEXT_INPUT_RADIUS, // rounded corners
    width: 2.0,
    color: Color::TRANSPARENT,
};

pub const TEXT_INPUT_PLACEHOLDER_COLOR: Color = Color::from_rgba(0.5, 0.5, 0.5, 1.0);

pub fn text_input_style(_theme: &Theme, status: text_input::Status) -> text_input::Style {
    match status {
        text_input::Status::Active => text_input::Style {
            background: TEXT_INPUT_BACKGROUND,
            border: TEXT_INPUT_BORDER,
            icon: Color::WHITE,
            placeholder: TEXT_INPUT_PLACEHOLDER_COLOR,
            value: Color::WHITE,
            selection: Default::default(),
        },
        text_input::Status::Hovered => text_input::Style {
            background: TEXT_INPUT_BACKGROUND,
            border: TEXT_INPUT_BORDER,
            icon: Color::WHITE,
            placeholder: TEXT_INPUT_PLACEHOLDER_COLOR,
            value: Color::WHITE,
            selection: Default::default(),
        },
        text_input::Status::Focused => text_input::Style {
            background: TEXT_INPUT_BACKGROUND,
            border: TEXT_INPUT_BORDER_ACTIVE,
            icon: Color::WHITE,
            placeholder: TEXT_INPUT_PLACEHOLDER_COLOR,
            value: Color::WHITE,
            selection: Default::default(),
        },
        text_input::Status::Disabled => text_input::Style {
            background: TEXT_INPUT_BACKGROUND,
            border: TEXT_INPUT_BORDER_DISABLED,
            icon: Color::WHITE,
            placeholder: TEXT_INPUT_PLACEHOLDER_COLOR,
            value: Color::WHITE,
            selection: Default::default(),
        },
    }
}

const BUTTON_BORDER_ACTIVE: Border = Border {
    radius: TEXT_INPUT_RADIUS, // rounded corners
    width: 2.0,
    color: CYAN,
};

const BUTTON_BORDER_DISABLED: Border = Border {
    radius: TEXT_INPUT_RADIUS, // rounded corners
    width: 2.0,
    color: Color::TRANSPARENT,
};

pub fn source_tooltip_style(_theme: &Theme) -> Style {
    Style {
        text_color: Some(Color::WHITE),
        background: Some(Color::BLACK.into()),
        border: TOOLTIP_BORDER,
        shadow: NO_SHADOW,
    }
}

pub fn transparent_button_style(
    _theme: &Theme,
    status: button::Status,
    color: Color,
) -> button::Style {
    let mut style = match status {
        button::Status::Active => button::Style {
            background: None,
            text_color: Color::WHITE,
            border: NO_BORDER,
            shadow: NO_SHADOW,
        },
        button::Status::Hovered => button::Style {
            background: None,
            text_color: Color::WHITE,
            border: NO_BORDER,
            shadow: NO_SHADOW,
        },
        button::Status::Pressed => button::Style {
            background: None,
            text_color: Color::WHITE,
            border: NO_BORDER,
            shadow: NO_SHADOW,
        },
        button::Status::Disabled => button::Style {
            background: None,
            text_color: Color::WHITE,
            border: NO_BORDER,
            shadow: NO_SHADOW,
        },
    };

    style.text_color = color;
    style
}

pub fn fav_button_style(_theme: &Theme, status: button::Status) -> button::Style {
    match status {
        button::Status::Active => button::Style {
            background: Some(Background::Color(Color::TRANSPARENT)),
            text_color: Color::WHITE,
            border: NO_BORDER,
            shadow: NO_SHADOW,
        },
        button::Status::Hovered => button::Style {
            background: Some(Background::Color(CYAN)),
            text_color: Color::WHITE,
            border: BUTTON_BORDER_ACTIVE,
            shadow: NO_SHADOW,
        },
        button::Status::Pressed => button::Style {
            background: Some(Background::Color(Color::from_rgba(0.0, 0.0, 0.8, 1.0))),
            text_color: Color::WHITE,
            border: BUTTON_BORDER_ACTIVE,
            shadow: NO_SHADOW,
        },
        button::Status::Disabled => button::Style {
            background: Some(Background::Color(Color::TRANSPARENT)),
            text_color: Color::WHITE,
            border: BUTTON_BORDER_DISABLED,
            shadow: NO_SHADOW,
        },
    }
}

pub fn button_chip_style(_theme: &Theme, status: button::Status) -> button::Style {
    match status {
        button::Status::Active => button::Style {
            background: Some(Background::Color(Color::from_rgba(0.0, 0.0, 0.8, 1.0))),
            text_color: Color::WHITE,
            border: BUTTON_BORDER_ACTIVE,
            shadow: NO_SHADOW,
        },
        button::Status::Hovered => button::Style {
            background: Some(Background::Color(CYAN)),
            text_color: Color::WHITE,
            border: BUTTON_BORDER_ACTIVE,
            shadow: NO_SHADOW,
        },
        button::Status::Pressed => button::Style {
            background: Some(Background::Color(Color::from_rgba(0.0, 0.0, 0.8, 1.0))),
            text_color: Color::WHITE,
            border: BUTTON_BORDER_ACTIVE,
            shadow: NO_SHADOW,
        },
        button::Status::Disabled => button::Style {
            background: Some(Background::Color(Color::from_rgba(0.0, 0.0, 0.8, 1.0))),
            text_color: Color::WHITE,
            border: BUTTON_BORDER_DISABLED,
            shadow: NO_SHADOW,
        },
    }
}

const MESSAGE_BORDER: Border = Border {
    radius: RADIUS_12, // rounded corners
    width: 2.0,
    color: Color::WHITE,
};

const DAY_SEPARATOR_BORDER: Border = Border {
    radius: RADIUS_12, // rounded corners
    width: 2.0,
    color: Color::TRANSPARENT,
};

// TODO make a closure that reacts to the theme
pub const MESSAGE_TEXT_STYLE: text::Style = text::Style {
    color: Some(Color::WHITE),
};

pub const TIME_TEXT_COLOR: Color = Color::from_rgba(0.6, 0.6, 0.6, 1.0);
pub const TIME_TEXT_SIZE: f32 = 11.0;
pub const TIME_TEXT_WIDTH: f32 = 30.0;

pub const MY_MESSAGE_BUBBLE_STYLE: Style = Style {
    text_color: Some(Color::WHITE),
    background: Some(Background::Color(Color::from_rgba(0.08, 0.3, 0.22, 1.0))),
    border: MESSAGE_BORDER,
    shadow: NO_SHADOW,
};

pub const DAY_SEPARATOR_STYLE: Style = Style {
    text_color: Some(Color::WHITE),
    background: Some(Background::Color(Color::from_rgba(0.0, 0.0, 0.0, 1.0))),
    border: DAY_SEPARATOR_BORDER,
    shadow: NO_SHADOW,
};

pub const OTHERS_MESSAGE_BUBBLE_STYLE: Style = Style {
    text_color: Some(Color::WHITE),
    background: Some(Background::Color(Color::from_rgba(0.0, 0.0, 0.0, 1.0))),
    border: MESSAGE_BORDER,
    shadow: NO_SHADOW,
};

const NAME_BOX_BORDER: Border = Border {
    radius: Radius {
        top_left: 6.0,
        top_right: 6.0,
        bottom_right: 6.0,
        bottom_left: 6.0,
    }, // rounded corners
    width: 1.0,
    color: Color::WHITE,
};

pub const NAME_BOX_STYLE: Style = Style {
    text_color: Some(Color::WHITE),
    background: Some(Background::Color(Color::from_rgba(0.0, 0.0, 0.0, 1.0))),
    border: NO_BORDER,
    shadow: NO_SHADOW,
};

pub fn name_box_style(_theme: &Theme) -> Style {
    NAME_BOX_STYLE
}
