require( "facebook/common/style.lua" );
dofile( "facebook/common/facebook_functions.lua" );

-- acquire the effective facebook stream [combining defaults, stream, and overrides]
local facebookstream = facebook_getstream(gDialogTable.stream, gDialogTable.overrides);

-- dump it if there's a dump function
if DumpTable then DumpTable(facebookstream); end;

-------------------------------------------------
-- STREAM MEMBERS THAT MEAN SOMETHING TO THIS DLG			
--
-- stream.ingametitle: the above-divider body message of the dialog UI
--		eg 'You've gotten a nice score!
--
-- stream.defaultusertext: the starter-prompt that a user will type over to 
--		caption their photo for upload.
--		eg I've made a new top score!
--		This string will appear in the dialog, and after editing will appear in the
--		facebook post.
-- 
-- stream.clearcaption: a flag to prevent users from posting the defaultusertext.
--		If true, posts that weren't edited will have a blank caption rather than 
--		the default caption.
-- 
-- stream.game_mode: a string that represents what mode you're playing in
--		eg "story mode", "endless mode"
-- 
-- stream.level:	 a string that represents what level you're playing
--		eg "Level 8 (expert)"
-- 
-- stream.score:	a string that represents what score you've achieved (locally)
--		eg '1500'
--
-- stream.total_story_mode: a string that names an aggregate score
--		eg 'total story mode'
--
-- stream.total_score:	a string that represents an aggregate score
--		eg '27,000'
--
-------------------------------------------------

MakeDialog
{
	name = 'facebook_asktopost',
	Bitmap
	{
		name = 'fb_score_bg_box',
		image="facebook/common/fb_score_bg_box",
		x=kCenter,
		y=kCenter,
		Window
		{
			name = 'above_divider',
			x = 2,
			y = 2,
			w = kMax - 2,
			h = 60,
			Text
			{
				name = 'dialog_title',
				font = FacebookTitleFont,
				x = 32,
				y = 10,
				w = kMax - 10,
				h = kMax,
				label = '#'..facebookstream.ingametitle,
				-- label = 'Nice score! Definitely worth bragging rights!',
			},
		},
		Window
		{
			name = 'below_divider',
			x = 2,
			y = 63,
			h = kMax - 2,
			w = kMax - 2,

			Window
			{
				name = 'story_mode_line',
				x = 12,
				y = 8,
				w = kMax - 12,
				h = 30,

				Text
				{
					font = FacebookBodyFont,
					name = 'game_mode',
					label = '#'..facebookstream.game_mode, -- "Story Mode"
					x = 0,
					y = 0,
					w = kMax,
					h = kMax,
				},

				Text
				{
					font = FacebookDetailFont,
					name = 'level',
					label = '#'..facebookstream.level,	-- "Level 8 (expert)",
					x = 157 - 12,
					y = 0,
					w = kMax,
					h = kMax,
				},

				Text
				{
					font = FacebookBodyFont,
					name = 'game score',
					label = '#'..facebookstream.score,	-- "1500",
					x = kMax,
					y = 0,
					w = 150,
					h = 20,
					flags = kHAlignRight,
					align = kHAlignRight,
				},
			},

			Window
			{
				name = 'total_mode_line',
				x = 12,
				w = kMax - 12,
				h = 30,
				y = 30,

				Text
				{
					font = FacebookBodyFont,
					name = 'total_game_mode',
					label = '#'..facebookstream.total_story_mode,	-- "Total Story Mode",
					x = 0,
					y = 0,
					w = kMax,
					h = kMax,
				},

				Text
				{
					font = FacebookBodyFont,
					name = 'total score',
					label = '#'..facebookstream.total_score, -- "215,195",
					x = kMax,
					y = 0,
					w = kMax,
					h = kMax,
					flags = kHAlignRight,
					align = kHAlignRight,
				},
			},

			Window
			{
				name = 'text_entry_window',
				x = 10,
				y = 51,
				w = kMax - 10,
				h = 48,

				FBTextEdit
				{
					-- enablewindow = 'facebook_btn_post',
					font = FacebookEditFont,
					x = 13,
					y = 10,
					w = kMax - 13,
					h = kMax - 10,
					length = 255,
					name = 'facebook_textedit',
					clearinitial = true,
					label = facebookstream.defaultusertext,	-- 'Text entered inside a textarea field looks like this.\nText is 12 pixels, regular weight.',
				};
			},

			SetStyle(FacebookPostButtonStyle),
			FBButton
			{
				name = 'facebook_btn_post',
				x = 13,
				y = kMax - 10,
				align = kVAlignBottom,
				label = 'facebook_btn_poststream',	-- Post to Facebook
				default = true,
				command=
					function()
						local msg = GetLabel("facebook_textedit");
						if (facebookstream.clearcaption == true and msg == facebookstream.defaultusertext) then
							msg = '';
						end
						
						local ww = FB_Hideaway();						
						if (facebook_dopoststream(msg, facebookstream, false)) then
							PopModal('facebook_asktopost');
							ModalReturn(true);
						else
							FB_Unhideaway(ww);
							-- It failed, let them try again if they want
						end
					end;
			},

			SetStyle(FacebookNoThanksButtonStyle),
			FBButton
			{
				name = 'nothanks',
				x = kMax - 13,
				y = kMax - 10,
				align = kVAlignBottom + kHAlignRight,
				cancel = true,
				close = true,
				command = function() ModalReturn(false); end;
				label = 'facebook_btn_nothanks',
			},
		},
	},
};

SetFocus( "facebook_textedit" );
FB_SetState("++FBScorePostPrompts");
FB_SetState("++FBPostFormShown");
