/*
 * Copyright 2023 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
 */

#pragma once

#include <glutils/glutils.hpp>

#include <studio/context.hpp>
#include <nostalgia/gfx/gfx.hpp>

#include <jasper/world/worldobject.hpp>

#include "../maptilehighlighter.hpp"

namespace jasper::world {

namespace ngfx = nostalgia::gfx;

class CollisionView {
	private:
		static constexpr int s_scale = 5;
		ox::UPtr<ngfx::Context> m_nctx;
		glutils::FrameBuffer m_frameBuffer;
		uint_t m_sheetTileStart{};
		int m_subsheetTilesWidth{};
		int m_subsheetTilesHeight{};
		MapTileHighlighter m_highlighter;

	public:
		CollisionView(studio::Context &sctx);

		ox::Error setup(
				ox::FileAddress const &tsAddr,
				ox::FileAddress const &palAddr,
				int w,
				int h,
				uint_t tile,
				CollisionMap colMap) noexcept;

		void draw() noexcept;

		[[nodiscard]]
		int scale() const noexcept;

		[[nodiscard]]
		glutils::FrameBuffer const &framebuffer() const noexcept;

		/**
		 * @return true if colMap changes
		 */
		bool click(ox::Vec2 const &pos, CollisionMap &colMap) noexcept;

	private:
		void buildGlBuffers(CollisionMap colMap) noexcept;

};

}
