from __future__ import annotations

from typing import Literal, Tuple, Union


# ANSI Format strings
ANSI_CODES = {
    'reset': "\033[0m",
    'attr': "\033[%dm%s",
    '4bit': "\033[%dm%s",
    '8bit': "\033[%d;5;%dm%s",
    '24bit': "\033[%d;2;%d;%d;%dm%s"
}

# ANSI Attribute codes
ATTRIBUTES: dict[Attribute, int] = {
    "bold": 1,
    "dark": 2,
    "italic": 3,
    "underline": 4,
    "blink": 5,
    "reverse": 7,
    "concealed": 8,
    "strike": 9,
    "double-underline": 21,
    "overline": 53,
}

# Standard Foreground Colors [4-bit]
FGCOLORS_STANDARD: dict[StandardColor, int] = {
    "black": 30,
    "grey": 30,  # Actually black but kept for backwards compatibility
    "red": 31,
    "green": 32,
    "yellow": 33,
    "blue": 34,
    "magenta": 35,
    "cyan": 36,
    "light_grey": 37,
    "dark_grey": 90,
    "light_red": 91,
    "light_green": 92,
    "light_yellow": 93,
    "light_blue": 94,
    "light_magenta": 95,
    "light_cyan": 96,
    "white": 97,
}

# Standard Background colors [4-bit]
BGCOLORS_STANDARD: dict[StandardColor, int] = {
    "black": 40,
    "grey": 40,  # Actually black but kept for backwards compatibility
    "red": 41,
    "green": 42,
    "yellow": 43,
    "blue": 44,
    "magenta": 45,
    "cyan": 46,
    "light_grey": 47,
    "dark_grey": 100,
    "light_red": 101,
    "light_green": 102,
    "light_yellow": 103,
    "light_blue": 104,
    "light_magenta": 105,
    "light_cyan": 106,
    "white": 107,
}

# 8-Bit [256 colors]
COLORS_256: dict[Color256, int] = {
    'black': 0,
    'grey': 16,
    "red": 1,
    "green": 2,
    "yellow": 3,
    "blue": 4,
    "magenta": 5,
    "cyan": 6,
    "light_grey": 7,
    "dark_grey": 8,
    "light_red": 9,
    "light_green": 10,
    "light_yellow": 11,
    "light_blue": 12,
    "light_magenta": 13,
    "light_cyan": 14,
    'smokewhite': 15,
    'white': 231,
    'tan': 180,
    'honeydew': 194,
    'light_coral': 210,
    'cornsilk': 230,
    'plum': 183,
    'plum_1': 176,
    'plum_2': 219,
    'plum_dim': 96,
    'plum_dim_1': 139,
    'khaki': 185,
    'khaki_1': 228,
    'khaki_dark': 143,
    'yellow_1': 226,
    'yellow_2': 184,
    'yellow_3': 190,
    'yellow_dark': 100,
    'yellow_pale': 187,
    'yellow_green': 106,
    'yellow_green_1': 148,
    'yellow_green_2': 154,
    'aquamarine': 79,
    'aquamarine_1': 86,
    'aquamarine_2': 122,
    'violet': 177,
    'violet_dark': 92,
    'violet_dark_1': 128,
    'blue_violet': 57,
    'orchid': 170,
    'orchid_medium': 133,
    'orchid_medium_1': 134,
    'orchid_medium_2': 171,
    'orchid_light': 207,
    'orchid_light_1': 212,
    'orchid_light_2': 213,
    'gold': 220,
    'gold_1': 142,
    'gold_2': 178,
    'goldenrod': 179,
    'goldenrod_light': 186,
    'goldenrod_light_1': 221,
    'goldenrod_light_2': 222,
    'goldenrod_light_3': 227,
    'goldenrod_dark': 136,
    'salmon': 209,
    'salmon_dim': 137,
    'salmon_light': 173,
    'salmon_light_1': 216,
    'brown_rosy': 138,
    'brown_sandy': 215,
    'navajo_white': 144,
    'navajo_white_1': 223,
    'misty_rose': 181,
    'misty_rose_1': 224,
    'thistle': 182,
    'thistle_1': 225,
    'wheat': 101,
    'wheat_light': 229,
    'orange': 172,
    'orange_green': 58,
    'orange_light_1': 208,
    'orange_light_2': 214,
    'orange_dim': 94,
    'orange_dim_1': 130,
    'orange_red_1': 166,
    'orange_red_2': 202,
    'magenta_1': 127,
    'magenta_2': 163,
    'magenta_3': 164,
    'magenta_4': 165,
    'magenta_light': 200,
    'magenta_light_1': 201,
    'magenta_dark': 90,
    'magenta_dark_1': 91,
    'red_1': 124,
    'red_2': 160,
    'red_3': 196,
    'indian_red': 131,
    'indian_red_1': 167,
    'indian_red_2': 203,
    'indian_red_3': 204,
    'dark_red': 52,
    'dark_red_1': 88,
    'violet_red_medium': 126,
    'violet_red_pale': 211,
    'pink': 175,
    'pink_1': 218,
    'hot_pink': 132,
    'hot_pink_1': 168,
    'hot_pink_2': 169,
    'hot_pink_3': 205,
    'hot_pink_4': 206,
    'light_pink': 95,
    'light_pink_1': 174,
    'light_pink_2': 217,
    'pink_deep': 53,
    'pink_deep_1': 89,
    'pink_deep_2': 125,
    'pink_deep_3': 161,
    'pink_deep_4': 162,
    'pink_deep_5': 197,
    'pink_deep_6': 198,
    'pink_deep_7': 199,
    'purple': 54,
    'purple_1': 55,
    'purple_2': 56,
    'purple_3': 93,
    'purple_dim': 60,
    'purple_medium': 97,
    'purple_medium_1': 98,
    'purple_medium_2': 104,
    'purple_light': 129,
    'purple_light_1': 135,
    'purple_light_2': 140,
    'purple_light_3': 141,
    'turquoise': 30,
    'turquoise_1': 45,
    'medium_turquoise': 80,
    'dark_turquoise': 44,
    'pale_turquoise': 66,
    'pale_turquoise_1': 159,
    'dark_cyan': 36,
    'cyan_1': 43,
    'cyan_2': 50,
    'cyan_3': 51,
    "cyan_4": 87,
    'cyan_5': 123,
    'cyan_light': 116,
    'cyan_light_1': 152,
    'cyan_light_2': 195,
    'chartreuse1': 64,
    'chartreuse2': 70,
    'chartreuse3': 76,
    'chartreuse4': 82,
    'chartreuse5': 112,
    'chartreuse6': 118,
    'dark_green': 22,
    'green_1': 28,
    'green_2': 34,
    'green_3': 40,
    'green_4': 46,
    'spring_green': 29,
    'spring_green_1': 35,
    'spring_green_2': 41,
    'spring_green_3': 42,
    'spring_green_4': 47,
    'spring_green_5': 48,
    'spring_green_6': 49,
    'green_light': 119,
    'green_light_2': 120,
    'pale_green': 77,
    'pale_green_1': 114,
    'pale_green_2': 121,
    'pale_green_3': 156,
    'sea_green': 78,
    'sea_green_1': 83,
    'sea_green_2': 84,
    'sea_green_3': 85,
    'sea_green_light': 37,
    'sea_green_dark': 65,
    'sea_green_dark_1': 71,
    'sea_green_dark_2': 108,
    'sea_green_dark_3': 115,
    'sea_green_dark_4': 150,
    'sea_green_dark_5': 151,
    'sea_green_dark_6': 157,
    'sea_green_dark_7': 158,
    'sea_green_dark_8': 193,
    'olive_green_dark': 107,
    'olive_green_dark_1': 113,
    'olive_green_dark_2': 149,
    'olive_green_dark_3': 155,
    'olive_green_dark_4': 191,
    'olive_green_dark_5': 192,
    'navy_blue': 17,
    'royal_blue': 63,
    'cornflower_blue': 69,
    'blue_1': 19,
    'blue_2': 20,
    'blue_3': 21,
    'dark_blue': 18,
    'dodger_blue': 26,
    'dodger_blue_1': 27,
    'dodger_blue_2': 33,
    'cadet_blue': 72,
    'cadet_blue_2': 73,
    'slate_blue': 61,
    'slate_blue_1': 62,
    'slate_blue_2': 99,
    'slate_blue_light': 105,
    'sky_blue': 74,
    'sky_blue_1': 111,
    'sky_blue_2': 117,
    'sky_blue_light': 109,
    'sky_blue_light_1': 110,
    'sky_blue_light_2': 153,
    'sky_blue_deep': 23,
    'sky_blue_deep_1': 24,
    'sky_blue_deep_2': 25,
    'sky_blue_deep_3': 31,
    'sky_blue_deep_4': 32,
    'sky_blue_deep_5': 38,
    'sky_blue_deep_6': 39,
    'steel_blue': 67,
    'steel_blue_1': 68,
    'steel_blue_2': 75,
    'steel_blue_3': 81,
    'steel_blue_light': 146,
    'steel_blue_light_1': 147,
    'steel_blue_light_2': 189,
    'slate_gray': 103,
    'grey_dim': 59,
    'grey_dark': 102,
    'grey_light': 145,
    'gainsboro': 188,
    'grey_1': 232,
    'grey_2': 233,
    'grey_3': 234,
    'grey_4': 235,
    'grey_5': 236,
    'grey_6': 237,
    'grey_7': 238,
    'grey_8': 239,
    'grey_9': 240,
    'grey_10': 241,
    'grey_11': 242,
    'grey_12': 243,
    'grey_13': 244,
    'grey_14': 245,
    'grey_15': 246,
    'grey_16': 247,
    'grey_17': 248,
    'grey_18': 249,
    'grey_19': 250,
    'grey_20': 251,
    'grey_21': 252,
    'grey_22': 253,
    'grey_23': 254,
    'grey_24': 255
}


# Just the names of colors
STANDARD_COLORNAMES: list = list(FGCOLORS_STANDARD.keys())

COLORS256_COLORNAMES: list = list(COLORS_256.keys())


# Type Annotations
Quality = Literal['high', 'medium', 'low']

RGBTuple = Tuple[int, int, int]

Attribute = Literal[
    "bold",
    "dark",
    "italic",
    "underline",
    "blink",
    "reverse",
    "concealed",
    "strike",
    "double-underline",
    "overline",
]


StandardColor = Literal[
    "black",
    "grey",
    "red",
    "green",
    "yellow",
    "blue",
    "magenta",
    "cyan",
    "light_grey",
    "dark_grey",
    "light_red",
    "light_green",
    "light_yellow",
    "light_blue",
    "light_magenta",
    "light_cyan",
    "white",
]


Color256 = Literal[
    'black',
    'grey',
    'red',
    'green',
    'yellow',
    'blue',
    'magenta',
    'cyan',
    'light_grey',
    'dark_grey',
    'light_red',
    'light_green',
    'light_yellow',
    'light_blue',
    'light_magenta',
    'light_cyan',
    'smokewhite',
    'white',
    'tan',
    'honeydew',
    'light_coral',
    'cornsilk',
    'plum',
    'plum_1',
    'plum_2',
    'plum_dim',
    'plum_dim_1',
    'khaki',
    'khaki_1',
    'khaki_dark',
    'yellow_1',
    'yellow_2',
    'yellow_3',
    'yellow_dark',
    'yellow_pale',
    'yellow_green',
    'yellow_green_1',
    'yellow_green_2',
    'aquamarine',
    'aquamarine_1',
    'aquamarine_2',
    'violet',
    'violet_dark',
    'violet_dark_1',
    'blue_violet',
    'orchid',
    'orchid_medium',
    'orchid_medium_1',
    'orchid_medium_2',
    'orchid_light',
    'orchid_light_1',
    'orchid_light_2',
    'gold',
    'gold_1',
    'gold_2',
    'goldenrod',
    'goldenrod_light',
    'goldenrod_light_1',
    'goldenrod_light_2',
    'goldenrod_light_3',
    'goldenrod_dark',
    'salmon',
    'salmon_dim',
    'salmon_light',
    'salmon_light_1',
    'brown_rosy',
    'brown_sandy',
    'navajo_white',
    'navajo_white_1',
    'misty_rose',
    'misty_rose_1',
    'thistle',
    'thistle_1',
    'wheat',
    'wheat_light',
    'orange',
    'orange_green',
    'orange_light_1',
    'orange_light_2',
    'orange_dim',
    'orange_dim_1',
    'orange_red_1',
    'orange_red_2',
    'magenta_1',
    'magenta_2',
    'magenta_3',
    'magenta_4',
    'magenta_light',
    'magenta_light_1',
    'magenta_dark',
    'magenta_dark_1',
    'red_1',
    'red_2',
    'red_3',
    'indian_red',
    'indian_red_1',
    'indian_red_2',
    'indian_red_3',
    'dark_red',
    'dark_red_1',
    'violet_red_medium',
    'violet_red_pale',
    'pink',
    'pink_1',
    'hot_pink',
    'hot_pink_1',
    'hot_pink_2',
    'hot_pink_3',
    'hot_pink_4',
    'light_pink',
    'light_pink_1',
    'light_pink_2',
    'pink_deep',
    'pink_deep_1',
    'pink_deep_2',
    'pink_deep_3',
    'pink_deep_4',
    'pink_deep_5',
    'pink_deep_6',
    'pink_deep_7',
    'purple',
    'purple_1',
    'purple_2',
    'purple_3',
    'purple_dim',
    'purple_medium',
    'purple_medium_1',
    'purple_medium_2',
    'purple_light',
    'purple_light_1',
    'purple_light_2',
    'purple_light_3',
    'turquoise',
    'turquoise_1',
    'medium_turquoise',
    'dark_turquoise',
    'pale_turquoise',
    'pale_turquoise_1',
    'dark_cyan',
    'cyan_1',
    'cyan_2',
    'cyan_3',
    'cyan_4',
    'cyan_5',
    'cyan_light',
    'cyan_light_1',
    'cyan_light_2',
    'chartreuse1',
    'chartreuse2',
    'chartreuse3',
    'chartreuse4',
    'chartreuse5',
    'chartreuse6',
    'dark_green',
    'green_1',
    'green_2',
    'green_3',
    'green_4',
    'spring_green',
    'spring_green_1',
    'spring_green_2',
    'spring_green_3',
    'spring_green_4',
    'spring_green_5',
    'spring_green_6',
    'green_light',
    'green_light_2',
    'pale_green',
    'pale_green_1',
    'pale_green_2',
    'pale_green_3',
    'sea_green',
    'sea_green_1',
    'sea_green_2',
    'sea_green_3',
    'sea_green_light',
    'sea_green_dark',
    'sea_green_dark_1',
    'sea_green_dark_2',
    'sea_green_dark_3',
    'sea_green_dark_4',
    'sea_green_dark_5',
    'sea_green_dark_6',
    'sea_green_dark_7',
    'sea_green_dark_8',
    'olive_green_dark',
    'olive_green_dark_1',
    'olive_green_dark_2',
    'olive_green_dark_3',
    'olive_green_dark_4',
    'olive_green_dark_5',
    'navy_blue',
    'royal_blue',
    'cornflower_blue',
    'blue_1',
    'blue_2',
    'blue_3',
    'dark_blue',
    'dodger_blue',
    'dodger_blue_1',
    'dodger_blue_2',
    'cadet_blue',
    'cadet_blue_2',
    'slate_blue',
    'slate_blue_1',
    'slate_blue_2',
    'slate_blue_light',
    'sky_blue',
    'sky_blue_1',
    'sky_blue_2',
    'sky_blue_light',
    'sky_blue_light_1',
    'sky_blue_light_2',
    'sky_blue_deep',
    'sky_blue_deep_1',
    'sky_blue_deep_2',
    'sky_blue_deep_3',
    'sky_blue_deep_4',
    'sky_blue_deep_5',
    'sky_blue_deep_6',
    'steel_blue',
    'steel_blue_1',
    'steel_blue_2',
    'steel_blue_3',
    'steel_blue_light',
    'steel_blue_light_1',
    'steel_blue_light_2',
    "slate_gray",
    'grey_dim',
    'grey_dark',
    'grey_light',
    'gainsboro',
    'grey_1',
    'grey_2',
    'grey_3',
    'grey_4',
    'grey_5',
    'grey_6',
    'grey_7',
    'grey_8',
    'grey_9',
    'grey_10',
    'grey_11',
    'grey_12',
    'grey_13',
    'grey_14',
    'grey_15',
    'grey_16',
    'grey_17',
    'grey_18',
    'grey_19',
    'grey_20',
    'grey_21',
    'grey_22',
    'grey_23',
    'grey_24'
]

# Color mode
ColorMode = Union[int, Literal[4, 8, 24]]

# Master Color Type
Color = Union[str, StandardColor, Color256, RGBTuple]
