#pragma once
#include "Component.h"
#include "../core/types/vec2.h"
#include "../core/types/color.h"
#include <vector>

enum class EasingFunction
{
    Linear,
    EaseInOut,
    EaseOutCubic
};

enum class PathMode {
    Loop,
    PingPong,
    Stop
};


class PathFollowerComponent : public Component
{
public:
    PathFollowerComponent(Object *owner);

    void Update(float dt);

    void AddTarget(const core::types::Vec2 &point);
    void ClearPath();

    void Save(YAML::Emitter &out) const override;
    void Load(const YAML::Node &node) override;
    std::string GetName() const override { return "PathFollowerComponent"; }

    float GetSpeed() const { return m_speed; }
    void SetSpeed(float s) { m_speed = s; }

    EasingFunction GetEasing() const { return m_easing; }
    void SetEasing(EasingFunction easing) { m_easing = easing; }

    std::vector<core::types::Vec2> &GetTargets() { return m_targets; }

    void RemoveTarget(size_t index)
    {
        if (index < m_targets.size())
            m_targets.erase(m_targets.begin() + index);
    }

    PathMode GetPathMode() const { return m_pathMode; }
void SetPathMode(PathMode mode) { m_pathMode = mode; }

void SetForward(bool forward) { m_forward = forward; }
bool IsForward() const { return m_forward; }


private:
    std::vector<core::types::Vec2> m_targets;
    size_t m_currentTarget = 0;
    float m_speed = 100.0f;
    EasingFunction m_easing = EasingFunction::Linear;

    PathMode m_pathMode = PathMode::Loop;
    bool m_forward = true;


    core::types::Vec2 m_currentPosition;
    bool m_initialized = false;

    float Ease(float t) const;
    float GetCornerSharpness(const core::types::Vec2 &a, const core::types::Vec2 &b, const core::types::Vec2 &c) const;
};
