#pragma once

#include "ShipCustomWarpDialog.h"
#include "ShipFlagsDialog.h"
#include "ShipGoalsDialog.h"
#include "ShipInitialStatusDialog.h"
#include "ShipSpecialStatsDialog.h"
#include <ui/dialogs/TableViewerDialog.h>
#include "ShipTextureReplacementDialog.h"
#include "ShipWeaponsDialog.h"
#include "ShipAltShipClass.h"

#include <mission/dialogs/ShipEditor/ShipEditorDialogModel.h>
#include <ui/FredView.h>
#include <QtWidgets/QDialog>

namespace fso::fred::dialogs {

namespace Ui {
class ShipEditorDialog;
}

class ShipEditorDialog : public QDialog, public SexpTreeEditorInterface {
	Q_OBJECT

  public:
	explicit ShipEditorDialog(FredView* parent, EditorViewport* viewport);
	~ShipEditorDialog() override;

	int getShipClass() const;
	int getSingleShip() const;
	bool getIfMultipleShips() const;

  protected:
	void closeEvent(QCloseEvent*) override;
	void hideEvent(QHideEvent*) override;
	void showEvent(QShowEvent*) override;
  private slots:

	void on_textureReplacementButton_clicked();
	void on_miscButton_clicked();
	void on_initialStatusButton_clicked();
	void on_initialOrdersButton_clicked();
	void on_tblInfoButton_clicked();
	void on_playerShipButton_clicked();
	void on_altShipClassButton_clicked();
	void on_prevButton_clicked();
	void on_nextButton_clicked();
	void on_deleteButton_clicked();
	void on_resetButton_clicked();
	void on_weaponsButton_clicked();
	void on_playerOrdersButton_clicked();
	void on_specialStatsButton_clicked();
	void on_hideCuesButton_clicked();
	void on_restrictArrivalPathsButton_clicked();
	void on_customWarpinButton_clicked();
	void on_restrictDeparturePathsButton_clicked();
	void on_customWarpoutButton_clicked();

	// column one
	void on_shipNameEdit_editingFinished();
	void on_shipDisplayNameEdit_editingFinished();
	void on_shipClassCombo_currentIndexChanged(int);
	void on_AIClassCombo_currentIndexChanged(int);
	void on_teamCombo_currentIndexChanged(int);
	void on_layerCombo_currentIndexChanged(int);

	// column two
	void on_hotkeyCombo_currentIndexChanged(int);
	void on_personaCombo_currentIndexChanged(int);
	void on_killScoreEdit_valueChanged(int);
	void on_assistEdit_valueChanged(int);
	void on_playerShipCheckBox_toggled(bool);
	void on_respawnSpinBox_valueChanged(int);

	//arrival
	void on_arrivalLocationCombo_currentIndexChanged(int);
	void on_arrivalTargetCombo_currentIndexChanged(int);
	void on_arrivalDistanceEdit_valueChanged(int);
	void on_arrivalDelaySpinBox_valueChanged(int);
	void on_updateArrivalCueCheckBox_toggled(bool);
	void on_noArrivalWarpCheckBox_stateChanged(int);
	void on_arrivalTree_rootNodeFormulaChanged(int, int);
	void on_arrivalTree_helpChanged(const QString&);
	void on_arrivalTree_miniHelpChanged(const QString&);

	//departure
	void on_departureLocationCombo_currentIndexChanged(int);
	void on_departureTargetCombo_currentIndexChanged(int);
	void on_departureDelaySpinBox_valueChanged(int);
	void on_updateDepartureCueCheckBox_toggled(bool);
	void on_departureTree_rootNodeFormulaChanged(int, int);
	void on_departureTree_helpChanged(const QString&);
	void on_departureTree_miniHelpChanged(const QString&);
	void on_noDepartureWarpCheckBox_stateChanged(int);
  private: // NOLINT(readability-redundant-access-specifiers)
	std::unique_ptr<Ui::ShipEditorDialog> ui;
	std::unique_ptr<ShipEditorDialogModel> _model;
	EditorViewport* _viewport;

	bool _cues_hidden = false;

	void update();

	void updateUi(bool overwrite = false);
	void updateColumnOne(bool overwrite = false);
	void updateColumnTwo(bool ovewrite = false);
	void updateArrival(bool overwrite = false);
	void updateDeparture(bool overwrite = false);
	void enableDisable();

	// column one
	void cargoChanged();
	void cargoTitleChanged();
	void altNameChanged();
	void callsignChanged();
};
} // namespace fso::fred::dialogs
