# shellcheck shell=bash
# shellcheck disable=SC2034

declare -A colors

colors=(
    [dark0_hard]='#1d2021'
    [dark0]='#282828'
    [dark0_soft]='#32302f'
    [dark1]='#3c3836'
    [dark2]='#504945'
    [dark3]='#665c54'
    [dark4]='#7c6f64'
    [dark4_256]='#7c6f64'

    [gray_245]='#928374'
    [gray_244]='#928374'

    [light0_hard]='#f9f5d7'
    [light0]='#fbf1c7'
    [light0_soft]='#f2e5bc'
    [light1]='#ebdbb2'
    [light2]='#d5c4a1'
    [light3]='#bdae93'
    [light4]='#a89984'
    [light4_256]='#a89984'

    [bright_red]='#fb4934'
    [bright_green]='#b8bb26'
    [bright_yellow]='#fabd2f'
    [bright_blue]='#83a598'
    [bright_purple]='#d3869b'
    [bright_aqua]='#8ec07c'
    [bright_orange]='#fe8019'

    [neutral_red]='#cc241d'
    [neutral_green]='#98971a'
    [neutral_yellow]='#d79921'
    [neutral_blue]='#458588'
    [neutral_purple]='#b16286'
    [neutral_aqua]='#689d6a'
    [neutral_orange]='#d65d0e'

    [faded_red]='#9d0006'
    [faded_green]='#79740e'
    [faded_yellow]='#b57614'
    [faded_blue]='#076678'
    [faded_purple]='#8f3f71'
    [faded_aqua]='#427b58'
    [faded_orange]='#af3a03'
)

map=(
        [grey]=${colors[dark4]}

        [white]=${colors[light0_hard]}

        [bright_red]=${colors[bright_red]}
        [bright_green]=${colors[bright_green]}
        [bright_yellow]=${colors[bright_yellow]}
        [bright_blue]=${colors[bright_blue]}
        [bright_magenta]=${colors[bright_purple]}
        [bright_cyan]=${colors[bright_aqua]}
        [bright_orange]=${colors[bright_orange]}

        [red]=${colors[neutral_red]}
        [green]=${colors[neutral_green]}
        [yellow]=${colors[neutral_yellow]}
        [blue]=${colors[neutral_blue]}
        [magenta]=${colors[neutral_purple]}
        [cyan]=${colors[neutral_aqua]}
        [orange]=${colors[neutral_orange]}

        [1]=${colors[neutral_red]}
        [2]=${colors[neutral_green]}
        [3]=${colors[neutral_yellow]}
        [4]=${colors[neutral_blue]}
        [5]=${colors[neutral_purple]}
        [6]=${colors[neutral_aqua]}
        [7]=${colors[neutral_orange]}
        [9]=${colors[bright_red]}
        [10]=${colors[bright_green]}
        [11]=${colors[bright_yellow]}
        [12]=${colors[bright_blue]}
        [13]=${colors[bright_purple]}
        [14]=${colors[bright_aqua]}
        [15]=${colors[bright_orange]}
    )

col=${map[$1]###}
r=${col:0:2}
g=${col:2:2}
b=${col:4:2}

echo -n "8;2;$((0x$r));$((0x$g));$((0x$b))"
