local addonName, TC = ...
TC.Minimap = {}

function TC:SetupMinimap()
    local ldb = LibStub("LibDataBroker-1.1"):NewDataObject("TownCrier", {
        type = "data source",
        text = "TownCrier",
        icon = "Interface\\Icons\\INV_Misc_Bell_01",
        OnClick = function(_, button)
            if button == "RightButton" then
                -- Safety check: Only toggle if the UI module loaded successfully
                if TC.UI and TC.UI.Toggle then
                    TC.UI:Toggle()
                else
                    print("|cFFFF0000TownCrier Error:|r UI Module failed to load. Check for Lua errors!")
                end
            else
                -- Opens standalone Ace3 HowTo window
                LibStub("AceConfigDialog-3.0"):Open("TownCrier")
            end
        end,
        OnTooltipShow = function(tooltip)
            tooltip:AddLine("|cFFFFD100TownCrier|r")
            tooltip:AddLine("Right-Click: |cFFFFFFFFOpen The Ledger|r")
            tooltip:AddLine("Left-Click: |cFFFFFFFFOpen HowTo|r")
        end,
    })
    TC.Minimap.icon = LibStub("LibDBIcon-1.0")
    TC.Minimap.icon:Register("TownCrier", ldb, TC.db.profile.minimap)
end