require("scripts/styles/style.lua");
require("scripts/styles/uistyle.lua");
require("scripts/styles/level_selector.lua");

local pageSize = 5;

local pos = {x = 84, y = 325};
local offset = 252; 

local function GetAreaButtonFunction(scenary, area, style, name)
	return function ()
		SelectAreaStyle(scenary, area, style, name);
	end
end

local function CreateStyleButtons(scenaryId, areaId, t --[[, lockLastButton ]])
	local amount = GetNextLevelInScenary(scenaryId);
	local name = scenaryNameMap[scenaryId];

	for i = 1, 3 do
	
		table.insert(t,
			BlgButton{
				name = "btn_"..scenaryId.."_"..areaId.."_"..i,
				transformMatrix = {x = pos.x + (offset * (i - 1)), y = pos.y, },
				--sound = "audio/FX/cp_activity_ready.ogg",
				sound = kDefaultButtonSound,
				upState = {
					bitmap = "common/buttons/level_selector/".. name .."/btn"..areaId.."/style"..i.."_preview",
				},
				overState = {
					bitmap = "common/buttons/level_selector/".. name .."/btn"..areaId.."/style"..i.."_preview_over",
				},
				downState = {
					bitmap = "common/buttons/level_selector/".. name .."/btn"..areaId.."/style"..i.."_preview",
				},
				command = GetAreaButtonFunction(scenaryId, areaId, i, name),
			}
		);
			
	end

	return t;
end

local function CreateButtons()
	local t = {};
	
	CreateStyleButtons(gScenary, gArea, t);
	
	return Group(t);
end

MakeDisplayHierarchy{
	autoPlay = true,
	enabled = false,
	
	BlgContainer
	{
		transformMatrix = {x = 0, y = 0},
		animation = {
			keyframes = {
				{
					index = 0,
					y = -800,
					tweens = {
						{
							type = "FunctionEase",
							target = TWEEN_ALL,
							functionName = "Back",
							easingMethod = "easeOut",
						},
					},
				},
				{
					index = 30,
					y = 0,
					tweens = {
						{
							type = "FunctionEase",
							target = TWEEN_ALL,
							functionName = "Back",
							easingMethod = "easeIn",
						},
					},
				},
				{
					index = 60,
					y = -800,
				},
			},
		},
		
		BlgBitmap {
			image = "common/buttons/level_selector/popups/reb_bg",
			center = {x = 0, y = 0},
			transformMatrix = {x = 27, y = 180},
		},
		
		BlgBitmap {
			image = "common/buttons/level_selector/popups/ls_caption",
			center = {x = 0, y = 0},
			transformMatrix = {x = 295, y = 180},
		},
		
		BlgBitmap {
			image = "common/buttons/level_selector/popups/deco_seahorse",
			center = {x = 0, y = 0},
			transformMatrix = {x = 240, y = 150},
		},
		
		BlgBitmap {
			image = "common/buttons/level_selector/popups/ls_rebuild",
			center = {x = 0, y = 0},
			transformMatrix = {x = 330, y = 180},
		},
		
		SetStyle(LevelSelectorButtonStyle),
		BlgButton{
			name = "backBtn",
			transformMatrix = {x = 64, y = 509},
			label = "back",
			
		 	upState =
		 	{
		 		bitmap = "common/buttons/btn_default",
		 	},
		 	overState = {
		 		bitmap = "common/buttons/btn_rollover",
		 	},
			downState = {
		 		bitmap = "common/buttons/btn_pushed",
		 		sound = kDefaultButtonSound,
		 	},
			
			command =
				function()
					CloseScenary();
				end
		},
		
		BlgText {
			name = "styleTitle",
			transformMatrix = {x = 243, y = 204},
			w = 203, h = 39,
			flags = kVAlignCenter + kHAlignRight,
			label = "Area_Style_Buttons_Rebuild",
			font = {
				standardFont,
				24,
				Color(184, 42, 152),
			},
		},
		
		SetStyle(nil),
		BlgText {
			name = "styleText",
			transformMatrix = {x = 490, y = 202},
			w = 203, h = 39,
			flags = kVAlignCenter + kHAlignLeft,
			label = "Area_Style_Buttons_Choose_A_Style",
			font = {
				standardFont,
				34,
				Color(184, 42, 152),
			},
		},
		
		BlgMovieClip {
			name = "buttonContainer",
			CreateButtons();
		},
		
	},
}

