
path = r"C:\Users\Norme\Documents\verdent-projects\new-project\GuildDeathLog\Modules\UI.lua"

with open(path, "r", encoding="utf-8") as f:
    lines = f.readlines()

# Find start: line with o.classText:SetText("Level "
# Find end:   closing 'end)' of the hasLastWords C_Timer block
start = None
end_line = None

for i, line in enumerate(lines):
    if start is None and 'o.classText:SetText("Level "' in line:
        start = i
    if start is not None and end_line is None:
        # Look for the closing of hasLastWords C_Timer.After block
        # which ends with "    end" on its own line around line 3723
        if i > start + 80 and line.strip() == 'end':
            # verify next non-blank line starts with blank or "    -- ── OVERLAY"
            for j in range(i+1, min(i+4, len(lines))):
                s = lines[j].strip()
                if s:
                    if 'OVERLAY' in s or 'SetAlpha' in s or 'SetScale' in s:
                        end_line = i
                    break
        if end_line is not None:
            break

print(f"Block: lines {start+1} to {end_line+1}")
print(f"Start: {lines[start].rstrip()}")
print(f"End:   {lines[end_line].rstrip()}")

NEW_BLOCK = '''\
    -- Col1: Klassen-Icon + Subtext "Stufe X Klasse"
    o.classIcon:SetTexture(self:GetClassIcon(death.classId))
    o.classText:SetText("Stufe " .. (death.level or "?") .. "  " .. GDL:GetClassName(death.classId))
    o.classText:SetTextColor(math.min(1, r * 1.05), math.min(1, g * 1.05), math.min(1, b * 1.05))

    -- Klassen-Farbakzente
    if o.iconGlow    then o.iconGlow:SetVertexColor(r, g, b, 0.45) end
    if o.iconBacking then o.iconBacking:SetVertexColor(r*0.24, g*0.16, b*0.05, 0.88) end
    if o.rowBg       then o.rowBg:SetVertexColor(r*0.08, g*0.05, b*0.02, 0.55) end
    if o.classGrad   then
        o.classGrad:SetVertexColor(r*0.50, g*0.30, b*0.08, 1)
        o.classGrad:SetAlpha(0.10)
    end
    if o.divider then o.divider:SetVertexColor(r*0.85, g*0.65, b*0.18, 0.50) end
    if o.sep2    then o.sep2:SetVertexColor(r*0.80, g*0.60, b*0.15, 0.50) end

    -- Col2: Killer (Spaltenheader liefert Kontext)
    local killer = death.killerName or death.killer
    local hasKiller = killer and killer ~= "" and killer ~= "Unknown"
    if hasKiller then
        o.killerText:SetText(killer)
    else
        o.killerText:SetText("Unbekannt")
    end
    if o.spellText then
        if death.killerSpell and death.killerSpell ~= "" then
            o.spellText:SetText("via " .. death.killerSpell)
            o.spellText:Show()
        else
            o.spellText:SetText("")
            o.spellText:Hide()
        end
    end

    -- Col3: Uhrzeit HH:MM:SS
    local hasTimestamp = death.timestamp and death.timestamp > 0
    if hasTimestamp then
        o.timestampText:SetText(date("%H:%M:%S", death.timestamp))
    else
        o.timestampText:SetText("--:--:--")
    end

    -- Col4: Zone
    local zone = death.zone
    o.zoneText:SetText(zone and zone ~= "" and zone or "Unbekannt")

    -- Letzte Worte
    local lastWords = death.lastWords
    local hasLastWords = lastWords and lastWords ~= ""
    if hasLastWords then
        if #lastWords > 90 then lastWords = lastWords:sub(1, 87) .. "..." end
    end

    -- Footer Level/Klasse
    if o.levelText then
        o.levelText:SetText("Stufe " .. (death.level or "?") .. "  \xc2\xb7  " .. GDL:GetClassName(death.classId))
        o.levelText:SetTextColor(math.min(1, r), math.min(1, g), math.min(1, b))
    end
    if o.lwLabel then
        if hasLastWords then o.lwLabel:Show() else o.lwLabel:Hide() end
    end

    -- Alle Elemente zu Beginn ausgeblendet
    o.nameText:SetAlpha(0);      o.nameText:Show()
    o.classText:SetAlpha(0);     o.classText:Show()
    o.killerText:SetAlpha(0);    o.killerText:Show()
    o.timestampText:SetAlpha(0); o.timestampText:Show()
    o.zoneText:SetAlpha(0);      o.zoneText:Show()
    o.lastWordsText:SetAlpha(0)
    if hasLastWords then o.lastWordsText:Show() else o.lastWordsText:Hide() end

    -- Reveal-Helfer
    local function revealFade(widget, delay, dur)
        dur = dur or 0.35
        C_Timer.After(delay, function()
            if not o:IsShown() then return end
            widget:SetAlpha(0)
            local el = 0
            local ticker = CreateFrame("Frame", nil, UIParent)
            ticker:SetScript("OnUpdate", function(self, dt)
                el = el + dt
                widget:SetAlpha(math.sqrt(math.min(1, el / dur)))
                if el >= dur then
                    widget:SetAlpha(1)
                    self:SetScript("OnUpdate", nil)
                    self:Hide()
                end
            end)
            ticker:Show()
        end)
    end

    -- Tabellenzeile: alle Spalten gleichzeitig bei ~1.0s
    local nameStr = death.name or ""
    revealFade(o.classText,      1.00)
    revealFade(o.killerText,     1.00)
    revealFade(o.timestampText,  1.00)
    revealFade(o.zoneText,       1.00)
    if o.spellText and o.spellText:IsShown() then revealFade(o.spellText, 1.10) end
    if o.levelText then revealFade(o.levelText, 1.25) end

    if hasLastWords then
        C_Timer.After(1.60, function()
            if not o:IsShown() then return end
            if FX and FX.TypewriterText then
                o.lastWordsText:SetAlpha(1)
                FX.TypewriterText(o.lastWordsText, '"' .. lastWords .. '"', 22)
            else
                o.lastWordsText:SetAlpha(1)
                o.lastWordsText:SetText('"' .. lastWords .. '"')
            end
        end)
    end
'''

new_lines = lines[:start] + [NEW_BLOCK] + lines[end_line+1:]

with open(path, "w", encoding="utf-8") as f:
    f.writelines(new_lines)

print(f"SUCCESS: DisplayOverlay updated (lines {start+1}-{end_line+1} replaced).")
print(f"New file: {len(new_lines)} lines")
