local f0_local0 = module
local f0_local1, f0_local2 = ...
f0_local0( f0_local1, package.seeall )
CoD.PrintModuleLoad( _NAME )
function ChooseStandardGameModeMenu( f1_arg0, f1_arg1 )
	LUI.FlowManager.RequestAddMenu( f1_arg0, "settings_recipe_choosetype", true, f1_arg1.controller, false, {
		requestedGameMode = "Standard",
		menu_title = Cac.GetGameModeTypeString( "Standard" ),
		teamsOnly = SvS.IsSvS()
	} )
end

function ChooseAlternateGameModeMenu( f2_arg0, f2_arg1 )
	LUI.FlowManager.RequestAddMenu( f2_arg0, "settings_recipe_choosetype", true, f2_arg1.controller, false, {
		requestedGameMode = "Alternate",
		menu_title = Cac.GetGameModeTypeString( "Alternate" ),
		teamsOnly = SvS.IsSvS()
	} )
end

function ChooseRecentModeMenu( f3_arg0, f3_arg1 )
	MatchRules.OpenSelectionMenu( f3_arg1.controller, {
		savedMode = "history",
		menu_title = Engine.Localize( "@LUA_MENU_RECENT_MODES" ),
		teamsOnly = SvS.IsSvS()
	} )
end

function ChooseMyModeMenu( f4_arg0, f4_arg1 )
	MatchRules.OpenSelectionMenu( f4_arg1.controller, {
		savedMode = "save",
		menuAction = "load",
		menu_title = Engine.Localize( "@LUA_MENU_MY_MODES" ),
		teamsOnly = SvS.IsSvS()
	} )
end

function CountModesForCategory( f5_arg0, f5_arg1 )
	local f5_local0 = Cac.GetGameModeList( f5_arg0 )
	local f5_local1 = 0
	for f5_local6, f5_local7 in ipairs( f5_local0 ) do
		local f5_local5 = true
		if f5_arg1 then
			f5_local5 = Engine.TableLookup( GameTypesTable.File, GameTypesTable.Cols.Ref, f5_local7, GameTypesTable.Cols.TeamChoice ) == "1"
		end
		if f5_local5 then
			f5_local1 = f5_local1 + 1
		end
	end
	return f5_local1
end

function GameModeFeeder( f6_arg0 )
	local f6_local0 = nil
	local f6_local1 = LUI.Alignment.Right
	f6_local0 = {}
	local f6_local2 = SvS.IsSvS()
	if CountModesForCategory( "Standard", f6_local2 ) > 0 then
		f6_local0[#f6_local0 + 1] = {
			type = "UIGenericButton",
			id = "standard_modes_id",
			properties = {
				button_text = Engine.Localize( "@LUA_MENU_STANDARD_MODES" ),
				button_action_func = ChooseStandardGameModeMenu
			}
		}
	end
	if CountModesForCategory( "Alternate", f6_local2 ) > 0 then
		f6_local0[#f6_local0 + 1] = {
			type = "UIGenericButton",
			id = "alternate_modes_id",
			properties = {
				button_text = Engine.Localize( "@LUA_MENU_ALTERNATE_MODES" ),
				button_action_func = ChooseAlternateGameModeMenu
			}
		}
	end
	if not SvS.IsSvS() then
		f6_local0[#f6_local0 + 1] = {
			type = "UIGenericButton",
			id = "recent_modes_id",
			properties = {
				button_text = Engine.Localize( "@LUA_MENU_RECENT_MODES" ),
				button_action_func = ChooseRecentModeMenu
			}
		}
	end
	if not SvS.IsSvS() then
		f6_local0[#f6_local0 + 1] = {
			type = "UIGenericButton",
			id = "my_modes_id",
			properties = {
				button_text = Engine.Localize( "@LUA_MENU_MY_MODES" ),
				button_action_func = ChooseMyModeMenu
			}
		}
	end
	return f6_local0
end

function OnMenuCreate( f7_arg0, f7_arg1 )
	f7_arg0:processEvent( LUI.ButtonHelperText.CommonEvents.addBackButton )
end

function popup_recipesetup_modes()
	return {
		type = "UIElement",
		id = "popup_recipesetup_modes_root",
		states = {
			default = {
				topAnchor = true,
				bottomAnchor = true,
				leftAnchor = true,
				rightAnchor = true,
				top = 0,
				bottom = 0,
				left = 0,
				right = 0
			}
		},
		handlers = {
			menu_create = OnMenuCreate
		},
		properties = {},
		children = {
			{
				type = "generic_menu_title",
				id = "popup_recipesetup_modes_title_text_id",
				properties = {
					menu_title = Engine.Localize( "@LUA_MENU_MODE_CAPS" )
				}
			},
			{
				type = "xboxlive_options_vlist",
				id = "popup_recipesetup_modes_vlist_id",
				childrenFeeder = GameModeFeeder
			},
			{
				type = "generic_back_button"
			},
			{
				type = "button_helper_text_main",
				id = "button_helper_text_id"
			},
			{
				type = "online_friends_widget",
				id = "online_friends_widget_id"
			}
		}
	}
end

function popup_recipesetup_modes_vlist()
	return {
		type = "UIVerticalList",
		states = {
			default = {
				alignment = LUI.Alignment.Top,
				leftAnchor = true,
				rightAnchor = false,
				topAnchor = true,
				bottomAnchor = false,
				left = GenericMenuDims.menu_left,
				right = GenericMenuDims.menu_right,
				top = GenericMenuDims.menu_top,
				bottom = GenericMenuDims.menu_bottom
			}
		}
	}
end

LUI.MenuBuilder.registerDef( "popup_recipesetup_modes", popup_recipesetup_modes )
LUI.MenuBuilder.registerDef( "popup_recipesetup_modes_vlist", popup_recipesetup_modes_vlist )
LockTable( _M )