#ifndef JNR_ANIMATION_H
#define JNR_ANIMATION_H

#include <SDL2/SDL.h>
#include <stdbool.h>

typedef struct AnimFrame {
    SDL_Rect src;          /* source rect in spritesheet */
    float    duration;     /* seconds this frame shows   */
} AnimFrame;

typedef struct AnimDef {
    AnimFrame    *frames;
    int           frame_count;
    bool          looping;
    SDL_Texture  *texture;     /* spritesheet for this anim (NULL = use default) */
} AnimDef;

typedef struct Animation {
    const AnimDef *def;
    int            current_frame;
    float          timer;
    bool           finished;
} Animation;

/* Set a new animation definition (resets playback) */
void animation_set(Animation *a, const AnimDef *def);

/* Update animation timer, advance frames */
void animation_update(Animation *a, float dt);

/* Get the current frame's source rect */
SDL_Rect animation_current_rect(const Animation *a);

/* Check if this is the last frame (useful for one-shot anims) */
bool animation_is_last_frame(const Animation *a);

/* Get the texture for the current animation (NULL if none set) */
SDL_Texture *animation_texture(const Animation *a);

#endif /* JNR_ANIMATION_H */
