#pragma once
#include "EngineFrame/Actor/Actor.h"
#include "EngineFrame/Component/Sprite.h"
#include "Asset/AnimationStruct.h"
#include <functional>
#include <tuple>
#include <utility>

class Animation : public Actor
{

public:
    struct ReplaceData
    {
        int Param1;
        int Param2;
        ReplaceData() : Param1(0), Param2(0) {}
        ReplaceData(int _Param1, int _Param2) : Param1(_Param1), Param2(_Param2) {}
    };

public:
    Animation(/* args */);
    Animation(std::string AniPath);
    Animation(std::string AniPath, std::function<std::string(std::string, Animation::ReplaceData)> AdditionalOptions, Animation::ReplaceData);
    ~Animation();

    void Init(std::string AniPath);
    void HandleEvents(SDL_Event *e) override;
    void Update(float deltaTime) override;
    void Render() override;
    void OnAdded(BaseNode *node) override;
    void Clear() override;
    void SetVisible(bool visible) override;

public:
    void FlushFrame(int Index);
    void Reset();
    AniScriptParser::AniFrame GetCurrentFrameInfo();
    // 设置帧索引
    void SetFrameIndex(int Index);
    void InterpolationLogic();
    // TODO SetOutline
    // TODO SetDye
    // TODO SetCrop

public:
    // Ani是否可用
    bool IsUsability = true;
    // 当前帧数
    int CurrentFrameIndex = 0;
    // 总帧数
    int TotalFrameIndex = 0;
    // 当前帧时间
    float CurrentIndexT = 0;
    // 当前帧
    RefPtr<Sprite> CurrentFrame = nullptr;
    // 下帧延迟
    float NextFrameDelay = 9999999;
    // 染色Flag
    bool DyeingFlag = false;
    // 插值模式
    std::vector<AniScriptParser::AniFrame> InterpolationFlag;
    // 关键帧回调
    std::function<void(int)> ChangeFrameCallback;
    // 结束回调
    std::function<void()> EndCallback;
    // Ani的标签
    std::unordered_map<std::string, AniScriptParser::AniFlag> AnimationFlag;
    // 帧对象数组
    std::vector<AniScriptParser::AniFrame> FrameArr;
    // 图片精灵帧对象
    std::vector<RefPtr<Sprite>> SpriteArr;
    // Ani类型
    std::string Type = "normal";
    // Ani路径
    std::string AniPath;
    // 是否描边
    bool IsOutline = false;
    // // 描边颜色
    // OutlineColor = null;
    // // 描边对象List
    // OutlineList = null;
    // // 当前描边对象
    // CurrentOutline = null;
    // // 染色颜色
    // DyeColor = null;
    // // 染色帧List
    // DyeFrameList = null;
    // // 整体染色
    // DyeAllFlag = false;

    // 附加选项
    std::function<std::string(std::string, Animation::ReplaceData)> AdditionalOptions;
    Animation::ReplaceData AdditionalOptionsData;
};
