from cycler import cycler
from matplotlib import font_manager
from pyfonts import load_google_font


def _set_family(family, **kargs):
    font = load_google_font(family, **kargs)
    font_file = font.get_file()
    font_manager.fontManager.addfont(font_file)
    return font.get_name()


darker_theme = {
    "name": "darker",
    "description": "A sleek, no-frills dark theme with high contrast and a modern feel",
    "theme": {
        "font.family": _set_family("Oswald"),
        "axes.spines.top": False,
        "axes.spines.right": False,
        "xtick.minor.visible": False,
        "xtick.major.size": 0,
        "ytick.major.size": 0,
        "ytick.minor.visible": False,
        "scatter.marker": "H",
        "lines.linewidth": 2.5,
        "yaxis.labellocation": "top",
        "xaxis.labellocation": "right",
        "axes.labelsize": 12,
        "axes.linewidth": 1.5,
        "text.color": "#fff",
        "axes.facecolor": "#282828",
        "figure.facecolor": "#282828",
        "axes.labelcolor": "#eeeeee",
        "axes.edgecolor": "#eeeeee",
        "xtick.color": "#eeeeee",
        "ytick.color": "#eeeeee",
        "axes.prop_cycle": cycler(
            "color", ["#FED789", "#A4BED5", "#72874E", "#023743", "#476F84", "#453947"]
        ),
    },
}


yellowish_theme = {
    "name": "yellowish",
    "description": "A bold, National Geographic-inspired theme with a warm yellow backdrop",
    "theme": {
        "font.family": _set_family("Delius"),
        "ytick.minor.visible": False,
        "xtick.minor.visible": False,
        "xtick.major.size": 0,
        "ytick.major.size": 0,
        "axes.spines.top": False,
        "axes.spines.right": False,
        "ytick.major.pad": 5,
        "xtick.major.pad": 5,
        "axes.grid": True,
        "yaxis.labellocation": "top",
        "xaxis.labellocation": "right",
        "grid.linewidth": 0.6,
        "grid.alpha": 0.2,
        "grid.color": "#5d5d5d",
        "grid.linestyle": "-",
        "legend.edgecolor": "#7e7e7e",
        "axes.edgecolor": "#be1414",
        "axes.labelcolor": "#be1414",
        "axes.titlecolor": "#be1414",
        "text.color": "#be1414",
        "axes.facecolor": "#f7dd7e",
        "figure.facecolor": "#f7dd7e",
        "axes.linewidth": 1.2,
        "axes.prop_cycle": cycler(
            "color", ["#000000", "#555555", "#7e7e7e", "#b1b1b1", "#ececec"]
        ),
    },
}

urban_theme = {
    "name": "urban",
    "description": "A clean, professional theme featuring the Urbanist font and muted tones.",
    "theme": {
        "font.family": _set_family("Urbanist"),
        "ytick.minor.visible": False,
        "xtick.minor.visible": False,
        "xtick.major.size": 0,
        "ytick.major.size": 0,
        "ytick.major.pad": 5,
        "xtick.major.pad": 5,
        "axes.spines.top": False,
        "axes.spines.right": False,
        "yaxis.labellocation": "top",
        "xaxis.labellocation": "right",
        "axes.grid": True,
        "grid.linewidth": 0.6,
        "grid.alpha": 0.1,
        "ytick.labelsize": 9,
        "xtick.labelsize": 9,
        "grid.linestyle": "-",
        "axes.linewidth": 1.2,
        "grid.color": "#1e1d1d",
        "axes.edgecolor": "#efefef",
        "axes.facecolor": "#efefef",
        "figure.facecolor": "#efefef",
        "axes.prop_cycle": cycler(
            "color", ["#F56455", "#15134B", "#87C785", "#572F30"]
        ),
    },
}

wsj_theme = {
    "name": "wsj",
    "description": "A refined, newspaper-style theme inspired by the Wall Street Journal.",
    "theme": {
        "font.family": _set_family("Crimson Pro"),
        "ytick.minor.visible": False,
        "xtick.minor.visible": False,
        "xtick.major.size": 0,
        "ytick.major.size": 0,
        "axes.spines.top": False,
        "axes.spines.right": False,
        "axes.spines.left": False,
        "yaxis.labellocation": "top",
        "xaxis.labellocation": "right",
        "ytick.major.pad": 5,
        "xtick.major.pad": 5,
        "axes.grid": True,
        "grid.linewidth": 0.8,
        "grid.linestyle": "-",
        "axes.linewidth": 1.2,
        "grid.alpha": 0.1,
        "grid.color": "#1e1d1d",
        "axes.edgecolor": "#1f1f1f",
        "axes.facecolor": "#f8ecdc",
        "figure.facecolor": "#f8ecdc",
        "axes.prop_cycle": cycler(
            "color",
            [
                "#855C75",
                "#D9AF6B",
                "#AF6458",
                "#736F4C",
                "#526A83",
                "#625377",
                "#68855C",
                "#9C9C5E",
                "#A06177",
                "#8C785D",
                "#467378",
                "#7C7C7C",
            ],
        ),
    },
}

economist_theme = {
    "name": "economist",
    "description": "A crisp, data-focused theme with subtle gridlines and sharp contrasts.",
    "theme": {
        "font.family": _set_family("Volkhov"),
        "ytick.minor.visible": False,
        "xtick.minor.visible": True,
        "xtick.major.size": 6,
        "xtick.minor.size": 3,
        "ytick.major.size": 0,
        "axes.spines.top": False,
        "axes.spines.right": False,
        "axes.spines.left": False,
        "ytick.major.pad": 5,
        "xtick.major.pad": 5,
        "yaxis.labellocation": "top",
        "xaxis.labellocation": "right",
        "axes.grid": True,
        "grid.linewidth": 0.4,
        "grid.linestyle": "-",
        "axes.linewidth": 1.2,
        "axes.grid.axis": "y",
        "text.color": "#3d3d3d",
        "grid.color": "#989797",
        "axes.edgecolor": "#1f1f1f",
        "axes.facecolor": "#e8f4f4",
        "figure.facecolor": "#e8f4f4",
        "axes.prop_cycle": cycler(
            "color",
            [
                "#DB444B",
                "#006BA2",
                "#3EBCD2",
                "#379A8B",
                "#EBB434",
                "#B4BA39",
                "#9A607F",
                "#D1B07C",
                "#758D99",
            ],
        ),
    },
}

minimal_theme = {
    "name": "minimal",
    "description": "A pure, distraction-free theme with a simple monochrome palette.",
    "theme": {
        "font.family": _set_family("Inter"),
        "ytick.minor.visible": False,
        "xtick.minor.visible": False,
        "xtick.major.size": 0,
        "ytick.major.size": 0,
        "axes.spines.top": False,
        "axes.spines.right": False,
        "axes.spines.left": False,
        "axes.spines.bottom": False,
        "ytick.major.pad": 5,
        "xtick.major.pad": 5,
        "axes.grid": True,
        "grid.linewidth": 0.8,
        "yaxis.labellocation": "top",
        "xaxis.labellocation": "right",
        "grid.linestyle": "-",
        "grid.alpha": 0.1,
        "axes.linewidth": 1.2,
        "grid.color": "#383838",
        "text.color": "#000000",
        "axes.edgecolor": "#000000",
        "axes.facecolor": "#ffffff",
        "figure.facecolor": "#ffffff",
        "axes.prop_cycle": cycler(
            "color",
            ["#678096", "#ACC2CF", "#CD5733", "#979461", "#A12A19"],
        ),
    },
}

ft_theme = {
    "name": "ft",
    "description": "A sophisticated, no-nonsense theme with a muted palette and strong typographic clarity, echoing the Financial Times' aesthetic.",
    "theme": {
        "font.family": _set_family("Noto Sans"),
        "ytick.minor.visible": False,
        "xtick.minor.visible": False,
        "xtick.major.size": 10,
        "ytick.major.size": 0,
        "axes.spines.top": False,
        "axes.spines.right": False,
        "axes.spines.left": False,
        "axes.spines.bottom": True,
        "ytick.major.pad": 5,
        "xtick.major.pad": 5,
        "yaxis.labellocation": "top",
        "xaxis.labellocation": "right",
        "axes.grid": False,
        "lines.linewidth": 2.5,
        "axes.linewidth": 0.8,
        "text.color": "#ebebeb",
        "axes.labelcolor": "#a2a2a2",
        "axes.edgecolor": "#a2a2a2",
        "xtick.color": "#a2a2a2",
        "ytick.color": "#a2a2a2",
        "axes.facecolor": "#302c34",
        "figure.facecolor": "#302c34",
        "axes.prop_cycle": cycler(
            "color",
            ["#f4245c", "#FF8811", "#9DD9D2", "#046E8F"],
        ),
    },
}

retro_theme = {
    "name": "retro",
    "description": "A nostalgic theme inspired by vintage graphics and retro gaming.",
    "theme": {
        "font.family": _set_family("VT323"),
        "axes.spines.top": False,
        "axes.spines.right": False,
        "xtick.minor.visible": False,
        "ytick.minor.visible": False,
        "xtick.major.size": 5,
        "ytick.major.size": 5,
        "yaxis.labellocation": "top",
        "xaxis.labellocation": "right",
        "axes.grid": True,
        "grid.linewidth": 1.0,
        "grid.linestyle": ":",
        "grid.alpha": 0.35,
        "grid.color": "#ffffff",
        "axes.linewidth": 1.5,
        "axes.facecolor": "#000033",
        "figure.facecolor": "#000033",
        "text.color": "#ffffff",
        "axes.labelcolor": "#ffffff",
        "axes.edgecolor": "#ffffff",
        "xtick.color": "#ffffff",
        "ytick.color": "#ffffff",
        "axes.prop_cycle": cycler(
            "color",
            ["#FF69B4", "#00FF00", "#00FFFF", "#FFD700", "#FF4500"],
        ),
    },
}

nature_theme = {
    "name": "nature",
    "description": "A calming theme inspired by natural landscapes, with earthy tones and organic shapes.",
    "theme": {
        "font.family": _set_family("Quicksand"),
        "axes.spines.top": False,
        "axes.spines.right": False,
        "xtick.minor.visible": False,
        "ytick.minor.visible": False,
        "xtick.major.size": 4,
        "ytick.major.size": 4,
        "ytick.labelsize": 8,
        "xtick.labelsize": 8,
        "yaxis.labellocation": "top",
        "xaxis.labellocation": "right",
        "axes.grid": True,
        "grid.linewidth": 0.5,
        "grid.linestyle": "--",
        "grid.alpha": 0.2,
        "grid.color": "#656565",
        "axes.edgecolor": "#A9A9A9",
        "axes.facecolor": "#F5F5DC",
        "figure.facecolor": "#F5F5DC",
        "axes.prop_cycle": cycler(
            "color", ["#6B8E23", "#3D9970", "#8B4513", "#87CEEB", "#FFD700", "#FFA500"]
        ),
        "text.color": "#3D9970",
        "axes.labelcolor": "#3D9970",
        "axes.titlecolor": "#3D9970",
    },
}

monoblue_theme = {
    "name": "monoblue",
    "description": "A high-contrast theme using shades of blue to emphasize data trends and maintain a clean, professional aesthetic.",
    "theme": {
        "font.family": _set_family("Roboto"),
        "axes.spines.top": False,
        "axes.spines.right": False,
        "xtick.minor.visible": False,
        "xtick.major.size": 5,
        "ytick.major.size": 5,
        "ytick.minor.visible": False,
        "yaxis.labellocation": "top",
        "xaxis.labellocation": "right",
        "scatter.marker": "o",
        "lines.linewidth": 2.0,
        "axes.labelsize": 12,
        "axes.linewidth": 1.0,
        "text.color": "#002060",
        "axes.facecolor": "#EBF5FF",
        "figure.facecolor": "#EBF5FF",
        "axes.labelcolor": "#002060",
        "axes.edgecolor": "#002060",
        "xtick.color": "#002060",
        "ytick.color": "#002060",
        "axes.prop_cycle": cycler(
            "color", ["#002060", "#4682B4", "#ADD8E6", "#B0C4DE", "#778899"]
        ),
    },
}

vscode_dark_theme = {
    "name": "vscode-dark",
    "description": "A dark theme inspired by Visual Studio Code's dark mode.",
    "theme": {
        "font.family": _set_family("Fira Code"),
        "axes.spines.top": False,
        "axes.spines.right": False,
        "lines.color": "white",
        "patch.edgecolor": "white",
        "text.color": "white",
        "axes.facecolor": "#1f1f1f",
        "axes.edgecolor": "white",
        "axes.labelcolor": "white",
        "xtick.color": "white",
        "ytick.color": "white",
        "grid.color": "white",
        "figure.facecolor": "#1f1f1f",
        "figure.edgecolor": "#1f1f1f",
        "patch.facecolor": "C0",
        "boxplot.boxprops.color": "white",
        "boxplot.capprops.color": "white",
        "boxplot.flierprops.color": "white",
        "boxplot.flierprops.markeredgecolor": "white",
        "boxplot.whiskerprops.color": "white",
        "image.cmap": "cividis",
        "axes.prop_cycle": cycler(
            "color",
            [
                "#4EC9B0",
                "#9CDCFE",
                "#C586C0",
                "#DCDCAA",
                "#6a9955",
                "#CE9178",
                "#4FC1FF",
                "#d16969",
                "#569cd6",
                "#d7ba7d",
                "#C8C8C8",
                "#ce9178",
                "#b5cea8",
            ],
        ),
    },
}

greenwave_theme = {
    "name": "greenwave",
    "description": "A sleek, dark-themed aesthetic with vibrant green accents, inspired by modern streaming interfaces. Designed for clarity and style, with bold typography and a focus on visual harmony.",
    "theme": {
        "font.family": _set_family("Plus Jakarta Sans", weight=800),
        "axes.facecolor": "#000000",
        "figure.facecolor": "#000000",
        "axes.labelcolor": "#FFFFFF",
        "axes.labelsize": 13,
        "axes.linewidth": 1.5,
        "axes.grid": True,
        "grid.color": "#1ED760",
        "grid.alpha": 0.3,
        "grid.linewidth": 0.8,
        "grid.linestyle": "-",
        "xtick.color": "#FFFFFF",
        "ytick.color": "#FFFFFF",
        "xtick.major.size": 0,
        "ytick.major.size": 0,
        "xtick.minor.visible": False,
        "ytick.minor.visible": False,
        "text.color": "#FFFFFF",
        "lines.linewidth": 2,
        "lines.markersize": 6,
        "legend.facecolor": "#000000",
        "legend.edgecolor": "#1ED760",
        "legend.fontsize": 10,
        "axes.prop_cycle": cycler(
            "color",
            [
                "#1ED760",
                "#FFFFFF",
                "#00394D",
                "#F05F6D",
                "#3490BB",
                "#89CDB4",
                "#FFDE90",
            ],
        ),
    },
}

lighter_theme = {
    "name": "lighter",
    "description": "A clean, modern theme inspired by the lighter aesthetic, perfect for technical charts.",
    "theme": {
        "font.family": _set_family("Outfit"),
        "axes.spines.top": False,
        "axes.spines.right": False,
        "xtick.minor.visible": False,
        "ytick.minor.visible": False,
        "xtick.major.size": 0,
        "ytick.major.size": 0,
        "ytick.major.pad": 8,
        "xtick.major.pad": 8,
        "axes.grid": True,
        "yaxis.labellocation": "top",
        "xaxis.labellocation": "right",
        "grid.linewidth": 0.5,
        "grid.alpha": 0.3,
        "grid.color": "#888888",
        "grid.linestyle": "-",
        "axes.facecolor": "#f6f8fa",
        "figure.facecolor": "#f6f8fa",
        "axes.edgecolor": "#d0d7de",
        "axes.labelcolor": "#24292f",
        "axes.titlecolor": "#24292f",
        "text.color": "#24292f",
        "xtick.color": "#24292f",
        "ytick.color": "#24292f",
        "axes.linewidth": 1.2,
        "axes.prop_cycle": cycler(
            "color",
            [
                "#72b7b2",  # teal
                "#f58518",  # orange
                "#e45756",  # coral red
                "#a05195",  # purple
                "#54a24b",  # green
            ],
        ),
    },
}

nord_theme = {
    "name": "nord",
    "description": "A crisp, Arctic-inspired theme based on the Nord color palette with frosty blues and clean contrasts",
    "theme": {
        "font.family": _set_family("Overpass"),
        "axes.spines.top": False,
        "axes.spines.right": False,
        "xtick.minor.visible": False,
        "ytick.minor.visible": False,
        "xtick.major.size": 5,
        "ytick.major.size": 5,
        "yaxis.labellocation": "top",
        "xaxis.labellocation": "right",
        "axes.grid": True,
        "grid.linewidth": 0.6,
        "grid.linestyle": "-",
        "grid.alpha": 0.15,
        "grid.color": "#4C566A",
        "axes.linewidth": 1.2,
        "text.color": "#2E3440",
        "axes.facecolor": "#ECEFF4",
        "figure.facecolor": "#ECEFF4",
        "axes.labelcolor": "#3B4252",
        "axes.edgecolor": "#3B4252",
        "xtick.color": "#3B4252",
        "ytick.color": "#3B4252",
        "axes.prop_cycle": cycler(
            "color",
            [
                "#5E81AC",
                "#BF616A",
                "#D08770",
                "#EBCB8B",
                "#A3BE8C",
                "#B48EAD",
                "#8FBCBB",
                "#88C0D0",
                "#81A1C1",
            ],
        ),
    },
}


ALL_THEMES = {
    "wsj": wsj_theme,
    "urban": urban_theme,
    "minimal": minimal_theme,
    "ft": ft_theme,
    "nature": nature_theme,
    "economist": economist_theme,
    "greenwave": greenwave_theme,
    "vscode-dark": vscode_dark_theme,
    "nord": nord_theme,
    "retro": retro_theme,
    "lighter": lighter_theme,
    "darker": darker_theme,
    "yellowish": yellowish_theme,
    "monoblue": monoblue_theme,
}
