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

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

OLD = '''    o.classText:SetText("Level " .. (death.level or "?") .. " " .. GDL:GetClassName(death.classId))
    o.classText:SetTextColor(0.9, 0.8, 0.6)
    
    o.classIcon:SetTexture(self:GetClassIcon(death.classId))

    -- Dynamische Klassenfarb-Elemente aktualisieren (topBar etc. entfernt -- Artwork liefert Rahmen)
    if o.iconGlow    then o.iconGlow:SetVertexColor(r, g, b, 0.55) end
    if o.iconBacking then o.iconBacking:SetVertexColor(r*0.24, g*0.16, b*0.05, 0.88) end
    if o.divider     then o.divider:SetVertexColor(r*0.85, g*0.65, b*0.18, 0.50) end
    if o.classGrad   then
        o.classGrad:SetVertexColor(r*0.50, g*0.30, b*0.08, 1)
        o.classGrad:SetAlpha(0.12)
    end

    -- \u2500\u2500 TEXTE VORBEREITEN (alle ausgeblendet, gestaffelt eingeblendet) \u2500\u2500\u2500\u2500\u2500\u2500\u2500
    -- classText: Klasse in Klassenfarbe
    o.classText:SetTextColor(r * 1.10, g * 1.10, b * 1.10)

    local zone = death.zone
    o.zoneText:SetText(zone and zone ~= "" and zone or "")

    local killer = death.killerName or death.killer
    local hasKiller = killer and killer ~= "" and killer ~= "Unknown"
    if hasKiller then
        local killerStr = "|cffFF6644Get\u00f6tet von:|r " .. killer
        if death.killerSpell and death.killerSpell ~= "" then
            killerStr = killerStr .. " |cffFFAAAA(" .. death.killerSpell .. ")|r"
        end
        o.killerText:SetText(killerStr)
    else
        o.killerText:SetText("")
    end

    local hasTimestamp = death.timestamp and death.timestamp > 0
    if hasTimestamp then
        o.timestampText:SetText("Gefallen am " .. date("%d.%m.%Y um %H:%M", death.timestamp) .. " Uhr")
    else
        o.timestampText:SetText("")
    end

    local lastWords = death.lastWords
    local hasLastWords = lastWords and lastWords ~= ""
    if hasLastWords then
        if #lastWords > 80 then lastWords = lastWords:sub(1, 77) .. "..." end
    end

    -- Mutual Exclusion: lastWords hat Vorrang \u00fcber killerText
    -- Wenn lastWords vorhanden \u2192 killerText wird in zoneText-Kette angeh\u00e4ngt,
    -- killerText (BOTTOM-Anker) bleibt ausgeblendet
    if hasLastWords and hasKiller then
        hasKiller = false
    end

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

    -- \u2500\u2500 REVEAL-HELFER: sanftes Einblenden einer FontString \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
    local function revealFade(widget, delay, dur)
        dur = dur or 0.38
        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
                local a = math.min(1, el / dur)
                -- Ease-out sqrt: schnell hell, dann verlangsamt
                widget:SetAlpha(math.sqrt(a))
                if el >= dur then
                    widget:SetAlpha(1)
                    self:SetScript("OnUpdate", nil)
                    self:Hide()
                end
            end)
            ticker:Show()
        end)
    end

    -- \u2500\u2500 GESTAFFELTE ENTHÜLLUNG (nach DeathCinematic Aufblend-Phase ~0.85s) \u2500\u2500\u2500
    -- Name: Typewriter bei 0.92s (existierendes Timing beibehalten)
    -- Klasse: 1.40s \u2014 Zone: 1.65s \u2014 Zeit: 1.85s \u2014 Killer: 2.05s \u2014 Letzte Worte: 2.30s
    local nameStr = death.name or ""

    revealFade(o.classText, 1.40)

    revealFade(o.zoneText, 1.65)

    if hasTimestamp then
        revealFade(o.timestampText, 1.85)
    end

    if hasKiller then
        revealFade(o.killerText, 2.05)
    end

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

NEW = '''    -- Col1: Klassen-Icon + Subtext "Stufe X Klasse"
    o.classIcon:SetTexture(self:GetClassIcon(death.classId))
    o.classText:SetText("Stufe " .. (death.level or "?") .. "  |cffBBBBBB" .. GDL:GetClassName(death.classId) .. "|r")
    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 (nur Name, Spaltenheader gibt 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
    -- Spell-Subzeile
    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 (nur 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

    -- lwLabel nur zeigen wenn lastWords vorhanden
    if o.lwLabel then
        if hasLastWords then o.lwLabel:Show() else o.lwLabel:Hide() end
    end

    -- Alle Elemente zu Beginn ausgeblendet (Alpha=0)
    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: sanftes Einblenden
    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 erscheint kompakt (alle Spalten gleichzeitig bei ~1.0s)
    local nameStr = death.name or ""
    local ROW_DELAY = 1.00

    -- Name als Typewriter (0.92s via DeathCinematic-Sequenz)
    -- Restliche Spalten: gleichzeitig einblenden
    revealFade(o.classText,      ROW_DELAY)
    revealFade(o.killerText,     ROW_DELAY)
    revealFade(o.timestampText,  ROW_DELAY)
    revealFade(o.zoneText,       ROW_DELAY)
    if o.spellText and o.spellText:IsShown() then revealFade(o.spellText, ROW_DELAY + 0.1) end
    if o.levelText then revealFade(o.levelText, ROW_DELAY + 0.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, '\\226\\128\\156' .. lastWords .. '\\226\\128\\157', 22)
            else
                o.lastWordsText:SetAlpha(1)
                o.lastWordsText:SetText('"' .. lastWords .. '"')
            end
        end)
    end'''

# Normalize line endings for matching
old_norm = OLD.replace('\r\n', '\n')
content_norm = content.replace('\r\n', '\n')

if old_norm in content_norm:
    new_content = content_norm.replace(old_norm, NEW, 1)
    with open(path, "w", encoding="utf-8") as f:
        f.write(new_content)
    print("SUCCESS: DisplayOverlay data block updated for table layout.")
else:
    # Try finding the key anchor lines
    lines = content_norm.split('\n')
    for i, line in enumerate(lines):
        if 'o.classText:SetText("Level "' in line:
            print(f"Found classText SetText at line {i+1}: {line.rstrip()}")
        if 'GESTAFFELTE' in line:
            print(f"Found GESTAFFELTE at line {i+1}: {line.rstrip()}")
        if 'Mutual Exclusion' in line:
            print(f"Found Mutual Exclusion at line {i+1}: {line.rstrip()}")
    print("FAILED: old string not found. See anchor lines above.")
