#pragma once

#include <qapplication.h>
#include <qboxlayout.h>
#include <qcombobox.h>
#include <qlabel.h>
#include <qmainwindow.h>
#include <qtoolbutton.h>
#include <qwidget.h>
#include <vector>
#include <QSettings>

#include "parser.h"

struct MdemBuffer {
	std::vector<Question*> questions  = std::vector<Question*>();
	time_t                 trainedAt  = 0;
	bool                   error      = false; 
	bool                   isModified = false;
};

struct Mdem {
    QWidget          wMdem;
    QVBoxLayout      vMdem;
    QLabel           wFrontText;
    QWidget          wFront;
    QHBoxLayout      hFront;
    QWidget          wBack;
    QVBoxLayout      hBack;
    QToolButton      editButton;
    QToolButton      deleteButton;
    QToolButton      showButton;
    int              labelCount;
    QVector<QLabel*> backLabels;
	Question        *question;
};

struct ErrorView {
	QWidget     box;
	QVBoxLayout layout;
	QLabel      label;
};

struct Page {
    size_t start;
    size_t end;
};

struct Pagination {
	int                 currentPage       = -1;
	std::vector<Page>   pages;
	QList<QToolButton*> paginationButtons;
	QToolButton         prevButton;
	QToolButton         firstButton;
	QToolButton         lastButton;
	QToolButton         nextButton; 
	QLabel              paginationLabel;
};

struct Toolbar {
	QToolButton  btnAdd;
	QToolButton  btnSave;
	QToolButton  btnLoad;
	QComboBox    cbAlgorithm;
	QToolButton  btnPractice;
};

void update(bool isChanged = false);
void saveMdem();
void updateMdemInfo(std::string filename = "", bool isChanged = true);
QMainWindow *initMdemListWindow();

#define SETTING_MEMORYBASE     "defaultMemorybase"	
#define SETTING_TIMEZONE       "timezone"	
#define SETTING_CHARACTER_WRAP "characterWrap"	
#define SETTING_NOT_REMEMBERED "notRemembered"	
#define SETTING_HARD           "hard"	
#define SETTING_MEDIUM         "medium"	
#define SETTING_EASY           "easy"	
#define SETTING_DEBUG          "debug"	
#define SETTING_SHOW_TIMES     "showTimes"	

#define TEXT_LG =        20
#define ERROR_POOL_CHUNK 50
#define DISTANCE         2
#define PER_PAGE         8
#define MDEM_BACKGROUND  "#F7F7F7"
