-- LibDBIcon-1.0: Minimap icon handler stub
local MAJOR, MINOR = "LibDBIcon-1.0", 1
local LibStub = _G.LibStub
local lib = LibStub:NewLibrary(MAJOR, MINOR)
if not lib then return end

lib.icons = lib.icons or {}

function lib:Register(name, dataObject, db)
    db = db or _G
    db = db[name] or {}
    db[name] = db[name] or {}
    if not lib.icons[name] then
        local icon = CreateFrame("Button", name.."MinimapButton", Minimap)
        icon:SetSize(28, 28)
        icon:SetFrameStrata("MEDIUM")
        icon:SetFrameLevel(Minimap:GetFrameLevel() + 1)
        icon:EnableMouse(true)
        icon:RegisterForClicks("LeftButtonUp")
        icon.texture = icon:CreateTexture(nil, "BACKGROUND")
        icon.texture:SetAllPoints(icon)
        icon.texture:SetTexture(dataObject.icon)
        dataObject.OnClick = dataObject.OnClick or function() end
        icon:SetScript("OnClick", dataObject.OnClick)
        icon:Show()
        lib.icons[name] = icon
    end
end

function lib:Show(name)
    local icon = lib.icons[name]
    if icon then icon:Show() end
end

function lib:Hide(name)
    local icon = lib.icons[name]
    if icon then icon:Hide() end
end
