#include "FormGeneralSettings.h"
#include "ui_FormGeneralSettings.h"

#include <QScroller>

#include "LanguageManager.h"
#include "DataTypeDef.h"
#include "GeneralInterface.h"

FormGeneralSettings::FormGeneralSettings(BaseWidget *parent)
    : BaseWidget(parent)
    , ui(new Ui::FormGeneralSettings)
{
    ui->setupUi(this);    

    GeneralInterface::setTouchScroller(ui->scrollArea);

    initCommandLinkButton();
    setupConnections();
}

FormGeneralSettings::~FormGeneralSettings()
{
    delete ui;
}

bool FormGeneralSettings::returnParent()
{
    return true;
}

void FormGeneralSettings::initCommandLinkButton()
{
    ui->language->setMainText(tr("Language"));
    ui->language->setDescriptionText(tr("Multiple Language Selection"));

    ui->admin_pwd_setting->setMainText(tr("Admin Password"));
    ui->admin_pwd_setting->setDescriptionText("");

    ui->charging_setup->setMainText(tr("Charging setup"));
    ui->charging_setup->setDescriptionText("");

    ui->dwell_time_seting->setMainText(tr("Page dwell time setting"));
    ui->dwell_time_seting->setDescriptionText(tr("Set the duration to stay on a page when no user interaction"));

    ui->screen_brightness_set->setMainText(tr("Screen brightness setting"));
    ui->screen_brightness_set->setDescriptionText(tr("Set the screen brightness when charging. no user interaction etc"));

    ui->network_setup->setMainText(tr("Network Setup"));
    ui->network_setup->setDescriptionText(tr("The network functionality may be limited here. it is recommended to configure the network via android setting"));

    ui->work_mode->setMainText("Work Mode");
}

void FormGeneralSettings::setupConnections()
{
    connect(LanguageManager::instance(), &LanguageManager::languageChanged, this, [this]() { ui->retranslateUi(this); });

    connect(ui->language,           &CustomCommandLinkButton::clicked, this, [this]() { emit generalSettingClicked(General::Form::LANGUAGE); });
    connect(ui->admin_pwd_setting,  &CustomCommandLinkButton::clicked, this, [this]() { emit generalSettingClicked(General::Form::ADMIN_PWD); });
    connect(ui->charging_setup,     &CustomCommandLinkButton::clicked, this, [this]() { emit generalSettingClicked(General::Form::CHARGING_SETUP); });
}
