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.filename_to_upload: a local filename of the image that will be uploaded
--		eg 'user:screenshot.jpg'
--		This string is non user-visible and must match the filename generated by code
--		ie in CreateScreenshot or CreateAvatarPhoto
--
-- stream.ingametitle: the above-divider title of the dialog UI
--		eg 'Post a screenshot'
--
-- stream.defaultusertext: the starter-prompt that a user will type over to 
--		caption their photo for upload.
--		eg 'I've crash landed in Wandering Willows'.
--		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.
-- 
-------------------------------------------------

MakeDialog
{
	name='facebook_asktopost', 
	Bitmap
	{
		name = 'fb_screenshot_bg_box',
		image="facebook/common/fb_screenshot_bg_box",
		x=kCenter,
		y=kCenter,
		Window
		{
			name = 'above_divider',
			x = 2,
			y = 2,
			w = kMax - 2,
			h = 57,
			Text
			{
				name = 'dialog_title',
				font = FacebookTitleFont,
				x = 32,
				y = 10,
				w = kMax - 10,
				h = kMax,
				label = '#'..facebookstream.ingametitle
				-- label = 'Post a screenshot to your Facebook photo album'
			},
		},
		
		Window
		{
			name = 'below_divider',
			x = 2,
			y = 60,
			h = kMax - 2,
			w = kMax - 2,

			FBBitmap
			{
				x = 53,
				y = 10,
				w = 200,
				h = 150,
				name = 'screenshot',
				image = facebookstream.filename_to_upload,
			},

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

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

			},

			SetStyle(FacebookPostButtonStyle),
			FBButton
			{
				name = 'facebook_btn_post',
				x = (18 - 4),
				y = kMax - (12 - 4),
				align = kVAlignBottom,
				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_dopostphoto(msg, facebookstream, false)) then
							ModalReturn(true);
							PopModal('facebook_asktopost');
						else
							-- It failed, let them try again if they want
							FB_Unhideaway(ww);
						end
					end;
	            label =	'facebook_btn_postphoto',
				-- label = "Post to Facebook",
			},

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

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