local PURPLE = "|cff9212d5"
local RESET = "|r"

local function say(msg)
    DEFAULT_CHAT_FRAME:AddMessage(PURPLE .. "LibMatic" .. RESET .. ": " .. tostring(msg))
end

local function testIconPicker()
    local picker = LibStub("LibMatic-IconPicker-1.0", true)
    if not picker then
        say("IconPicker library not loaded")
        return
    end
    say("opening IconPicker...")
    picker:Open(nil, function(chosen)
        if chosen then
            say("picked fileID " .. tostring(chosen))
        else
            say("cancelled")
        end
    end)
end

local function testChangeLog()
    local changelog = LibStub("LibMatic-ChangeLog-1.0", true)
    if not changelog then
        say("ChangeLog library not loaded")
        return
    end
    say("opening ChangeLog sample...")
    changelog:Show({
        title = "LibMatic - Change Log",
        statusText = "Sample changelog for /libmatictest changelog",
        version = "1.0.0",
        footer = "For the full version history see CurseForge.",
        entries = {
            {
                version = "1.0.0",
                date = "05/21/2026",
                sections = {
                    { label = "Added", body = "Sample change log entry rendered by LibMatic-ChangeLog-1.0. Scroll to confirm the popup, version header, section label, and body all render." },
                },
            },
        },
    })
end

SLASH_LIBMATICTEST1 = "/libmatictest"
SLASH_LIBMATICTEST2 = "/lmt"
SlashCmdList["LIBMATICTEST"] = function(msg)
    local cmd = (msg or ""):lower():match("^(%S*)")
    if cmd == "changelog" then
        testChangeLog()
    else
        testIconPicker()
    end
end
