#pragma once

#include <QTableView>
#include <QTableWidget>
#include <QSqlRecord>
#include <QPushButton>
#include <QLabel>
#include <QSqlRecord>

class AdvancedTableView : public QTableView
{
	Q_OBJECT

	enum SelectedViewState {
		Normal,
		Max,
		Min
	};

public:
	AdvancedTableView(QWidget *parent);
	~AdvancedTableView();

	void setMultipleSelect(bool value);
	void setPKFieldName(const QString &fieldName) { pkFieldName = fieldName; };
	const QVector<QSqlRecord> *getSelectedRecords() { return selectedRecords; };
	const QStringList getSelectedPKs();
	const QVariant getSelectedPK();
	const QSqlRecord getSelectedRecord();

public:
	void setModel(QAbstractItemModel *model) override;

public slots:
	void checkStateChanged(Qt::CheckState state, const QSqlRecord &);
	void expandSelectedView();
	void collapseSelectedView();
	void removeRow();

protected:
	void resizeEvent(QResizeEvent *event) override;	

private:
	void init();
	void cloneHeaderLabels();
	void selectRecord(const QSqlRecord &record);
	void unselectRecord(const QSqlRecord &record);

private:
	QWidget				*wgtContainer;
	QTableWidget		*twSelected;
	QLabel				*lblCounter;
	QPushButton			*btnExpand;
	QPushButton			*btnCollapse;
	SelectedViewState	selectedViewState;
	bool				multipleSelect;
	bool				inited;
	QString				pkFieldName;
	QVector<QSqlRecord>	*selectedRecords;
};
