#pragma once

#include "../actor/player_actor.h"
#include "../core/debug_flags.h"
#include "../data/level_definition.h"
#include "../debug/debug_overlay.h"
#include "camera_controller.h"
#include "../stage/stage_renderer.h"

#include <frostbite2D/scene/scene.h>
#include <frostbite2D/types/type_math.h>
#include <string>
#include <vector>

namespace ns_game {

class WhiteboxScene : public frostbite2D::Scene {
public:
  void onEnter() override;
  void Update(float deltaTime) override;
  bool OnEvent(const frostbite2D::Event& event) override;
  void Render() override;

private:
  struct BattleZoneRuntime {
    bool triggered = false;
    bool cleared = false;
  };

  frostbite2D::Camera* activeCamera() const;
  std::vector<BattleZoneDebugInfo> buildBattleZoneDebugInfo() const;
  void configureCamera();
  bool handleDebugKey(frostbite2D::KeyCode keyCode);
  void toggleDebugOverlay();
  void beginCameraBoundsBlend(const frostbite2D::Rect& targetBounds);
  void clearActiveBattleZone();
  void updateCameraBoundsBlend(float deltaTime);
  void updateBattleZones();
  void updateCamera(float deltaTime);

  LevelDefinition level_;
  DebugFlags debugFlags_;
  std::vector<BattleZoneRuntime> battleZoneStates_;
  int activeBattleZoneIndex_ = -1;
  bool cameraBoundsBlendActive_ = false;
  float cameraBoundsBlendTimer_ = 0.0f;
  float cameraBoundsBlendDuration_ = 0.35f;
  frostbite2D::Rect cameraBoundsBlendStart_;
  frostbite2D::Rect cameraBoundsBlendTarget_;
  frostbite2D::Rect currentCameraBounds_;
  CameraController cameraController_;
  StageRenderer stageRenderer_;
  DebugOverlay debugOverlay_;
  frostbite2D::Ptr<PlayerActor> player_;
};

} // namespace ns_game
