/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

#pragma once

#include "Base/ITickable.hpp"
#include "Base/ICloseable.hpp"
#include "Base/IPlatform.hpp"
#include "InputDeviceGLFW.hpp"
#include <array>

namespace OpenVulkano
{
	namespace GLFW
	{
		class WindowGLFW;

		class InputProviderGLFW final : public ITickable, public ICloseable
		{
			friend WindowGLFW;
			static InputProviderGLFW* INSTANCE;

			std::array<ControllerGLFW, 16> controllers = {};
			MouseGLFW mouse;
			KeyboardGLFW keyboard;
			uint8_t mouseButtons = 0;
			bool activeWindowChanged = false;
			
		public:
			void Init();

			void Close() override;

			void PreTick();

			void Tick() override;

			void SetMouseButton(int button, bool state);

			void SetKeyboardKey(IWindow* window, int key, int scanCode, int action, int mods);

			void MouseEnterExitWindow(IWindow* window);

			void OnJoystickConnect(int joystickId);

			void OnJoystickDisconnect(int joystickId);

			static void JoystickCallback(int joystickId, int joystickEvent);
		};
	}
}
