--[[
	Slash
		This is the slash command handler for Bagnon
--]]

function BagnonSlash_Load()
	SlashCmdList["BagnonCOMMAND"] = BagnonSlash;
	SLASH_BagnonCOMMAND1 = "/bagnon";
	SLASH_BagnonCOMMAND2 = "/bgn";
end

function BagnonSlash(msg)
	local msg = string.lower(msg);
	if(msg == "" or msg == BAGNON_COMMAND_HELP) then
		BagnonSlash_DisplayHelp();
	elseif(msg == BAGNON_COMMAND_SHOWBANK) then
		BagnonCore_Toggle("Banknon");
	elseif(msg == BAGNON_COMMAND_SHOWBAGS) then
		BagnonCore_Toggle("Bagnon");
	elseif(msg == BAGNON_COMMAND_REVERSE) then
		BagnonSlash_ReverseOrder();
	end
end

function BagnonSlash_DisplayHelp()
	BagnonMsg(BAGNON_HELP_TITLE);
	BagnonMsg(BAGNON_HELP_HELP);
	BagnonMsg(BAGNON_HELP_SHOWBAGS);
	BagnonMsg(BAGNON_HELP_SHOWBANK);
	BagnonMsg(BAGNON_HELP_REVERSE);
end

function BagnonSlash_ReverseOrder()
	if(BagnonSets.reverseOrder == nil) then
		BagnonSets.reverseOrder = 1;
		BagnonMsg(BAGNON_REVERSE_ENABLED);
	else
		BagnonSets.reverseOrder = nil;
		BagnonMsg(BAGNON_REVERSE_DISABLED);
	end

	BagnonCore_OrderBags(Bagnon, BagnonSets.reverseOrder);
	BagnonCore_OrderBags(Banknon, BagnonSets.reverseOrder);

	if(Bagnon and Bagnon:IsShown()) then
		BagnonCore_GenerateFrame(Bagnon);
	end

	if(Banknon and Banknon:IsShown()) then
		BagnonCore_GenerateFrame(Banknon);
	end
end