local ClickMenu, namespace = ...
local L = namespace.L

--Our one and only config option
local MouseButton = "RightButton" --LeftButton, RightButton, MiddleButton

--End config
local menuFrame = CreateFrame("Frame", "BobMinimapRightClickMenu", UIParent, "UIDropDownMenuTemplate")
local menuList = {
    {
			text = "Micromenu",
			isTitle = true,
			notCheckable = true,
	},
    {
        text = "Character",
        icon = 'Interface\\PaperDollInfoFrame\\UI-EquipmentManager-Toggle',
        func = function()
            securecall(ToggleCharacter, 'PaperDollFrame')
        end,
        notCheckable = true,
    },
    {
        text = "Spellbook",
        icon = 'Interface\\MINIMAP\\TRACKING\\Class',
        func = function()
            securecall(ToggleSpellBook, BOOKTYPE_SPELL)
        end,
        notCheckable = true,
    },
    {
        text = "Talents",
        icon = 'Interface\\MINIMAP\\TRACKING\\Ammunition',
        func = function()
            if (not PlayerTalentFrame) then
                LoadAddOn('Blizzard_TalentUI')
            end
            if (not GlyphFrame) then
                LoadAddOn('Blizzard_GlyphUI')
            end
            securecall(ToggleTalentFrame)
        end,
        notCheckable = true,
    },
    {
        text = "Inventory",
        icon = 'Interface\\MINIMAP\\TRACKING\\Banker',
        func = function()
            securecall(ToggleAllBags)
        end,
        notCheckable = true,
    },
    {
        text = "Achievements",
        icon = 'Interface\\ACHIEVEMENTFRAME\\UI-Achievement-Shield',
        func = function()
            securecall(ToggleAchievementFrame)
        end,
        notCheckable = true,
    },
    {
        text = "Quest Log",
        icon = 'Interface\\GossipFrame\\ActiveQuestIcon',
        func = function()
            securecall(ToggleFrame, QuestLogFrame)
        end,
        notCheckable = true,
    },
    {
        text = "Friends",
        icon = 'Interface\\FriendsFrame\\PlusManz-BattleNet',
        func = function()
            securecall(ToggleFriendsFrame, 1)
        end,
        notCheckable = true,
    },
    {
        text = "Guild",
        icon = 'Interface\\GossipFrame\\TabardGossipIcon',
        arg1 = IsInGuild('player'),
        func = function()
            if (IsTrialAccount()) then
                UIErrorsFrame:AddMessage(ERR_RESTRICTED_ACCOUNT, 1, 0, 0)
            else
                securecall(ToggleGuildFrame)
            end
        end,
        notCheckable = true,
    },
    {
        text = "Group Finder",
        icon = 'Interface\\LFGFRAME\\BattleNetWorking0',
        func = function()
            securecall(PVEFrame_ToggleFrame, 'GroupFinderFrame', LFDParentFrame)
        end,
        notCheckable = true,
    },
    {
        text = "Player vs. Player",
        icon = 'Interface\\MINIMAP\\TRACKING\\BattleMaster',
        func = function()
            if (not PVPUIFrame) then
                securecall(PVP_LoadUI)
            end
            securecall(PVPUIFrame_ToggleFrame)
        end,
        notCheckable = true,
    },
    {
        text = "Dungeon Journal     ",
        icon = 'Interface\\MINIMAP\\TRACKING\\Profession',
        func = function()
            securecall(ToggleEncounterJournal)
        end,
        notCheckable = true,
    },
    {
        text = "Mounts",
        icon = 'Interface\\MINIMAP\\TRACKING\\StableMaster',
        func = function()
            securecall(TogglePetJournal, 1)
        end,
        notCheckable = true,
    },
    {
        text = "Pets",
        icon = 'Interface\\MINIMAP\\TRACKING\\StableMaster',
        func = function()
            securecall(TogglePetJournal, 2)
        end,
        notCheckable = true,
    },
    {
        text = CALENDAR,
        icon = 'Interface\\Calendar\\UI-Calendar-Button',
        func = function()
            if (not StoreFrame) then
                LoadAddOn("Blizzard_Calendar")
            end
            securecall(Calendar_Toggle)
        end,
        notCheckable = true,
	},
    {
        text = "Store",
        icon = 'Interface\\MINIMAP\\TRACKING\\BattleMaster',
        func = function()
            if (not StoreFrame) then
                LoadAddOn("Blizzard_StoreUI")
            end
            securecall(ToggleStoreUI)
        end,
        notCheckable = true,
    },
    {
        text = "Support",
        icon = 'Interface\\CHATFRAME\\UI-ChatIcon-Blizz',
        func = function()
            securecall(ToggleHelpFrame)
        end,
        notCheckable = true,
    },
    {
        text = "Zone Map",
        func = function()
            securecall(ToggleBattlefieldMinimap)
        end,
        notCheckable = true,
    },
    {
        text = "Logout",
        func = function()
            Logout()
        end,
        notCheckable = true,
    },
    {
        text = "Quit",
        func = function()
            ForceQuit()
        end,
        notCheckable = true,
    },
}
Minimap:SetScript("OnMouseUp", function(self, button)
	if button == MouseButton then
		securecall(EasyMenu, menuList, menuFrame, self, 5, 100, 'MENU', 3)	-- stays open 3 seconds
	else
		Minimap_OnClick(self)
	end
end)