import os

import cfgtools

tab_enabled = None
tab_reader_enabled = None


def get_tab_enabled():
    # type: (...) -> bool

    global tab_enabled

    if tab_enabled is not None:
        return tab_enabled

    config = cfgtools.read(os.environ["LOADERCFG"])
    tab_enabled = config.find_value(
        path="Customizations.EnableTabBtns",
        default="true",
    )
    tab_enabled = tab_enabled.lower() == "true"

    return tab_enabled


def get_tab_reader_enabled():
    # type: (...) -> bool

    global tab_reader_enabled

    if tab_reader_enabled is not None:
        return tab_reader_enabled

    config = cfgtools.read(os.environ["LOADERCFG"])
    tab_reader_enabled = config.find_value(
        path="TabConfig.TabReaderEnabled",
        default="false",
    )
    tab_reader_enabled = get_tab_enabled() and tab_reader_enabled.lower() == "true"

    return tab_reader_enabled
