//
// Created by Krad on 2021/11/22.
//

#include "AdminSettingForm.h"
#include <QHBoxLayout>
#include <QStackedWidget>
#include <QStringListModel>
#include <QListWidget>
#include "tabformwidget.h"
#include <QListWidgetItem>
#include "ui_tabformwidget.h"
#include <QLabel>
#include "UserOperationLogForm.h"
#include "generalform.h"
#include <QPushButton>
#include "systemsettingform.h"
#include "AccountTableForm.h"
#include "event/EventCenter.h"
#include "aboutwidget.h"

AdminSettingForm::AdminSettingForm(QWidget* parent, Qt::WindowFlags f) : TabFormWidget(parent) {

	QHBoxLayout* layout = new QHBoxLayout(this);
	layout->setMargin(0);
	layout->setContentsMargins(0, 8, 0, 1);
	this->ui->contentWidget->setLayout(layout);
	this->ui->contentWidget->setObjectName("contentWidgetWithBBorder");
	QListWidget* widget = new QListWidget(this);
	widget->setFixedWidth(250);
	QStringList menus;
	//menus << tr("General") << tr("Account") << tr("System") << tr("Information") << tr("Log") << tr("About");
	menus << tr("General") << tr("Account") << tr("System") << tr("About");
	widget->addItems(menus);
	widget->setSpacing(3);
	for (int i = 0; i < menus.count(); ++i) {
		widget->item(i)->setTextAlignment(Qt::AlignCenter);
	}
	layout->addWidget(widget);
	QStackedWidget* stackedWidget = new QStackedWidget(this);

	QWidget* spacerLine2 = new QWidget(this);
	spacerLine2->setFixedWidth(2);
	spacerLine2->setObjectName("verSpaceLine");
	spacerLine2->setStyleSheet("margin-bottom:8px");
	layout->addWidget(spacerLine2);
	layout->addWidget(stackedWidget);
	this->ui->commandWidget->hide();

	GeneralForm* generalForm = new GeneralForm(this);
	stackedWidget->addWidget(generalForm);

	AccountTableForm* acc = new AccountTableForm(this);

	stackedWidget->addWidget(acc);

	systemSettingForm* systemSetting = new systemSettingForm(this);
	stackedWidget->addWidget(systemSetting);

	//QLabel* systemSetting = new QLabel(this);
	//systemSetting->setText("systemSetting");
	//stackedWidget->addWidget(systemSetting);

	//QLabel* Info = new QLabel(this);
	//Info->setText("info");
	//stackedWidget->addWidget(Info);

	//UserOperationLogForm* operationLogForm = new UserOperationLogForm(this);
	//stackedWidget->addWidget(operationLogForm);

	//QLabel* about = new QLabel(this);
	//about->setText(tr("About"));

	AboutWidget* about = new AboutWidget(this);
	stackedWidget->addWidget(about);


	widget->setCurrentRow(0);
	connect(widget, &QListWidget::currentRowChanged, [=](int rowindex) {
		stackedWidget->setCurrentIndex(rowindex);
		});
	connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]() {
		QStringList menus2;
		menus2 << tr("General") << tr("Account") << tr("System") << tr("About");
		widget->clear();
		widget->addItems(menus2);
		for (int i = 0; i < menus.count(); ++i) {
			widget->item(i)->setTextAlignment(Qt::AlignCenter);
		}
		});
}

AdminSettingForm::~AdminSettingForm() {

}
