"""
A colorscheme for this project needs:
fg and bg 0-4, where 0 is used as default font / background
fg-<color> and bg-<color> where <color> is  "red", "orange", "yellow", "green", "aqua", "blue", "purple", "gray"
"""

from math import floor


colors = ["red", "orange", "yellow", "green", "aqua", "blue", "purple", "gray"]

def brightness(color:str, percent:float):
    if color.startswith("#"):
        color = color.strip("#")
        newcolor = "#"
    else:
        newcolor = ""
    for i in range(3):
        c = float(int(color[i*2:i*2+2], 16))
        c = int(round(max(0, min(c*percent, 0xff)), 0))
        newcolor += f"{c:02x}"
    return newcolor

#
# GRUVBOX
#
p_gruvbox = {
    "fg0":          "#282828",
    "fg0-hard":     "#1d2021",
    "fg0-soft":     "#32302f",
    "fg1":          "#3c3836",
    "fg2":          "#504945",
    "fg3":          "#665c54",
    "fg4":          "#7c6f64",
    "bg0":          "#fbf1c7",
    "bg0-hard":     "#f9f5d7",
    "bg0-soft":     "#f2e5bc",
    "bg1":          "#ebdbb2",
    "bg2":          "#d5c4a1",
    "bg3":          "#bdae93",
    "bg4":          "#a89984",
    "dark-red":     "#cc241d",
    "dark-green":   "#98971a",
    "dark-yellow":  "#d79921",
    "dark-blue":    "#458588",
    "dark-purple":  "#b16286",
    "dark-aqua":    "#689d6a",
    "dark-orange":  "#d65d0e",
    "dark-gray":    "#928374",
    "light-red":    "#fb4934",
    "light-green":  "#b8bb26",
    "light-yellow": "#fabd2f",
    "light-blue":   "#83a598",
    "light-purple": "#d3869b",
    "light-aqua":   "#8ec07c",
    "light-orange": "#f38019",
    "light-gray":   "#a89984",
    "alt-red":      "#9d0006",
    "alt-green":    "#79740e",
    "alt-yellow":   "#b57614",
    "alt-blue":     "#076678",
    "alt-purple":   "#8f3f71",
    "alt-aqua":     "#427b58",
    "alt-orange":   "#af3a03",
    "alt-gray":     "#7c6f64",
}

def gruvbox_light():
    GRUVBOX_LIGHT = { "fg0": p_gruvbox["fg0-hard"], "bg0": p_gruvbox["bg0-hard"] } \
        | {f"fg{n}": p_gruvbox[f"fg{n}"] for n in range(1,5)} \
        | {f"bg{n}": p_gruvbox[f"bg{n}"] for n in range(1,5)} \
        | {f"fg-{n}": p_gruvbox[f"alt-{n}"] for n in colors} \
        | {f"bg-{n}": p_gruvbox[f"light-{n}"] for n in colors}
    return GRUVBOX_LIGHT

def gruvbox_dark():
    GRUVBOX_DARK = { "fg0": p_gruvbox["bg0-hard"], "bg0": p_gruvbox["fg0-hard"] } \
        | {f"fg{n}": p_gruvbox[f"bg{n}"] for n in range(1,5)} \
        | {f"bg{n}": p_gruvbox[f"fg{n}"] for n in range(1,5)} \
        | {f"fg-{n}": p_gruvbox[f"light-{n}"] for n in colors} \
        | {f"bg-{n}": p_gruvbox[f"dark-{n}"] for n in colors}
    return GRUVBOX_DARK

#
# LEGACY
#
p_legacy = {
    "fg0":              "#fcfcfc",
    "bg0":              "#333333",
    "red":              "#d12229",
    "green":            "#007940",
    "yellow":           "#ffc615",
    "blue":             "#2440fe",
    "purple":           "#4D1037",
    "aqua":             "#008585",
    "orange":           "#f68a1e",
    "gray":             "#928374",
}

def legacy():
    LEGACY = \
        { f"fg{n}": brightness(p_legacy["fg0"], 1-n/8) for n in range(5)} \
        | { f"bg{n}": brightness(p_legacy["bg0"], 1+n/8) for n in range(5)} \
        | { f"bg-{n}": c for n,c in p_legacy.items() } \
        | { f"fg-{n}": brightness(c, 2.0) for n,c in p_legacy.items() }
    return LEGACY

#
# TUM
#
p_tum = {
    "dark-blue":		"#072140",
    "light-blue":	    "#5E94D4",
    "alt-blue":	        "#3070B3",
    "light-yellow":	    "#FED702",
    "dark-yellow":	    "#CBAB01",
    "alt-yellow":	    "#FEDE34",
    "light-orange":	    "#F7811E",
    "dark-orange":	    "#D99208",
    "alt-orange":	    "#F9BF4E",
    "light-purple":	    "#B55CA5",
    "dark-purple":		"#9B468D",
    "alt-purple":		"#C680BB",
    "light-red":	    "#EA7237",
    "dark-red":	        "#D95117",
    "alt-red":	        "#EF9067",
    "light-green":      "#9FBA36",
    "dark-green":       "#7D922A",
    "alt-green":	    "#B6CE55",
    "light-gray":	    "#475058",
    "dark-gray":	    "#20252A",
    "alt-gray":	        "#333A41",
    "light-aqua":       "#689d6a",
    "dark-aqua":        "#427b58",  # taken aquas from gruvbox
    "fg0-hard":	        "#000000",
    "fg0":		        "#000000",
    "fg0-soft":	        "#20252A",
    "fg1":               "#072140",
    "fg2":	            "#333A41",
    "fg3":	            "#475058",
    "fg4":	            "#6A757E",
    "bg0-hard":	        "#FFFFFF",
    "bg0":		        "#FBF9FA",
    "bg0-soft":	        "#EBECEF",
    "bg1":	            "#DDE2E6",
    "bg2":	            "#E3EEFA",
    "bg3":	            "#F0F5FA",
}

def tum():
    TUM = {}
    for n,c in p_tum.items():
        n2 = n.replace("light", "bg").replace("dark", "fg")
        TUM[n2] = c
    TUM["fg-blue"] = p_tum["alt-blue"]  # dark blue is too black
    return TUM

#
# STUPID
#
p_stupid = {
    "bg0":              "#0505aa",
    "fg0":              "#ffffff",
    "red":              "#ff0000",
    "green":            "#23ff81",
    "yellow":           "#ffff00",
    "blue":             "#5555ff",
    "purple":           "#b00b69",
    "aqua":             "#00ffff",
    "orange":           "#ffa500",
    "gray":             "#444444",
}
def stupid():
    LEGACY = \
        { f"fg{n}": brightness(p_stupid["fg0"], 1-n/8) for n in range(5)} \
        | { f"bg{n}": brightness(p_stupid["bg0"], 1+n/8) for n in range(5)} \
        | { f"bg-{n}": c for n,c in p_stupid.items() } \
        | { f"fg-{n}": brightness(c, 2.0) for n,c in p_stupid.items() }
    return LEGACY

