#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QPropertyAnimation>
#include <QTimer>
#include <QPixmap>
#include <QBitmap>
#include <QGraphicsBlurEffect>
#include <QFont>
#include <QCloseEvent>
#include <QMutex>
#include <QMutexLocker>

#include "statuswidget.h"
#include "settingswidget.h"
#include "aboutwidget.h"
#include "helpwidget.h"
#include "chooseversiondialog.h"

namespace Ui {
class MainWindow;
}

class MenuEntry;
class DialogWindow;
class PatchList;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(PatchList *legacy_patches, QWidget *parent = 0);
    ~MainWindow();
    int getLastDialogResult();

protected:
    virtual void closeEvent(QCloseEvent *event) override;

public slots:
    void showMessageDialog(QObject* emitter, QString message, QString ok_button_text = "Ок", QString cancel_button_text = "Отмена");
    void updateFontSizes();

signals:
    void messageDialogFinished(QObject* emitter, int result);

protected:
    void mouseMoveEvent(QMouseEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void resizeEvent(QResizeEvent *event) override;
    bool eventFilter(QObject *watched, QEvent *event) override;

private slots:
    void randomChangeBackground();

    void on_menuentry_1_clicked();

    void on_menuentry_2_clicked();

    void on_menuentry_3_clicked();

    void on_menuentry_4_clicked();

    void onHoverMenuentry(MenuEntry* hovered_entry);

    void on_closeButton_clicked();

    void on_minimizeButton_clicked();

    void setupWindowBackgroundAndMask(QPixmap background);

    void onPatchOperationsStarted();

    void onPatchOperationsFinished();

private:
    void makeConnections();

    void setupMenuHoverWidget();

    void moveMenuHoverWidget(MenuEntry* target);

    void checkMenuIsHovered();

    void hideAllContentWidgets();

    bool buttonsMouseMoveEventFilter(QObject *obj, QEvent *event);

    void setEventFilterRecursive(QObject* widget);

private:
    bool show_warning_on_close = false;

    PatchList *legacy_patches_;

    Ui::MainWindow *ui;

    MenuEntry* current_active_entry_;
    MenuEntry* current_hovered_entry_;

    StatusWidget *status_widget_;
    SettingsWidget *settings_widget_;
    HelpWidget *help_widget_;
    AboutWidget *about_widget_;

    ChooseVersionDialog *choose_locale_dialog_;
    DialogWindow *dialog_window_;

    QWidget* menu_hover_widget_;
    QPropertyAnimation* menu_hover_widget_animation_;
    QTimer menu_hover_checker_timer_;

    QPoint drag_position_;

    int current_bg_id_;
    QPixmap current_bg_;
    QBitmap current_mask_;
    QTimer background_update_timer_;

    const int MAX_PIXMAP_ID = 21;
};


#endif // MAINWINDOW_H
