from typing import Mapping

from textual.color import Color
from textual.style import Style, NULL_STYLE

SGR_STYLES: Mapping[int, Style] = {
    1: Style(bold=True),
    2: Style(dim=True),
    3: Style(italic=True),
    4: Style(underline=True),
    5: Style(blink=True),
    6: Style(blink=True),
    7: Style(reverse=True),
    8: Style(reverse=True),
    9: Style(strike=True),
    21: Style(underline2=True),
    22: Style(dim=False, bold=False),
    23: Style(italic=False),
    24: Style(underline=False),
    25: Style(blink=False),
    26: Style(blink=False),
    27: Style(reverse=False),
    28: NULL_STYLE,  # "not conceal",
    29: Style(strike=False),
    30: Style(foreground=Color(0, 0, 0, ansi=0)),
    31: Style(foreground=Color(128, 0, 0, ansi=1)),
    32: Style(foreground=Color(0, 128, 0, ansi=2)),
    33: Style(foreground=Color(128, 128, 0, ansi=3)),
    34: Style(foreground=Color(0, 0, 128, ansi=4)),
    35: Style(foreground=Color(128, 0, 128, ansi=5)),
    36: Style(foreground=Color(0, 128, 128, ansi=6)),
    37: Style(foreground=Color(192, 192, 192, ansi=7)),
    39: Style(foreground=Color(0, 0, 0, ansi=-1)),
    40: Style(background=Color(0, 0, 0, ansi=0)),
    41: Style(background=Color(128, 0, 0, ansi=1)),
    42: Style(background=Color(0, 128, 0, ansi=2)),
    43: Style(background=Color(128, 128, 0, ansi=3)),
    44: Style(background=Color(0, 0, 128, ansi=4)),
    45: Style(background=Color(128, 0, 128, ansi=5)),
    46: Style(background=Color(0, 128, 128, ansi=6)),
    47: Style(background=Color(192, 192, 192, ansi=7)),
    49: Style(background=Color(0, 0, 0, ansi=-1)),
    51: NULL_STYLE,  # "frame",
    52: NULL_STYLE,  # "encircle",
    53: NULL_STYLE,  # "overline",
    54: NULL_STYLE,  # "not frame not encircle",
    55: NULL_STYLE,  # "not overline",
    90: Style(foreground=Color(128, 128, 128, ansi=8)),
    91: Style(foreground=Color(255, 0, 0, ansi=9)),
    92: Style(foreground=Color(0, 255, 0, ansi=10)),
    93: Style(foreground=Color(255, 255, 0, ansi=11)),
    94: Style(foreground=Color(0, 0, 255, ansi=12)),
    95: Style(foreground=Color(255, 0, 255, ansi=13)),
    96: Style(foreground=Color(0, 255, 255, ansi=14)),
    97: Style(foreground=Color(255, 255, 255, ansi=15)),
    100: Style(background=Color(128, 128, 128, ansi=8)),
    101: Style(background=Color(255, 0, 0, ansi=9)),
    102: Style(background=Color(0, 255, 0, ansi=10)),
    103: Style(background=Color(255, 255, 0, ansi=11)),
    104: Style(background=Color(0, 0, 255, ansi=12)),
    105: Style(background=Color(255, 0, 255, ansi=13)),
    106: Style(background=Color(0, 255, 255, ansi=14)),
    107: Style(background=Color(255, 255, 255, ansi=15)),
}
