TableColorTheme
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © boitoki

//@version=5

// @description TODO: This library provides the color for the table.
library("TableColorTheme")

GREEN__ = #1bbd96
BLUE___ = #2400ee
ORANGE_ = #fdbd08
RED____ = #fb003e
BLACK__ = #02223c
WHITE__ = #F3F3F3
GRAY___ = #292A2B
TVBLACK = #131722
TVGRAY_ = #20222b
DFGRAY_ = color.new(color.gray, 30)

// @function theme: Provides the colors of monokai.
// @param name TODO: The name of the color group.
// @returns TODO: Returns an array of colors.
// https://kolormark.com/brands/monokai
export monokai (string name) =>
    switch name
        'purple' => #AE81FF
        'blue' => #66D9EF
        'green' => #A6E22E
        'yellow' => #E6DB74
        'orange' => #FD971F
        'pink' => #F92672
        'black' => #272822
        => #272822

// @function theme: Provides the colors of monokai pro.
// @param name TODO: The name of the color group.
// @returns TODO: Returns an array of colors.
export monokaipro (string name) =>
    switch name
        'purple' => #AB9DF2
        'blue' => #78DCE8
        'green' => #A9DC76
        'yellow' => #FFD866
        'orange' => #FC9867
        'pink' => #FF6188
        'black' => #2D2A2E
        => #2D2A2E

// [Table]
// border_color = color.gray
// border_width = 1
// frame_color = color.gray
// frame_width = 2
//
// [Cell]
// text_color = color.black
// text_size = size.normal
// bgcolor = color.white
//
// [Head]
// head_text_color = color.white
// head_text_size = size.normal
// head_bgcolor = color.black


// @function theme This function provides the color for the table.
// @param name TODO: The name of the color group.
// @returns TODO: Returns an array of colors.
export theme(string name) =>
    switch name
        'green'  => [GREEN__, 1, GREEN__, 1, BLACK__, size.normal, WHITE__, WHITE__, size.normal, GREEN__]
        'blue'   => [BLUE___, 1, BLUE___, 1, BLACK__, size.normal, WHITE__, WHITE__, size.normal, BLUE___]
        'orange' => [ORANGE_, 1, ORANGE_, 1, BLACK__, size.normal, WHITE__, #392a00, size.normal, ORANGE_]
        'red'    => [RED____, 1, RED____, 1, BLACK__, size.normal, WHITE__, WHITE__, size.normal, RED____]
        'black'  => [BLACK__, 1, BLACK__, 1, BLACK__, size.normal, WHITE__, WHITE__, size.normal, BLACK__]
        'white'  => [WHITE__, 1, BLACK__, 1, BLACK__, size.normal, WHITE__, BLACK__, size.normal, WHITE__]
        'dark'   => [DFGRAY_, 1, DFGRAY_, 1, #ffffff, size.normal, TVBLACK, #a3a6b0, size.normal, TVBLACK]
        'night'  => [#343640, 1, #343640, 1, WHITE__, size.normal, TVBLACK, #b2b5be, size.normal, #343640]
        'carbon' => [GRAY___, 1, GRAY___, 1, WHITE__, size.normal, GRAY___, WHITE__, size.normal, GRAY___]
        'monokai'=> [#252328, 1, #252328, 1, #d5ced4, size.normal, #211e23, #66D9EF, size.normal, #211e23]
        'multi'  => [GREEN__, 0, GREEN__, 0, WHITE__, size.normal, GREEN__, WHITE__, size.normal, GREEN__]
        => [color.gray, 1, color.gray, 2, color.black, size.normal, color.white, color.white, size.normal, color.black]

[border_color, border_width, frame_color, frame_width, text_color, text_size, bgcolor, head_text_color, head_text_size, head_bgcolor] = theme(input.string(defval="green", options=['green', 'blue', 'orange', 'red', 'black', 'white', 'dark', 'night', 'carbon', 'monokai', 'multi']))

var table panel = table.new(position.top_right, 3, 4, border_color=border_color, border_width=border_width, frame_color=frame_color, frame_width=frame_width)

table.cell(panel, 0, 0, "h", bgcolor=head_bgcolor, text_color=head_text_color, text_size=head_text_size)
table.cell(panel, 1, 0, "name", bgcolor=bgcolor, text_color=text_color, text_size=text_size)
table.cell(panel, 2, 0, "value", bgcolor=bgcolor, text_color=text_color, text_size=text_size)

table.cell(panel, 0, 1, "h", bgcolor=head_bgcolor, text_color=head_text_color, text_size=head_text_size)
table.cell(panel, 1, 1, "open", bgcolor=bgcolor, text_color=text_color, text_size=text_size)
table.cell(panel, 2, 1, str.format('{0,number,#.#}', open), bgcolor=bgcolor, text_color=text_color, text_size=text_size)

table.cell(panel, 0, 2, "h", bgcolor=head_bgcolor, text_color=head_text_color, text_size=head_text_size)
table.cell(panel, 1, 2, "close", bgcolor=bgcolor, text_color=text_color, text_size=text_size)
table.cell(panel, 2, 2, str.format('{0,number,#.#}', close), bgcolor=bgcolor, text_color=text_color, text_size=text_size)