local _, addon = ...
local HLY = addon.HLY

local dbicon = LibStub("LibDBIcon-1.0")

local dataObject = LibStub("LibDataBroker-1.1"):NewDataObject("HLYqol", {
    type    = "launcher",
    icon    = addon.iconPath,
    OnClick = function(_, mouseButton)
        if mouseButton == "RightButton" then
            HLY.db.minimap.hide = true
            dbicon:Refresh("HLYqol")
            return
        end
        HLY:OpenOptions()
    end,
    OnTooltipShow = function(tooltip)
        tooltip:SetText(addon.displayName)
        tooltip:AddLine("Left Click: Open options", 1, 1, 1)
        tooltip:AddLine("Right Click: Hide button", 1, 1, 1)
    end,
})

function HLY:UpdateMinimapButton()
    if not self.db or not self.db.minimap then return end
    dbicon:Refresh("HLYqol", self.db.minimap)
end

function HLY:SetupMinimapButton()
    if not self.db or not self.db.minimap then return end
    if dbicon:IsRegistered("HLYqol") then
        self:UpdateMinimapButton()
        return
    end
    dbicon:Register("HLYqol", dataObject, self.db.minimap)
end
