local PT = AhUI
local L = PT.L
local LDB = LibStub("LibDataBroker-1.1")
local LDBIcon = LibStub("LibDBIcon-1.0")

local broker = LDB:NewDataObject("AhUI", {
    type = "data source",
    text = "AhUI",
    icon = "Interface\\AddOns\\AhUI\\media\\AhUI.tga",

OnClick = function(self, button)
    if button == "LeftButton" then
        if IsShiftKeyDown()
            and PT.FarmTracker
            and PT.FarmTracker.ToggleVisibility
            and (not AhUI_DB or not AhUI_DB.farmTracker or AhUI_DB.farmTracker.config == nil or AhUI_DB.farmTracker.config.minimapShiftOpen ~= false)
        then
            PT.FarmTracker:ToggleVisibility()
            return
        end

        if PT.Settings and PT.Settings.category then
            Settings.OpenToCategory(PT.Settings.category:GetID())
        end

    elseif button == "RightButton" then
        if IsShiftKeyDown() then
            if PT.DisEnchantSuper and PT.DisEnchantSuper.Toggle then
                PT.DisEnchantSuper:Toggle()
            end
        else
            if PT.AccountOverview then
                PT.AccountOverview:Toggle()
            end
        end
    end
end,

OnTooltipShow = function(tt)
    tt:AddLine(L["LDB_TITLE"])
    tt:AddLine(L["LDB_LEFT_CLICK"], 1, 1, 1)
    tt:AddLine(L["LDB_RIGHT_CLICK"], 1, 1, 1)
    tt:AddLine(L["LDB_SHIFT_LEFT_CLICK"] or "Shift + LMB — Farm Tracker", 1, 1, 1)
    tt:AddLine(L["LDB_SHIFT_R_CLICK"] or "Shift + RMB — Disenchant Menu", 1, 1, 1)
end,
})

local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function()
    AhUI_DB = AhUI_DB or {}
    AhUI_DB.minimap = AhUI_DB.minimap or { hide = false }

    LDBIcon:Register("AhUI", broker, AhUI_DB.minimap)
end)
