local frame = CreateFrame("Frame", "StatusLineFrame", UIParent)
frame:SetSize(400, 20)
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", frame.StopMovingOrSizing)

local text = frame:CreateFontString(nil, "OVERLAY")
text:SetAllPoints(frame)
text:SetJustifyH("CENTER")

-- Match chat font with thin outline
local font, size, flags = ChatFontNormal:GetFont()
text:SetFont(font, size, (flags or "").." OUTLINE")

local function GetRepairPercent()
    local total, current = 0, 0
    for i = 1, 18 do
        local cur, max = GetInventoryItemDurability(i)
        if cur and max then
            current = current + cur
            total = total + max
        end
    end
    if total == 0 then return 100 end
    return math.floor((current / total) * 100)
end

local function FormatGold()
    local gold = GetMoney()
    local g = math.floor(gold / 10000)
    local goldColor = "|cffffd700"  -- gold color
    return string.format("%d%s|r", g, goldColor.."g")
end

local function UpdateText()
    local goldText = FormatGold()
    local repair = GetRepairPercent()
    local _, _, worldMS = GetNetStats()
    local fps = math.floor(GetFramerate())

    -- Durability color
    local repairColor
    if repair >= 70 then
        repairColor = "|cff00ff00" -- Green
    elseif repair >= 30 then
        repairColor = "|cffffff00" -- Yellow
    else
        repairColor = "|cffff0000" -- Red
    end
    local repairText = string.format("%s%d%%|r", repairColor, repair)

    -- FPS color
    local fpsColor
    if fps >= 60 then
        fpsColor = "|cff00ff00"
    elseif fps >= 30 then
        fpsColor = "|cffffff00"
    else
        fpsColor = "|cffff0000"
    end
    local fpsText = string.format("%s%d |r", fpsColor, fps)

    -- MS color
    local msColor
    if worldMS <= 100 then
        msColor = "|cff00ff00"
    elseif worldMS <= 250 then
        msColor = "|cffffff00"
    else
        msColor = "|cffff0000"
    end
    local msText = string.format("%s%d |r", msColor, worldMS)

    text:SetText(string.format(
        " %s      Durability:%s      MS:%s FPS:%s",
        goldText,
        repairText,
        msText,
        fpsText
    ))
end

frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("PLAYER_MONEY")
frame:RegisterEvent("UPDATE_INVENTORY_DURABILITY")
frame:RegisterEvent("ZONE_CHANGED_NEW_AREA")
frame:RegisterEvent("PLAYER_LOGIN")

frame:SetScript("OnEvent", function(self, event)
    UpdateText()

    if event == "PLAYER_LOGIN" then
        C_Timer.After(0.5, function()
            local chatFrame = ChatFrame1
            if chatFrame then
                frame:ClearAllPoints()
                frame:SetPoint("BOTTOMLEFT", chatFrame, "TOPLEFT", -45, 25)
            end
        end)
    end
end)

C_Timer.NewTicker(2, UpdateText)
