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

#pragma once

#include <studio/studio.hpp>

#include <nostalgia/core/gfx.hpp>
#include <nostalgia/core/palette.hpp>

namespace nostalgia::core {

class PaletteEditorImGui: public studio::Editor {

	private:
		studio::StudioContext &m_sctx;
		turbine::Context &m_tctx;
		Palette m_pal;
		size_t m_selectedColorRow = 0;
		size_t m_page = 0;

	public:
		PaletteEditorImGui(studio::StudioContext &sctx, ox::CRStringView path);

		void keyStateChanged(turbine::Key key, bool down) override;

		void draw(studio::StudioContext&) noexcept final;

	protected:
		ox::Error saveItem() noexcept final;

	private:
		static void drawColumn(ox::CStringView txt) noexcept;

		static void drawColumn(uint64_t i) noexcept;

		void drawColorsEditor() noexcept;

		void drawPagesEditor() noexcept;

		void drawColorEditor() noexcept;

		ox::Error handleCommand(studio::UndoCommand const*) noexcept;
};

}
