extends LineEdit

static var styles: = [null, null]
static var init_done: = false

var checkbutton_material: Material


func _init() -> void:
    ProjectSettings.connect('settings_changed', on_setting_changed)
    if not init_done:
        init_done = true
        var style_light: = get_theme_stylebox('read_only')
        style_light.bg_color = Color.GRAY
        styles[1] = style_light
        var style_dark: = style_light.duplicate(true)
        style_dark.bg_color = Color(0.12, 0.12, 0.12)
        styles[0] = style_dark


func on_setting_changed():
    checkbutton_material = $CheckButton.material
    apply_colors()


func apply_colors():
    var is_light: bool = ProjectSettings.get_setting('application/config/%s' % 'Цвет темы программы', false)
    if is_light:
        add_theme_stylebox_override('read_only', styles[1])
        $CheckButton.material = null
    else:
        add_theme_stylebox_override('read_only', styles[0])
        $CheckButton.material = checkbutton_material
