#ifndef COLOUREDLINEEDIT_H
#define COLOUREDLINEEDIT_H

#include "../stylesheethandler/stylesheethandler.h"

#include <QVariant>

#include <QLineEdit>

#include <QParallelAnimationGroup>

#include <QPropertyAnimation>

#include <QApplication>

class AnimatedPropertyStyleSheet;

class ColouredLineEdit : public QLineEdit {
  Q_OBJECT
  Q_PROPERTY(QColor text MEMBER m_currentTextColor WRITE setTextColor)
  Q_PROPERTY(QColor background MEMBER m_currentBackgroundColor WRITE
                 setBackgroundColor)
  Q_PROPERTY(QColor border MEMBER m_currentBorderColor WRITE setBorderColor)

public:
  void setTextColor(const QColor &color);
  void setBackgroundColor(const QColor &color);
  void setBorderColor(const QColor &color);

private:
  using Animator = QPropertyAnimation;
  QColor m_currentTextColor;
  QColor m_currentBackgroundColor;
  QColor m_currentBorderColor;
  Animator *m_colorProperty;
  Animator *m_backgroundColorProperty;
  Animator *m_borderColorProperty;
  QParallelAnimationGroup *m_parallelAnimationGroup;

public:
  explicit ColouredLineEdit(QWidget *parent = nullptr);

private:
  void createAnimators();
  void configureAnimators();
  void setStartColors(const QColor &color);
  void setEndColors(const QColor &color);
  void setStartColors();
  void setEndColors();

private:
  static QColor defaultTextColor() noexcept;
  static QColor defaultBackgroundColor() noexcept;
  static QColor defaultBorderColor() noexcept;
  constexpr const char *styleSheetTemplate() const noexcept;
  QString styleSheet() const noexcept;
  void setIntermediateColor(const QColor &color) noexcept;
  void setDuration(int milliseconds) noexcept;

public slots:
  void animate();
  void notice(const QColor &color, bool illuminate = false);
  // void softlyReset();
};

#endif // COLOUREDLINEEDIT_H
