#pragma once

#include "layers/backgroundLayer.h"
#include "layers/keyboardLayer.h"

#include <chrono>
#include <quokka_gfx.h>

class AppContext;
//--------------------------------------------------------------
class MainWindow : public quokka_gfx::Window
{
  friend class Layer;

  using Timestamp = std::chrono::milliseconds;

  enum class PlaybackState : uint8_t
  {
    Stopped = 0,
    Playing,
    Paused
  };

  public:
  MainWindow()                                     = delete;      // Default constructor
  virtual ~MainWindow()                            = default;     // Default destructor
  MainWindow(const MainWindow &obj)                = delete;      // Copy constructor
  MainWindow(MainWindow &&obj) noexcept            = delete;      // Move constructor
  MainWindow &operator=(const MainWindow &obj)     = delete;      // Copy assignment operator
  MainWindow &operator=(MainWindow &&obj) noexcept = delete;      // Move assignment operator

  explicit MainWindow(AppContext        &appContext,     // Constructor
                      quokka_gfx::Application &app);

  void OnEvent(SDL_Event *event) override;     // Handle event
  void Update(float dt) override;              // Update the window state
  bool Draw() override;                        // Draw the window content

  protected:
  AppContext &m_appContext;     // Reference to the application context

  // Layers
  BackgroundLayer m_backgroundLayer;     // Background layer instance
  KeyboardLayer   m_keyboardLayer;       // Keyboard layer instance

  PlaybackState m_playbackState = PlaybackState::Playing;     // Current playback state
  Timestamp     m_musicTime     = {};                         // Current music time in milliseconds

  private:
  void onResize(const quokka_gfx::Size &newSize);     // Handle window resize event

  void updateMusicTime(float dt);     // Update the current music time based on playback state
};
//--------------------------------------------------------------
