#pragma once

#include "duration-control.hpp"
#include "macro-schedule.hpp"
#include "macro-selection.hpp"

#include <QCheckBox>
#include <QColor>
#include <QDateEdit>
#include <QDateTimeEdit>
#include <QDialog>
#include <QGroupBox>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QRadioButton>
#include <QSpinBox>
#include <QComboBox>

namespace advss {

// Dialog for creating or editing a MacroScheduleEntry.
class MacroScheduleEntryDialog : public QDialog {
	Q_OBJECT

public:
	static bool AskForSettings(QWidget *parent, MacroScheduleEntry &entry,
				   bool isNew);

private:
	explicit MacroScheduleEntryDialog(QWidget *parent,
					  const MacroScheduleEntry &entry,
					  bool isNew);

	void PopulateFromEntry(const MacroScheduleEntry &entry);
	void ApplyToEntry(MacroScheduleEntry &entry) const;

	// Basic fields
	QLineEdit *_name;
	MacroSelection *_macroSel;
	QDateTimeEdit *_startDateTime;

	// Optional end date
	QCheckBox *_hasEndDate;
	QDateTimeEdit *_endDate;
	QComboBox *_endDateAction;

	// Repeat
	QCheckBox *_doesRepeat;
	DurationSelection *_repeatInterval;

	// Repeat end (hidden when type == NONE)
	QGroupBox *_repeatEndGroup;
	QRadioButton *_endNever;
	QRadioButton *_endAfterN;
	QSpinBox *_endCount;
	QRadioButton *_endUntil;
	QDateEdit *_endUntilDate;

	// Color
	QPushButton *_colorBtn;
	QColor _color;
	void UpdateColorButton();

	// Options
	QCheckBox *_checkConditions;
	QCheckBox *_runElseActionsOnConditionFailure;
	QCheckBox *_enabled;
};

} // namespace advss
