#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "finder.h"
#include "word_list.h"

#include <QMainWindow>
#include <QStandardItemModel>
#include <QStringListModel>
#include <filesystem>
#include <memory>

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow {
  Q_OBJECT

private:
  WordList word_list_;
  QStringListModel result_model_;
  QStandardItemModel search_algorithms_;
  QStandardItemModel word_list_sources_;
  std::unique_ptr<Finder> finder_;
  bool incremental_search_enabled_;

public:
  /** Create a new MainWindow.
   *
   * @param[in] enableIncrementalSearch Run search while typing.
   * @param[in] enableDevMode Show additional widgets to configure search.
   */
  MainWindow(QWidget *parent = nullptr, bool enableIncrementalSearch = false,
             bool enableDevMode = false);
  ~MainWindow();

private:
  void setDevMode(bool enable);
  void setupAlgorithmSelector();
  void setupWordListSourceSelector();
  void setupWordList();
  void generateWordList();
  void loadWordList(std::filesystem::path path);
  void search(const QString &search_term);
  void createSelectedFinder();
  void showResults(const WordRefList &results);
  void clearResults();

private slots:
  void on_searchInput_textChanged(const QString &search_term);
  void on_searchAlgorithmSelector_currentIndexChanged(int);
  void on_wordListSourceSelector_currentIndexChanged(int);
  void on_wordListSizeSelector_valueChanged(int);
  void on_searchInput_returnPressed();

private:
  Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
