# Copyright (c) 2018-2022, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#

from pathlib import Path

import omni.ui as ui
from omni.ui import color as cl
from omni.ui import constant as fl
from omni.ui import url

CURRENT_PATH = Path(__file__).parent
DATA_PATH = CURRENT_PATH.parent.parent.parent.parent.joinpath("data")
FONTS_PATH = CURRENT_PATH.parent.parent.parent.parent.joinpath("fonts")


def get_style():
    """
    Returns the standard omni.ui style for documentation
    """
    cl.documentation_nvidia = cl("#76b900")

    # Content
    cl.documentation_bg = cl.white
    cl.documentation_text = cl("#1a1a1a")
    cl.documentation_h1_bg = cl.black
    cl.documentation_h1_color = cl.documentation_nvidia
    cl.documentation_h2_line = cl.black
    cl.documentation_h2_color = cl.documentation_nvidia
    cl.documentation_exec_bg = cl("#454545")
    cl.documentation_code_bg = cl("#eeeeee")
    cl.documentation_code_fadeout = cl("#eeeeee01")
    cl.documentation_code_fadeout_selected = cl.documentation_nvidia
    cl.documentation_code_line = cl("#bbbbbb")

    fl.documentation_margin = 5
    fl.documentation_code_size = 16
    fl.documentation_code_radius = 2
    fl.documentation_text_size = 18
    fl.documentation_h1_size = 36
    fl.documentation_h2_size = 28
    fl.documentation_h3_size = 20
    fl.documentation_line_width = 0.3

    cl.url_link = cl("#3333CC")

    # Catalog
    cl.documentation_catalog_bg = cl.black
    cl.documentation_catalog_text = cl("#cccccc")
    cl.documentation_catalog_h1_bg = cl("#333333")
    cl.documentation_catalog_h1_color = cl.documentation_nvidia
    cl.documentation_catalog_h2_bg = cl("#fcfcfc")
    cl.documentation_catalog_h2_color = cl("#404040")
    cl.documentation_catalog_h3_bg = cl("#e3e3e3")
    cl.documentation_catalog_h3_color = cl("#404040")
    cl.documentation_catalog_icon_selected = cl("#333333")

    fl.documentation_catalog_tree1_size = 17
    fl.documentation_catalog_tree1_margin = 5
    fl.documentation_catalog_tree2_size = 19
    fl.documentation_catalog_tree2_margin = 2
    fl.documentation_catalog_tree3_size = 19
    fl.documentation_catalog_tree3_margin = 2

    url.documentation_logo = f"{DATA_PATH.joinpath('main_ov_logo_square.png')}"
    url.documentation_settings = f"{DATA_PATH.joinpath('settings.svg')}"
    url.documentation_plus = f"{DATA_PATH.joinpath('plus.svg')}"
    url.documentation_minus = f"{DATA_PATH.joinpath('minus.svg')}"

    url.documentation_font_regular = f"{FONTS_PATH}/DINPro-Regular.otf"
    url.documentation_font_regular_bold = f"{FONTS_PATH}/DINPro-Bold.otf"
    url.documentation_font_monospace = f"{FONTS_PATH}/DejaVuSansMono.ttf"

    style = {
        "Window": {"background_color": cl.documentation_catalog_bg, "border_width": 0, "padding": 0},
        "Rectangle::content_background": {"background_color": cl.documentation_bg},
        "Label::paragraph": {
            "color": cl.documentation_text,
            "font_size": fl.documentation_text_size,
            "margin": fl.documentation_margin,
        },
        "Text::code": {
            "color": cl.documentation_text,
            "font": url.documentation_font_monospace,
            "font_size": fl.documentation_code_size,
            "margin": fl.documentation_margin,
        },
        "url_link": {"color": cl.url_link, "font_size": fl.documentation_text_size},
        "table_label": {
            "color": cl.documentation_text,
            "font_size": fl.documentation_text_size,
            "margin": 2,
        },
        "Rectangle::code": {
            "background_color": cl.documentation_code_bg,
            "border_color": cl.documentation_code_line,
            "border_width": fl.documentation_line_width,
            "border_radius": fl.documentation_code_radius,
        },
        "Rectangle::code_background": {"background_color": cl.documentation_exec_bg},
        "Rectangle::h1": {"background_color": cl.documentation_h1_bg},
        "Rectangle::tree1": {"background_color": cl.documentation_catalog_h1_bg},
        "Rectangle::tree2": {"background_color": 0x0},
        "Rectangle::tree2:selected": {"background_color": cl.documentation_catalog_h2_bg},
        "Rectangle::tree3": {"background_color": 0x0},
        "Rectangle::tree3:selected": {"background_color": cl.documentation_catalog_h3_bg},
        "Text::h1": {
            "color": cl.documentation_h1_color,
            "font": url.documentation_font_regular,
            "font_size": fl.documentation_h1_size,
            "margin": fl.documentation_margin,
            "alignment": ui.Alignment.CENTER,
        },
        "Text::h2": {
            "color": cl.documentation_h2_color,
            "font": url.documentation_font_regular,
            "font_size": fl.documentation_h2_size,
            "margin": fl.documentation_margin,
        },
        "Text::h3": {
            "color": cl.documentation_h2_color,
            "font": url.documentation_font_regular,
            "font_size": fl.documentation_h3_size,
            "margin": fl.documentation_margin,
        },
        "Text::tree1": {
            "color": cl.documentation_catalog_h1_color,
            "font": url.documentation_font_regular_bold,
            "font_size": fl.documentation_catalog_tree1_size,
            "margin": fl.documentation_catalog_tree1_margin,
        },
        "Text::tree2": {
            "color": cl.documentation_catalog_text,
            "font": url.documentation_font_regular,
            "font_size": fl.documentation_catalog_tree2_size,
            "margin": fl.documentation_catalog_tree2_margin,
        },
        "Text::tree2:selected": {"color": cl.documentation_catalog_h2_color},
        "Text::tree3": {
            "color": cl.documentation_catalog_text,
            "font": url.documentation_font_regular,
            "font_size": fl.documentation_catalog_tree3_size,
            "margin": fl.documentation_catalog_tree3_margin,
        },
        "Text::tree3:selected": {"color": cl.documentation_catalog_h3_color},
        "Image::main_logo": {"image_url": url.documentation_logo},
        "Image::settings": {"image_url": url.documentation_settings},
        "Image::plus": {"image_url": url.documentation_plus},
        "Image::minus": {"image_url": url.documentation_minus},
        "Image::plus:selected": {"color": cl.documentation_catalog_icon_selected},
        "Image::minus:selected": {"color": cl.documentation_catalog_icon_selected},
        "Line::h2": {"border_width": fl.documentation_line_width},
        "Line::h3": {"border_width": fl.documentation_line_width},
        "TextOverlay": {
            "background_color": cl.documentation_bg,
            "background_gradient_color": cl.documentation_code_fadeout,
        },
        "TextOverlay:hovered": {"background_color": cl.documentation_code_fadeout_selected},
        "RunButton": {"background_color": cl("#76b900"), "border_radius": 2},
        "RunButton.Label": {"color": 0xFF3E3E3E, "font_size": 14},
        "RunButton:hovered": {"background_color": cl("#84d100")},
        "RunButton:pressed": {"background_color": cl("#7bc200")},
    }

    return style
