function Load(name)
	local resourceName = GetCurrentResourceName()
	local chunk = LoadResourceFile(resourceName, ('data/%s.lua'):format(name))
	if chunk then
		local err
		chunk, err = load(chunk, ('@@%s/data/%s.lua'):format(resourceName, name), 't')
		if err then
			error(('\n^1 %s'):format(err), 0)
		end
		return chunk()
	end
end

-------------------------------------------------------------------------------
-- Settings
-------------------------------------------------------------------------------

Config = {}

-- It's possible to interact with entities through walls so this should be low
Config.MaxDistance = 7.0

-- Enable debug options
Config.Debug = false

-- Supported values: true, false
Config.Standalone = false

-- Enable outlines around the entity you're looking at
Config.EnableOutline = false

-- Whether to have the target as a toggle or not
Config.Toggle = false

-- Draw a Sprite on the center of a PolyZone to hint where it's located
Config.DrawSprite = false

-- The default distance to draw the Sprite
Config.DrawDistance = 10.0

-- The color of the sprite in rgb, the first value is red, the second value is green, the third value is blue and the last value is alpha (opacity). Here is a link to a color picker to get these values: https://htmlcolorcodes.com/color-picker/
Config.DrawColor = {255, 255, 255, 255}

-- The color of the sprite in rgb when the PolyZone is targeted, the first value is red, the second value is green, the third value is blue and the last value is alpha (opacity). Here is a link to a color picker to get these values: https://htmlcolorcodes.com/color-picker/
Config.SuccessDrawColor = {30, 144, 255, 255}

-- The color of the outline in rgb, the first value is red, the second value is green, the third value is blue and the last value is alpha (opacity). Here is a link to a color picker to get these values: https://htmlcolorcodes.com/color-picker/
Config.OutlineColor = {255, 255, 255, 255}

-- Enable default options (Toggling vehicle doors)
Config.EnableDefaultOptions = true

-- Disable the target eye whilst being in a vehicle
Config.DisableInVehicle = false

-- Key to open the target eye, here you can find all the names: https://docs.fivem.net/docs/game-references/input-mapper-parameter-ids/keyboard/
Config.OpenKey = 'LMENU' -- Left Alt

-- Control for key press detection on the context menu, it's the Right Mouse Button by default, controls are found here https://docs.fivem.net/docs/game-references/controls/
Config.MenuControlKey = 238

-------------------------------------------------------------------------------
-- Target Configs
-------------------------------------------------------------------------------

-- These are all empty for you to fill in, refer to the .md files for help in filling these in

Config.CircleZones = {

}

Config.BoxZones = {

	-- -- VICEROY HOSPITAL

    -- ["emschecking"] = {
    --     name = "emschecking",
    --     coords = vector3(-816.98, -1237.2, 7.34), -- VICEROY HOSPITAL
    --     length = 0.8,
    --     width = 0.8,
    --     heading = 50,
    --     debugPoly = false,
    --     minZ = 3.54,
    --     maxZ = 7.54,
    --     options = {
    --         {
    --             type = "client",
    --             event = "qb-ambulancejob:checkin",
    --             icon = "fas fa-procedures",
    --             label = "Emergency Checking ",
    --         },
    --     },
    --     distance = 2.5,
    -- },

    -- ["emsarmory"] = {
    --     name = "emsarmory",
    --     coords = vector3(-820.32, -1243.47, 7.34), -- VICEROY HOSPITAL
    --     length = 3.0,
    --     width = 0.5,
    --     heading = 50,
    --     debugPoly = false,
    --     minZ = 4.74,
    --     maxZ = 8.74,
    --     options = {
    --         {
    --             type = "client",
    --             event = "qb-ambulancejob:armory",
    --             icon = "fas fa-user-md",
    --             label = "Equipment Locker",
    --             job = "ambulance",
    --         },
    --     },
    --     distance = 2.5,
    -- },

    -- ["emsstash"] = {
    --     name = "Emsstash",
    --     coords = vector3(-827.24, -1237.13, 7.34), -- VICEROY HOSPITAL
    --     length = 0.5,
    --     width = 5,
    --     heading = 50,
    --     debugPoly = false,
    --     minZ = 4.94,
    --     maxZ = 8.94,
    --     options = {
    --         {
    --             type = "client",
    --             event = "qb-ambulancejob:stash",
    --             icon = "fas fa-dungeon",
    --             label = "Open Your Stash",
    --             job = "ambulance",
    --         },
    --     },
    --     distance = 2.5,
    -- },

    -- LIBERTY CITY POLICE NYPD

    -- ["Policefingerprint"] = {
    --     name = "Policefingerprint",
    --     coords = vector3(473.98, -1014.49, 26.27), -- LIBERTY CITY POLICE NYPD
    --     length = 3,
    --     width = 2,
    --     heading = 270,
    --     debugPoly = false,
    --     minZ = 22.67,
    --     maxZ = 26.67,
    --     options = {
    --         {
    --             type = "client",
    --             event = "qb-police:client:scanFingerPrint",
    --             icon = "fas fa-fingerprint",
    --             label = "Open Fingerprint",
    --             job = "police",
    --         },
    --     },
    --     distance = 2.5,
    -- },

    ["PoliceArmory"] = {
        name = "PoliceArmory",
        coords = vector3(-102.35, -95.27, -2.73), -- LIBERTY CITY POLICE NYPD
        length = 4.7,
        width = 1.0,
        heading = 30,
        debugPoly = false,
        minZ = 4.33,
        maxZ = 0.33,
        options = {
            {
                type = "client",
                event = "qb-police:client:openArmoury",
                icon = "fas fa-boxes",
                label = "Open Police Armory",
                job = "police",
            },
        },
        distance = 2.5,
    },

    ["PoliceStash"] = {
        name = "PoliceStash",
        coords = vector3(-95.21, -94.09, -2.73), -- LIBERTY CITY POLICE NYPD
        length = 0.55,
        width = 1.6,
        heading = 30,
        debugPoly = false,
        minZ = 4.73,
        maxZ = 0.73,
        options = {
            {
                type = "client",
                event = "qb-police:client:openStash",
                icon = "fas fa-dungeon",
                label = "Open Your Stash",
                job = "police",
            },
        },
        distance = 2.5,
    },

    ["PoliceEvidence"] = { 
        name = "PoliceEvidence",
        coords = vector3(-69.74, -83.87, -1.02), -- LIBERTY CITY POLICE NYPD
        length = 5.4,
        width = 0.9,
        heading = 297,
        debugPoly = false,
        minZ = 3.62,
        maxZ = 0.38,
        options = {
            {
                type = "client",
                event = "qb-police:client:openTrash1",
                icon = "fas fa-trash",
                label = "Police Evidence 1", 
                job = "police",
            },
			{	
				type = "client",
				event = "qb-police:client:openTrash2",
				icon = "fas fa-trash",
				label = "Police Evidence 2",
				job = "police",
			 },
			 {	
				type = "client",
				event = "qb-police:client:openTrash3",
				icon = "fas fa-trash",
				label = "Police Evidence 3",
				job = "police",
			 },
			 {
				type = "client",
				event = "qb-police:client:openTrash4",
				icon = "fas fa-trash",
				label = "Police Evidence 4",
				job = "police",
			 },
             {
				type = "client",
				event = "qb-police:client:openTrash5",
				icon = "fas fa-trash",
				label = "Police Evidence 5",
				job = "police",
			 },
        },
        distance = 2.5,
    },


    ["PoliceEvidence2"] = {
        name = "PoliceEvidence2",
        coords = vector3(-73.38, -85.54, -1.02), -- LIBERTY CITY POLICE NYPD
        length = 0.65,
        width = 2.75,
        heading = 27,
        debugPoly = false,
        minZ = 3.62,
        maxZ = 0.38,
        options = {
            {
                type = "client",
                event = "police:client:EvidenceStashDrawer",
                icon = "fas fa-dungeon",
                label = "Police Evidence Mdt",
                job = "police",
            },
        },
        distance = 2.5,
    },

    -- PRISON

    -- ["prisonslushy"] = {
    --     name = "prisonslushy",
    --     coords = vector3(1777.66, 2560.07, 45.67), -- PRISON
    --     length = 0.6,
    --     width = 0.6,
    --     heading = 0,
    --     debugPoly = false,
	-- 	minZ = 45.67,
	-- 	maxZ = 46.67,
    --     options = {
	-- 		{
    --             type = "client",
    --             event = "qb-prison:client:slushy",
    --             icon = "fas fa-wine-bottle",
    --             label = "Make Slushy",
    --         },
    --     },
    --     distance = 1.5
    -- },
	-- ["prisontime"] = {
    --     name = "prisontime",
    --     coords = vector3(1827.3, 2587.72, 46.01), -- PRISON
    --     length = 0.45,
    --     width = 0.55,
    --     heading = 0,
    --     debugPoly = false,
	-- 	minZ = 46.11,
	-- 	maxZ = 47.01,
    --     options = {
	-- 		{
    --             type = "client",
    --             event = "qb-prison:client:checkTime",
    --             icon = "fas fa-user-clock",
    --             label = "Check Jail Time",
    --         },
    --     },
    --     distance = 1.5
    -- },
	-- ["prisoncanteen"] = {
    --     name = "prisoncanteen",
    --     coords = vector3(1783.12, 2559.56, 45.67), -- PRISON
    --     length = 0.4,
    --     width = 0.55,
    --     heading = 0,
    --     debugPoly = false,
	-- 	minZ = 45.62,
	-- 	maxZ = 46.07,
    --     options = {
	-- 		{
    --             type = "client",
    --             event = "qb-prison:client:useCanteen",
    --             icon = "fas fa-utensils",
    --             label = "Open Canteen",
    --         },
    --     },
    --     distance = 1.5
    -- },

}


Config.PolyZones = {

}

Config.TargetBones = {

	["Vehicle"] = {
        bones = {
            "door_dside_f",
            "door_dside_r",
            "door_pside_f",
            "door_pside_r"
        },
        options = {
            {
                type = "client",
                event = "qb-vehiclekeys:client:GiveKeys",
                icon = "fas fa-car",
                label = "Give Keys",
            },
			{
                type = "client",
                event = "qb-trunk:client:GetIn",
                icon = "fas fa-user-secret",
                label = "Get In Trunk",
            },
			{
                type = "client",
                event = "ps-fuel:client:petrolcanrefuel",
                icon = "fas fa-gas-pump",
                label = "Refuel Car",
                item = 'weapon_petrolcan',
            },
			{
                type="client",
                event="ps-fuel:client:siphonfuel",
                label = "Siphon Fuel",
                icon = 'fas fa-gas-pump',
                item = 'fuelsiphon',
            },
            {
                type = "client",
                event = "police:client:SetPlayerOutVehicle",
                icon = "fas fa-chevron-circle-right",
                label = "Take Out Of Vehicle",
            },
            {
                type = "client",
                event = "police:client:PutPlayerInVehicle",
                icon = "fas fa-chevron-circle-left",
                label = "Place In Vehicle",
            },
			{
                type= "client",
                event= "angelicxs-flipcar:flipcar",
                label = "Flip Car",
                icon = "fas fa-arrow-up",
            },
            {
                type = "client",
                event = "police:client:ImpoundVehicle",
                icon = "fas fa-car",
                label = "Impound Vehicle",
                job = "police"
            },
        },
        distance = 5.0
    },

    
}	


Config.TargetModels = {


	-- BIKE

    ["bikes"] = {
		models = {
			'akuma',
            'avarus',
            'bagger',
            'bati',
            'bati2',
            'bf400',
            'carbonrs',
            'chimera',
            'cliffhanger',
            'daemon',
            'daemon2',
            'defiler',
            'deathbike',
            'deathbike2',
            'deathbike3',
            'diablous',
            'diablous2',
			'enduro',
			'double',
			'faggio',
			'faggio2',
			'faggio3',
			'fcr',
			'fcr2',
			'gargoyle',
			'hakuchou',
			'hakuchou2',
			'hexer',
			'innovation',
			'lectro',
			'manchez',
			'nemesis',
			'nightblade',
			'oppressor',
			'pcj',
			'ratbike',
			'ruffian',
			'sanchez',
			'sanchez2',
			'sanctus',
			'shotaro',
			'sovereign',
			'stryder',
			'thrust',
			'vader',
			'vindicator',
			'vortex',
			'wolfsbane',
			'zombiea',
			'zombieb',
			'manchez2',
			'shinobi',
			'reever',
			'esskey',
			'z8r',
			's1000drag',
			'policeb',
			'bmwr',
			'r1',
			'zx10',
		},
		options = {
			{
                type = "client",
                event = "qb-vehiclefailure:client:CleanVehicle2",
                icon = "fas fa-car",
                label = "Clean Vehicle",
                job = 'mechanic',
            },
			{
                type = "client",
                event = "cc-fuel:client:petrolcanrefuel",
                icon = "fas fa-gas-pump",
                label = "Refuel Car",
                item = 'weapon_petrolcan',
            },
            {
                type="client",
                event="cc-fuel:client:siphonfuel",
                label = "Siphon Fuel",
                icon = 'fas fa-gas-pump',
                item = 'fuelsiphon',
            },
		},
		distance = 2.5,
	},

}

Config.GlobalPedOptions = {

}

Config.GlobalVehicleOptions = {

}

Config.GlobalObjectOptions = {

}

Config.GlobalPlayerOptions = {

    options = {
        {
            type = "client",
            event = "qb-phone:client:GiveContactDetails",
            icon = "fas fa-address-book",
            label = "Give Contact Details",
        },
        {
            event = "police:client:RobPlayer",
            icon = "fas fa-user-secret",
            label = "Rob Person",
        },
        {
            type = "client",
            event = "police:client:CuffPlayer",
            icon = "fas fa-hands",
            label = "Hardcuff / Uncuff",
            job = "police", "ambulance",
            item = "handcuffs",
        },
        {
            type = "client",
            event = "police:client:EscortPlayer",
            icon = "fas fa-key",
            label = "Escort",
        },
        {
            type = "client",
            event = "police:client:PutPlayerInVehicle",
            icon = "fas fa-chevron-circle-left",
            job = "police",
            label = "Place In Vehicle",
        },
        {
            type = "client",
            event = "police:client:SetPlayerOutVehicle",
            icon = "fas fa-chevron-circle-right",
            job = "police",
            label = "Take Out Of Vehicle",
        },
        {
            type = "client",
            event = "police:client:SearchPlayer",
            icon = "fas fa-circle",
            label = "Search Person",
			job = "police", "ambulance",
        },

    },
    distance = 2.5,	

}

Config.Peds = {

}

-------------------------------------------------------------------------------
-- Functions
-------------------------------------------------------------------------------
local function JobCheck() return true end
local function GangCheck() return true end
local function JobTypeCheck() return true end
local function ItemCheck() return true end
local function CitizenCheck() return true end

CreateThread(function()
	local state = GetResourceState('qb-core')
	if state ~= 'missing' then
		local timeout = 0
		while state ~= 'started' and timeout <= 100 do
			timeout += 1
			state = GetResourceState('qb-core')
			Wait(0)
		end
		Config.Standalone = false
	end
	if Config.Standalone then
		local firstSpawn = false
		local event = AddEventHandler('playerSpawned', function()
			SpawnPeds()
			firstSpawn = true
		end)
		-- Remove event after it has been triggered
		while true do
			if firstSpawn then
				RemoveEventHandler(event)
				break
			end
			Wait(1000)
		end
	else
		local QBCore = exports['qb-core']:GetCoreObject()
		local PlayerData = QBCore.Functions.GetPlayerData()

		ItemCheck = QBCore.Functions.HasItem

		JobCheck = function(job)
			if type(job) == 'table' then
				job = job[PlayerData.job.name]
				if job and PlayerData.job.grade.level >= job then
					return true
				end
			elseif job == 'all' or job == PlayerData.job.name then
				return true
			end
			return false
		end

		JobTypeCheck = function(jobType)
			if type(jobType) == 'table' then
				jobType = jobType[PlayerData.job.type]
				if jobType then
					return true
				end
			elseif jobType == 'all' or jobType == PlayerData.job.type then
				return true
			end
			return false
		end

		GangCheck = function(gang)
			if type(gang) == 'table' then
				gang = gang[PlayerData.gang.name]
				if gang and PlayerData.gang.grade.level >= gang then
					return true
				end
			elseif gang == 'all' or gang == PlayerData.gang.name then
				return true
			end
			return false
		end

		CitizenCheck = function(citizenid)
			return citizenid == PlayerData.citizenid or citizenid[PlayerData.citizenid]
		end

		RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
			PlayerData = QBCore.Functions.GetPlayerData()
			SpawnPeds()
		end)

		RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
			PlayerData = {}
			DeletePeds()
		end)

		RegisterNetEvent('QBCore:Client:OnJobUpdate', function(JobInfo)
			PlayerData.job = JobInfo
		end)

		RegisterNetEvent('QBCore:Client:OnGangUpdate', function(GangInfo)
			PlayerData.gang = GangInfo
		end)

		RegisterNetEvent('QBCore:Player:SetPlayerData', function(val)
			PlayerData = val
		end)
	end
end)

function CheckOptions(data, entity, distance)
	if distance and data.distance and distance > data.distance then return false end
	if data.job and not JobCheck(data.job) then return false end
	if data.excludejob and JobCheck(data.excludejob) then return false end
	if data.jobType and not JobTypeCheck(data.jobType) then return false end
	if data.excludejobType and JobTypeCheck(data.excludejobType) then return false end
	if data.gang and not GangCheck(data.gang) then return false end
	if data.excludegang and GangCheck(data.excludegang) then return false end
	if data.item and not ItemCheck(data.item) then return false end
	if data.citizenid and not CitizenCheck(data.citizenid) then return false end
	if data.canInteract and not data.canInteract(entity, distance, data) then return false end
	return true
end
Config.TargetModels = {
    ["PDGarage"] = {
		models = {
			`ig_trafficwarden`
		},
		options = {
			{
				event = "garage:menu",
				icon = "fas fa-shopping-cart",
				label = "Take Out Pd Vehicle",
				job = "police",
				
			},
		},
		distance = 4.5,
	}
}
