#ifndef MAINWIN_H
#define MAINWIN_H

#pragma once
#include "libs/camera/camera.h"
#include "select_file_dialog.h"
#include "cv_params.h"
#include "libs/cv/mat_methods.h"
#include "libs/util/logger.h"
#include "libs/camera_calibration/camera_calibration.h"
#include "libs/robot/staubli.h"
#include "libs/dialog/robotcomunnication_gui.h"
#include "libs/thread/continuous_capture_thread.h"
#include "libs/thread/main_algorithm.h"
#include "ui/help.h"
#include "libs/util/json_handler.h"
#include "libs/util/camera_robot_calibration.h"

#include <QMainWindow>
#include <QMessageBox>
#include <QInputDialog>
#include <QFileDialog>
#include <QDialog>
#include <QElapsedTimer>
#include <iostream>
#include <QTextStream>
#include <future>
#include <thread>

Q_DECLARE_METATYPE(camera::frame);

QT_BEGIN_NAMESPACE
namespace Ui { class MainWin; }
QT_END_NAMESPACE

class MainWin : public QMainWindow
{
    Q_OBJECT

public:
    MainWin(QWidget *parent = nullptr);
    ~MainWin();

private slots:
    void on_actionmvImpact_Setting_triggered();

    void getCameras();

    void on_exit_button_clicked();

    void on_comboBoxF_activated(int index);

    void on_comboBoxS_activated(int index);

    void on_shotS_button_clicked();

    void on_shotF_button_clicked();

    void on_start_button_clicked();

    void on_cancel_button_clicked();

    void on_saveF_button_clicked();

    void on_saveS_button_clicked();

    void on_camConfigF_button_clicked();

    void on_camConfigS_button_clicked();

    void on_actionRefresh_triggered();

    void on_actionSave_All_frames_triggered();

    void on_actionShoot_All_triggered();

    void on_actionOnly_Front_view_triggered();

    void on_actionOnly_Side_view_triggered();

    void on_actionBoth_views_triggered();

    void show_Front_Frame(camera::frame frame, QString color = "");

    void show_Side_Frame(camera::frame frame, QString color = "");

    void on_actionFront_View_triggered();

    void on_actionLoad_Parameters_triggered();

    void on_actionSave_Parameters_triggered();

    void on_actionCalibrate_triggered();

    void on_actionSet_Calibration_Point_triggered();

    void setCalibrate_Point();

    bool isCalibrated();

    void on_actionGripper_colors_triggered();

    void on_actionStart_triggered();

    void on_actionSet_Connection_triggered();

    void on_actionSet_This_position_as_Default_triggered();

    void on_actionStop_triggered();

    void on_ShowStats(QString,QString);

    void on_ShowMarked(QImage,QImage);

    void on_ShowImages(QImage front,QImage side);

    void on_actionReadme_triggered();

    void onNumberChanged(int);

    void on_MeasurementProgressChanged(double);

    void on_CalculationProgressChanged(double);

    void on_actionGo_Home_triggered();

    void on_actionCalibrate_2_triggered();

    void on_actionSet_default_positions_triggered();

    void on_action1st_position_triggered();

    void on_action2nd_position_triggered();

    void on_action3rd_position_triggered();

    void on_actionLoad_triggered();

    void on_actionSave_triggered();

    void on_actionValidate_triggered();

    void on_actionTest_Detection_triggered();

    void on_actionSet_Default_triggered();

    void on_actionAbout_triggered();

private:
    bool timerFlag, continuousSTOP = false;
    Logger log;
    Ui::MainWin *ui;
    Select_File_Dialog *saveDialog;
    cv_Params *setParameters_Utility;
    camera_calibration *calib;
    QElapsedTimer *timer;
    ri::Staubli *robot;
    std::unique_ptr<interfaceBALLUFF::Camera> front_camera;
    std::unique_ptr<interfaceBALLUFF::Camera> side_camera;
    camera::frame front_frame;
    camera::frame side_frame;
    tcpc::sParameters parameters;
    continuous_capture_thread *continuousCapture;
    Main_Algorithm *calibration_thread;
    bool bTCP = false;
    ri::Point TCP;
    ri::eRobot_TOOL TCP_TOOL = ri::eRobot_TOOL::FLANGE;
    uint16_t stats_CNT = 0;
};
#endif // MAINWIN_H
