if not _G.ROBBEDACOP_PT then
    return
end

local function Box_create(panel, params, config)
	local box_panel = panel:panel(params)
	local color = config and config.color
	local bg_color = config and config.bg_color or Color(1, 0, 0, 0)

	box_panel:rect({
		blend_mode = "normal",
		name = "bg",
		halign = "grow",
		alpha = 0.00,
		layer = -1,
		valign = "grow",
		color = bg_color,
		rotation = 360,
	})
	return box_panel
end

Hooks:PostHook(HUDManager,"_setup_player_info_hud_pd2","ROBBEDACOP_PTHUDManager",function(self)
	local hm = managers.hud:script(PlayerBase.PLAYER_INFO_HUD_PD2)
	local parent_panel = hm and hm.panel
	local RACCS = ROBBEDACOP_PT.settings
	if ROBBEDACOP_PT.settings.hide_text then
		ROBBEDACOP_PT.text = ""
	end
	if alive(parent_panel) then
		ROBBEDACOP_PT.panel = Box_create(parent_panel, {
			name = "ROBBEDACOP_PT_box",
			rotation = 360,
			h = 0,
			w = 0,
			x = RACCS.counter_x,
			y = RACCS.counter_y
		})
		ROBBEDACOP_PT.counter = ROBBEDACOP_PT.panel:text({
			name = "ROBBEDACOP_PT_counter",
			align = "center",
			color = Color(255, RACCS.color_r or 255, RACCS.color_g or 255, RACCS.color_b or 255) / 255,
			font = tweak_data.hud.medium_font,
			font_size = RACCS.font_size,
			layer = 2,
			rotation = 360,
			text = "",
			vertical = "center",
		})
		self:add_updator("ROBBEDACOP_PT_update",function(t,dt)
			if RACCS.display_mode == 1 then
				ROBBEDACOP_PT.counter:set_text(ROBBEDACOP_PT.text .. 658893 - managers.custom_safehouse:get_trophy("trophy_washington").objectives[1].progress)
			elseif RACCS.display_mode == 2 then
				ROBBEDACOP_PT.counter:set_text(ROBBEDACOP_PT.text .. managers.custom_safehouse:get_trophy("trophy_washington").objectives[1].progress)
			end
		end)
	end
end)
