local _,ns = ...
ns.ADDUIEVENT("PLAYER_ENTERING_WORLD", function()
if AddUIDB.unitf ==  false  then return end

local function CreateBarPctText(frame, ap, rp, x, y, font, manabar)
if not frame then return end
	local bar = ( manabar and frame.manabar ) or ( not manabar and frame.healthbar )
	if bar then
		if bar.pctText then
			bar.pctText:ClearAllPoints()
			bar.pctText:SetPoint(ap, bar, rp, x, y)
		else
		
			font = font or "NumberFontNormal"
			bar.pctText = frame:CreateFontString(nil, "OVERLAY", font)
			bar.pctText:SetPoint(ap, bar, rp, x, y)
			bar.pctText:SetText("???")
		end
	end
end
--创建框架
if AddUIDB.unitbt then
local PlayerFramefont = CreateBarPctText(PlayerFrame, "LEFT", "RIGHT", 2, 0, "NumberFontNormalLarge")
--local PetFramefont = CreateBarPctText(PetFrame, "LEFT", "RIGHT", 2, 0)
PetFrameHealthBarText:SetTextHeight(9)
PetFrameManaBarText:SetTextHeight(9)

local TargetFramefont = CreateBarPctText(TargetFrame, "RIGHT", "LEFT", 0, 0, "NumberFontNormalLarge")
local FocusFramefont = CreateBarPctText(FocusFrame, "RIGHT", "LEFT", 0, 0, "NumberFontNormalLarge")

local TargetFrameToTfont = CreateBarPctText(TargetFrameToT, "LEFT", "RIGHT", 0, 0)
local FocusFrameToTfont = CreateBarPctText(FocusFrameToT, "LEFT", "RIGHT", 0, 0)

for i = 1, MAX_BOSS_FRAMES do
	local bossFrame = _G["Boss"..i.."TargetFrame"]
	local bossFrame = CreateBarPctText(bossFrame,"RIGHT", "LEFT", 0, 0, "NumberFontNormalLarge")
end
end


end)
--百分比
local function textUpdate(bar)
	if bar.pctText then
		local textType = GetCVar("statusTextDisplay")
		local frame = bar:GetParent()
		if bar.StatusBar then bar=bar.StatusBar end
		local value = bar:GetValue()
		local _, maxvalue = bar:GetMinMaxValues()
		if textType == "NUMERIC" then
			bar.pctText:SetText(ns.ADDUIBFB(value,maxvalue))
		else
			bar.pctText:SetText("")
		end
	end
end

local function ADDUIUpdateTextString(s)
if AddUIDB.unitf ==  false  then return end
	if GetCVar("statusTextDisplay") ~= "PERCENT" then 
		if 	s.TextString and s.currValue then 
			s.TextString:SetText(ns.ADDUIWK(s:GetValue())) 
		end
		if 	s.RightText and s.currValue then
			s.RightText:SetText(ns.ADDUIWK(s:GetValue()))
		end
	end
	if GetCVar("statusTextDisplay") == "PERCENT" then
		if 	s.TextString and s.currValue then 
			local _,maxv = s:GetMinMaxValues()
			s.TextString:SetText(ns.ADDUIBFB(s:GetValue(),maxv))
		end
	end
	if s.LeftText and s.TextString and s.currValue then
		local _,maxv = s:GetMinMaxValues()
		s.LeftText:SetText(ns.ADDUIBFB(s:GetValue(),maxv))
	end
end
hooksecurefunc("UnitFrameHealthBar_OnUpdate", textUpdate)
hooksecurefunc("UnitFrameHealthBar_OnUpdate", ADDUIUpdateTextString)
hooksecurefunc("UnitFrameManaBar_OnUpdate", ADDUIUpdateTextString)
--hooksecurefunc(TextStatusBarMixin,"UpdateTextString", ADDUIUpdateTextString)
--hooksecurefunc(TextStatusBarMixin,"UpdateTextString", textUpdate)

--武僧酒池
--[[
hooksecurefunc("MonkStaggerBar_UpdateValue",function(monkt)
local maxhealth = UnitHealthMax(monkt:GetParent().unit);
local currstagger = UnitStagger(monkt:GetParent().unit)
if currstagger and maxhealth then
if currstagger ~= 0 then currstagger  = ADDUIWK(currstagger) end
if monkt.TextString then monkt.TextString:SetText(currstagger.."|cff00E5EE / |r"..ADDUIWK(maxhealth)) end
if monkt.RightText then monkt.RightText:SetText(currstagger) end
end
end)
]]