/*
 * MIT License
 * Author: Mark Allyn
 *
 * scope.h — abstract base class for all radar scope displays.
 *
 * Each concrete scope implements render(), handleKey(), and getName().
 * The base class handles:
 *   - s / S key routing (ScopeManager intercepts these before calling
 *     the scope, so scopes only receive other keys)
 *   - auto-advance timer (reset by any key or control input)
 */

#pragma once
#include <string>
#include "shared_render_state.h"
#include "target_buffer.h"
#include "left_panel.h"

class Scope {
public:
    Scope(SharedRenderState& srs, TargetBuffer& tb, TextRenderer& tr)
        : srs_(srs), tb_(tb), tr_(tr) {}

    virtual ~Scope() = default;

    // Called after GL context is current.
    virtual bool init(const std::string& shaderDir) = 0;

    // Called every frame. dt = seconds since last frame.
    virtual void render(float dt, float viewportW, float viewportH) = 0;

    // Called on GLFW key events (s/S already consumed by ScopeManager).
    virtual void handleKey(int key, int scancode, int action, int mods) = 0;

    // Human-readable name for the progress log.
    virtual std::string getName() const = 0;

    // Auto-advance timer management (called by ScopeManager)
    void  tickTimer(float dt) { autoTimer_ += dt; }
    void  resetTimer()        { autoTimer_  = 0.f; }
    bool  shouldAdvance()     const { return autoTimer_ >= SCOPE_AUTO_ADVANCE_SEC; }

protected:
    SharedRenderState& srs_;
    TargetBuffer&      tb_;
    TextRenderer&      tr_;

    float autoTimer_ = 0.f;
};
