#pragma once

#include <QWidget>
#include <QColor>
#include <QComboBox>
#include <list>
#include "ColorButton.h"

struct ColorPoint {
	double alpha;
	QColor color;
	ColorPoint(double alpha, QColor color) : alpha(std::clamp(alpha, 0.0, 1.0)), color(color) {}
};


class ColorGradient : public QWidget
{
	Q_OBJECT

public:
	enum ColorInterpolationMode{ RGB, HSL};
	enum ColorMode{ Interpolate, Discrete};
	ColorGradient(QWidget *parent);
	~ColorGradient();
	QColor getColor(double alpha);
	void addColorPoint(double alpha);
	void removeColorPoint(ColorPoint& point);
	void setMode(ColorMode mode);
	void setInterpolationMode(ColorInterpolationMode mode);
private:
	ColorMode mode = ColorMode::Interpolate;
	ColorInterpolationMode interpolationMode = ColorInterpolationMode::RGB;
	std::list<ColorPoint> pointList;
	//UI
	ColorPoint* selected = nullptr;
	QComboBox* interpolationCombobox = nullptr;
	QComboBox* modeCombobox = nullptr;
	QSpacerItem* spacerH = nullptr;
	QLabel* label = nullptr;
	ColorButton* colorbutton = nullptr;
	void paintEvent(QPaintEvent* event) override;
	void mousePressEvent(QMouseEvent* event) override;
	void mouseMoveEvent(QMouseEvent* event) override;

signals:
	void gradientChanged();
};
