local AceGUI = LibStub("AceGUI-3.0")

-- Ensure SharedMedia is loaded
local LSM = LibStub("LibSharedMedia-3.0")

-- Function to show the change log
Critmatic.showChangeLog = function()
    -- Create a container frame
    local frame = AceGUI:Create("Frame")
    frame:SetTitle("CritMatic - Change Log")
    frame:SetStatusText("Need Help? Copy the Discord Link in General Options. ")
    frame:SetLayout("Fill")
    frame:SetWidth(600)
    frame:SetHeight(500)

    local backgroundTexture = LSM:Fetch("background", Critmatic.db.profile.changeLogPopUp.borderAndBackgroundSettings.backgroundTexture)
    frame.frame:SetBackdrop({
        bgFile = backgroundTexture,
        edgeFile = LSM:Fetch("border", Critmatic.db.profile.changeLogPopUp.borderAndBackgroundSettings.borderTexture),
        edgeSize = Critmatic.db.profile.changeLogPopUp.borderAndBackgroundSettings.borderSize,
    })

    -- Create a scroll container
    local scrollContainer = AceGUI:Create("SimpleGroup")
    scrollContainer:SetFullWidth(true)
    scrollContainer:SetFullHeight(true)
    scrollContainer:SetLayout("Fill")
    frame:AddChild(scrollContainer)

    -- Create a ScrollFrame
    local scroll = AceGUI:Create("ScrollFrame")
    scroll:SetLayout("List")
    scrollContainer:AddChild(scroll)

    -- Add the change log text
    local changelog = [[

[v6.1.0-release] - 05/10/2026

 Changed:

 TOC Interface line refreshed for every live Classic WoW client. Multi-flavor list is now 50503, 40402, 38001, 20505, 11508 covering MoP Classic 5.5.3, Cataclysm, Wrath / Titan Reforged 3.8.1, TBC Anniversary 2.5.5, and Classic Era 1.15.8. Per-flavor packager keys updated to match: Interface-Mists 50503, Interface-Cata 40402, Interface-Wrath 38001, Interface-BCC 20505, Interface-Classic 11508. The bogus Interface-Titan key was dropped.

 Removed:

 Retail / Mainline support dropped this release. Patch 12.0 ("Midnight") blocks unprivileged addons from registering COMBAT_LOG_EVENT_UNFILTERED, which is what CritMatic uses to record crits. Without CLEU there is no addon. Shipping a retail-listed CritMatic that can't perform its core function would just mislead users, so retail is intentionally untargeted until Blizzard relaxes the restriction. Classic flavors unaffected.


[v6.0.0-release] - 05/09/2026

 Removed (breaking):

 The "Send to /say" toggle and the entire SAY broadcast path are gone. /say is muted in instances by Blizzard and combined with the combat-end timing window made the broadcast unreliable. Group channels (Party / Raid / Battlegrounds via INSTANCE_CHAT) and Guild remain. Existing canSendCritsToSay saved-vars are silently ignored.

 Changed:

 Social broadcast is now Questie-style: one group-context channel plus an optional guild simulcast. In a battleground sends INSTANCE_CHAT, in a raid sends RAID or INSTANCE_CHAT-for-LFR, in a party sends PARTY or INSTANCE_CHAT-for-LFG. Guild is added when toggled. No more SAY + GUILD + PARTY all at once.

 Versioning:

 Going forward CritMatic follows strict semver. The setting removal drives the MAJOR bump from 5.5.11 to 6.0.0.


[v5.5.11-release] - 05/09/2026

 Fixed:

 Crit Log window now remembers the size you resized it to across /reload and relog. The saved width/height was being clobbered on every show by a hardcoded SetSize; now it falls back to the same defaults as the rest of the restore path.

 Right-click "Open Changelog" on the CritMatic icon now actually opens the changelog. The menu was calling a function name that didn't exist (capital S typo), so the item was silently dead. Fixed.

 Changed:

 This popup now shows only the latest 3 releases plus a pointer to the full CHANGE_LOG.md on GitHub or CurseForge. Going forward each release prepends here and drops the oldest, so the popup never grows past 3 versions of bullets.


For the full version history see CHANGE_LOG.md on GitHub or CurseForge.

]]

    local r, g, b = unpack(Critmatic.db.profile.changeLogPopUp.fontSettings.fontColor)
    -- Fetch the custom font from SharedMedia
    local customFont = LSM:Fetch("font", Critmatic.db.profile.changeLogPopUp.fontSettings.font)
    local logLabel = AceGUI:Create("Label")
    logLabel:SetText(changelog)
    logLabel:SetFullWidth(true)

    logLabel:SetFont(customFont, Critmatic.db.profile.changeLogPopUp.fontSettings.fontSize, Critmatic.db.profile.changeLogPopUp.fontSettings.fontOutline)
    logLabel:SetColor(r, g, b)

    scroll:AddChild(logLabel)

end

