#pragma once

#include <Arduino.h>
#include <FastLED.h>
#include <functional>
#include "ColorPalettes.h"

#define MinLoopDelay 2
#define MaxLoopDelay 200
#define MaxSpeed 100

#define RANDOM_DECAY true
#define LINEAR_DECAY false

#define CYCLES_PER_DIRECTION 2

void Animation_Init(void);

void Animation_Loop(bool volatile& loop_active_flag, int speed, std::function<int()> callback);
void Animation_Loop_Limited(bool volatile& loop_active_flag, int speed, TickType_t duration, std::function<int()> callback);
void Animation_Loop_Cycles(bool volatile& loop_active_flag, int speed, uint32_t loop_cycles, std::function<int()> callback);

void Anim_Rainbow(bool volatile& loop_active_flag, CRGB* leds, int size, int speed);

void Anim_Fire(bool volatile& activeFlag, CRGB* leds, int size, int speed, const CRGBPalette16& firePalette, int shift);

void Anim_Color_Sectors(bool volatile& activeFlag, CRGB* leds, int size, const COLOR_PACK& colorPack, uint8_t numRepeats, int speed);

//template<typename TPalette>
//void Anim_Color_Gradient_Trans(bool volatile& activeFlag, CRGB* leds, int size, TPalette& palette, uint8_t paletteSize, uint8_t numRepeats, int speed);
//void Anim_Color_Gradient_Red_Yellow_Violet(bool volatile& activeFlag, CRGB* leds, int size, int speed);

void Anim_Comets(bool volatile& activeFlag, CRGB* leds, int size, const COLOR_PACK& colorPack, int speed, bool randomDecay, bool shorterTail, int cometMultiplier);
//void Anim_Comet_Rainbow(bool volatile& activeFlag, CRGB* leds, int size, int speed);

void Anim_TimedFill(bool volatile& activeFlag, CRGB* leds, int size, CRGB col1, CRGB col2, int totalDurationMs, int shift); 

void Anim_ColorBreath(bool volatile& activeFlag, CRGB* leds, int size, const COLOR_PACK& colors, uint32_t timeMs, int speed);

void Anim_GradientRotate(bool volatile& activeFlag, CRGB* leds, int size, const COLOR_PACK& colors, int speed);

uint32_t getRandomValue(uint32_t maxValue);
