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.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.


[v5.5.10-release] - 05/08/2026

 Added:

 Buy Me A Coffee link in General settings (optional, copy-only). The General tab now has a Support group with Discord + BMAC, plus a By group showing the author.

 Changed:

 General tab reorganized into Support and By groups. Toggles above are unchanged.

 Localization parity restored across all 11 locales. deDE, esES, esMX, frFR, itIT, koKR, ptBR, ruRU, zhCN, zhTW now translate every option string from v5.5.8 / v5.5.9 / v5.5.10.

 Fixed:

 Send Crits to Say no longer broadcasts inside instances (dungeons, raids, battlegrounds, arenas). Open-world /say is unchanged.

 critFormat / critHealFormat defaults switched from {star} to {rt1} so the gold star icon shows on every locale.

 Updated:

 In-game changelog popup refreshed with all release notes from v5.5.0 through v5.5.10. Going forward this popup is updated as part of every release.


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

