#pragma once
#include <memory>
#include <vector>
#include <atomic>
#include <mutex>
#include <string> 
#include "Engine/Engine.h"
#include "Core/Features/Cache/Cache.h"
#include "ImGui/imgui.h"

namespace Globals {
	struct CachedPlayer {
		SDK::Instance Character;
		SDK::Instance Head;

		SDK::Instance Torso;
		SDK::Instance LeftArm;
		SDK::Instance RightArm;
		SDK::Instance LeftLeg;
		SDK::Instance RightLeg;

		SDK::Instance UpperTorso;
		SDK::Instance LowerTorso;
		SDK::Instance LeftUpperArm;
		SDK::Instance LeftLowerArm;
		SDK::Instance LeftHand;
		SDK::Instance RightUpperArm;
		SDK::Instance RightLowerArm;
		SDK::Instance RightHand;
		SDK::Instance LeftUpperLeg;
		SDK::Instance LeftLowerLeg;
		SDK::Instance LeftFoot;
		SDK::Instance RightUpperLeg;
		SDK::Instance RightLowerLeg;
		SDK::Instance RightFoot;

		SDK::Instance HumanoidRootPart;
		SDK::Instance Humanoid;
		std::string Name = "";
		std::string Tool_Name = "None";
		float Health = 0.f;
		float Distance = 0.f;
	};
	__declspec(selectany) std::mutex Cache_Mutex;
	__declspec(selectany) std::vector<CachedPlayer> Player_Cache;

	__declspec(selectany) SDK::Instance Datamodel = {};
	__declspec(selectany) SDK::Players LocalPlayer = {};
	__declspec(selectany) SDK::Instance Camera = {};
	__declspec(selectany) SDK::Players Players = {};
	inline SDK::Instance Workspace = {};
	inline SDK::Instance Lighting = {};

	inline SDK::Instance VisualEngine = {};
	inline SDK::Instance Renderview = {};
}

namespace Globals {

	namespace Settings {

		inline bool Team_Check;
		inline bool Client_Check;
		inline bool Streamproof;
		inline int Performance_Mode = 2;
		inline bool Wobbly_Enabled{ true };
		inline float Wobbly_Strength{ 3.0f }; // Сила волны (0.0 - 10.0)
		inline float Wobbly_Speed{ 5.0f };
	}

	namespace World {

		inline bool Skybox;
		inline bool Rotate;
		inline bool Ambience;
		inline bool Fog;
		inline bool Brightness;
		inline bool Exposure;
		inline bool FOV;

		inline int Skybox_Type = 0;
		inline float Skybox_Rotate_Speed = 1.0f;
		inline float Fog_Distance = 300.0f;
		inline float FOV_Distance = 90.0f;

		inline float ExposureI = 0.0f;
		inline float BrightnessI = 1.0f;

		namespace Colors {

			inline float Ambience[4] = { 0.960784f, 0.709804f, 0.960784f, 1.0f };
			inline float Fog[4] = { 0.960784f, 0.709804f, 0.960784f, 1.0f };
		}
	}

	namespace Aimbot {

		inline bool useFov;


		inline bool Enabled;
		inline bool DrawFov;
		inline bool FovSpin;
		inline bool ClosestPlayerFound;
		inline bool FillFov;
		inline bool AimbotSticky;
		inline bool Shake;
		inline bool KnockedCheck;

		inline float ShakeX{ 0.0f };
		inline float ShakeY{ 0.0f };
		inline float ShakeZ{ 0.0f };


		inline SDK::Instance AimTarget;
		inline float FovSize = 50;

		inline int HitPart = 0; // 0 = Head, 1 = Torso, 2 = LowerTorso
		inline int Aimbot_type = 0; // 0 = Mouse , 1 = Camera

		inline float FovColor[4] = { 0.960784f, 0.709804f, 0.960784f, 1.0f };

		inline int FovSpinSpeed = 1;

		inline ImGuiKey Aimbot_Key = ImGuiKey_Q;
		inline ImKeyBindMode Aimbot_Mode = ImKeyBindMode_Hold;


		namespace Camera {
			inline float Smoothing_X{ 1.0f };
			inline float Smoothing_Y{ 1.0f };
		}

		namespace Mouse {
			inline float Smoothing_X{ 1.0f };
			inline float Smoothing_Y{ 1.0f };

			inline float Mouse_Sensitivty{ 1.0f };
		}
	}

	namespace Silent
	{
		inline bool DrawFov{ false };
		inline bool Enabled{ false };
		inline bool StickyAim{ false };
		inline bool SpoofMouse{ true };
		inline bool UseFov{ false };
		inline bool KnockedCheck{ false };
		inline bool GunBasedFov{ false };
		inline float Fov{ 67.67f };
		inline float FovDoubleBarrel{ 67.67f };
		inline float FovTacticalShotgun{ 67.67f };
		inline float FovRevolver{ 67.67f };
		inline ImGuiKey Silent_Key = ImGuiKey_Q;
		inline ImKeyBindMode Silent_Mode = ImKeyBindMode_Toggle;
		inline int AimPart{ 0 };
		inline float FovColor[4]{ 0.960784f, 0.709804f, 0.960784f, 1.0f };
		inline int FovSpinSpeed = 1;
		inline bool FovSpin;
		inline bool FillFov;
	}

	namespace Visuals {
		inline bool Box_Fill;
		inline bool Box_Fill_Gradient;
		inline bool Box_Fill_Gradient_Rotate;
		inline bool Name;
		inline bool Distance;
		inline bool Skeleton;
		inline bool Chams;
		inline bool ChamsFade;

		inline bool Enabled = true;
		inline bool Box = false;
		inline bool Healthbar = false;
		inline bool Health = false;
		inline bool Tool = false;
		inline bool Rig_Type = false;

		inline float Render_Distance = 200.0f;

		inline int ChamsFadeSpeed = 2;
		inline int BoxFillSpeed = 2;
		inline int Healthbar_Type = 1;
		inline int Box_Type = 0;
		inline int Box_Fill_Type = 0;
		inline int Name_Type = 1;
		inline int Thickness = 2;

		namespace Colors {

			inline float Box[4] = { 0.960784f, 0.709804f, 0.960784f, 1.0f };
			inline float BoxFill_Top[4] = { 0.960784f, 0.709804f, 0.960784f, 0.50f };
			inline float BoxFill_Bottom[4] = { 0.f, 0.f, 0.f, 0.50f };
			inline float Healthbar[4] = { 0.960784f, 0.709804f, 0.960784f, 1.0f };
			inline float Name[4] = { 0.960784f, 0.709804f, 0.960784f, 1.0f };
			inline float Distance[4] = { 0.960784f, 0.709804f, 0.960784f, 1.0f };
			inline float Rig_Type[4] = { 0.960784f, 0.709804f, 0.960784f, 1.0f };
			inline float Tool[4] = { 0.960784f, 0.709804f, 0.960784f, 1.0f };
			inline float Health[4] = { 0.960784f, 0.709804f, 0.960784f, 1.0f };
			inline float Skeleton[4] = { 0.960784f, 0.709804f, 0.960784f, 1.0f };
			inline float Chams[4] = { 0.960784f, 0.709804f, 0.960784f, 1.0f };
			inline float ChamsOutline[4] = { 0.f, 0.f, 0.f, 1.0f };

			inline float Healthbar_Top[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
			inline float Healthbar_Middle[4] = { 1.0f, 1.0f, 0.0f, 1.0f };
			inline float Healthbar_Bottom[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
		}
	}

	namespace Misc {
		inline bool firerate = false;
		inline float fireratevalue = 0.05f;

		inline bool Fly = false;
		inline ImGuiKey Fly_Key = ImGuiKey_F;
		inline ImKeyBindMode Fly_Mode = ImKeyBindMode_Toggle;
		inline float Fly_Speed = 50.0f;  

		inline bool Noclip = false;
		inline ImGuiKey Noclip_Key = ImGuiKey_V;
		inline ImKeyBindMode Noclip_Mode = ImKeyBindMode_Toggle;

		inline bool Desync = false;
		inline ImGuiKey Desync_Key = ImGuiKey_C;
		inline ImKeyBindMode Desync_Mode = ImKeyBindMode_Toggle;
		inline bool desync_active = false;
		inline SDK::Vector3 desync_activation_pos = { 0.f, 0.f, 0.f };
		inline bool DesyncChams = true;
		inline float DesyncChamsColor[4] = { 0.760f, 0.537f, 0.760f, 0.21f };
		inline float DesyncChamsOutline[4] = { 0.760f, 0.537f, 0.760f, 1.0f };
		inline bool desync_interval_enabled{ false };
		inline int desync_pulse_interval_ms{ 100 };
		inline bool desync_interval_is_lagging{ false };
		inline float desync_interval_total_time{ 0.f };
		inline float desync_interval_time_left{ 0.f };

	}

	namespace Hitbox {
		inline bool Enabled{ false };
		inline float Size{ 5.f };
		inline bool HeadOnly{ false };
		inline ImGuiKey Hitbox_Key = ImGuiKey_H;
		inline ImKeyBindMode Hitbox_Mode = ImKeyBindMode_Toggle;

		inline bool DrawHitbox{ false };           
		inline bool FillHitbox{ false };           
		inline float HitboxColor[4]{ 1.f, 0.f, 0.f, 1.f };      
		inline float HitboxFillColor[4]{ 1.f, 0.f, 0.f, 0.3f }; 
		inline float HitboxThickness{ 1.f };       
	}
}