#pragma once
#include <SDL3/SDL.h>

#include <vector>

enum class SyncState {
    Idle,
    LeftReady,
    RightReady,
    Synced,
    ClearFlash
};

class SyncLineRenderer {
public:
    SyncLineRenderer();

    void SetRect(const SDL_FRect& rect);
    void SetState(SyncState state);
    void TriggerClearFlash();

    void Update(float deltaTime);
    void Render(SDL_Renderer* renderer);

private:
    struct SyncParticle {
        float x;
        float y;
        float vx;
        float vy;
        float w;
        float h;
        float alpha;
        SDL_Color color;
    };

    SDL_FRect m_rect{};
    SyncState m_state;

    float m_flashTimer;
    float m_time;

    float m_pulseTime{0.0f};
    float m_spawnAcc{0.0f};
    std::vector<SyncParticle> m_particles;

    static constexpr float FLASH_DURATION = 0.15f;
    static constexpr size_t MAX_PARTICLES = 240;

    void SpawnParticle();
    void SpawnBurst(int count);

    SDL_Color GetBaseColor() const;
};
