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

#pragma once

#include "popup.hpp"
#include "filetreemodel.hpp"

namespace studio {

class FilePickerPopup {

	private:
		ox::String m_name;
		struct Explorer: public FileExplorer {
			mutable bool opened{};
			explicit Explorer(keel::Context &kctx);
			void fileOpened(ox::StringViewCR path) const noexcept override;
		} m_explorer;
		ox::Vector<ox::String> const m_fileExts;
		bool m_open{};

	public:
		explicit FilePickerPopup(ox::StringParam name, keel::Context &kctx, ox::StringParam fileExt) noexcept;

		explicit FilePickerPopup(ox::StringParam name, keel::Context &kctx, ox::SpanView<ox::StringLiteral> fileExts) noexcept;

		explicit FilePickerPopup(ox::StringParam name, keel::Context &kctx, ox::Vector<ox::String> fileExts) noexcept;

		void refresh() noexcept;

		void open() noexcept;

		void close() noexcept;

		[[nodiscard]]
		bool isOpen() const noexcept;

		ox::Optional<ox::String> draw(Context &ctx) noexcept;

	private:
		[[nodiscard]]
		ox::Optional<ox::String> handlePick() noexcept;

};

}
