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

#pragma once

#include <functional>

#include <imgui.h>

#include <turbine/context.hpp>
#include <studio/context.hpp>

namespace studio::ig {

inline constexpr auto BtnSz = ImVec2{52, 22};

class ChildStackItem {
	public:
		explicit ChildStackItem(ox::CStringView id, ImVec2 const&sz = {}) noexcept;
		~ChildStackItem() noexcept;
};

class IDStackItem {
	public:
		explicit IDStackItem(int id) noexcept;
		explicit IDStackItem(const char *id) noexcept;
		explicit IDStackItem(ox::CStringView id) noexcept;
		~IDStackItem() noexcept;
};

class IndentStackItem {
	private:
		float m_indent{};
	public:
		explicit IndentStackItem(float id) noexcept;
		~IndentStackItem() noexcept;
};

void centerNextWindow(turbine::Context &ctx) noexcept;

bool PushButton(ox::CStringView lbl, ImVec2 const&btnSz = BtnSz) noexcept;

enum class PopupResponse {
	None,
	OK,
	Cancel,
};

PopupResponse PopupControlsOkCancel(float popupWidth, bool &popupOpen);

[[nodiscard]]
bool BeginPopup(turbine::Context &ctx, ox::CStringView popupName, bool &show, ImVec2 const&sz = {285, 0});

/**
 *
 * @param lbl
 * @param list
 * @param selectedIdx
 * @return true if new value selected, false otherwise
 */
bool ComboBox(ox::CStringView lbl, ox::SpanView<ox::String> list, size_t &selectedIdx) noexcept;

bool FileComboBox(
		ox::CStringView lbl,
		studio::StudioContext &sctx,
		ox::StringView fileExt,
		size_t &selectedIdx) noexcept;

bool ListBox(
		ox::CStringView name,
		std::function<ox::CStringView(size_t)> const&f,
		size_t strCnt,
		size_t &selIdx) noexcept;

/**
 *
 * @param name
 * @param list
 * @param selIdx
 * @return true if new value selected, false otherwise
 */
bool ListBox(ox::CStringView name, ox::SpanView<ox::String> const&list, size_t &selIdx) noexcept;

class FilePicker {
	private:
		bool m_show{};
		studio::StudioContext &m_sctx;
		ox::String const m_title;
		ox::String const m_fileExt;
		ImVec2 const m_size;
	public:
		ox::Signal<ox::Error(ox::StringView)> filePicked;

		FilePicker(
				studio::StudioContext &sctx,
				ox::String title,
				ox::String fileExt,
				ImVec2 const&size = {}) noexcept;

		void draw() noexcept;

		void show() noexcept;

};

}
