local esc = minetest.formspec_escape

local page_1 = "Welcome! Thanks for trying out this Among Us clone/rip-off.\n"..
   "This short tutorial should help you get on your feet, and prepare you for what lies ahead. "..
   "If you've never played Among Us, or know nothing about the game you'll want to read this page, "..
   "otherwise feel free to skip ahead to the next page.\n\n"..
   "In this game you play with a team of others, one member of the team is a traitor/imposter. "..
   "The traitor tries to kill all the other players without being outted as the traitor, "..
   "the other team members complete tasks and try to raise XP to defeat the traitor.\n"..
   "The team wins by voting out the traitor, or earning enough XP. Different levels have different player requirements, and XP goals."

local page_2 = "Tasks\n"..
   "There are a wide variety of tasks, different tasks can give different amounts of XP. "..
   "Map makers are able to set their own XP requirements, but don't worry, every time you earn XP "..
   "you'll get a helpful chat message telling you how much more XP you need to defeat the traitor.\n"..
   "Some tasks require you to get a replacement part, click a button, enter a code, or even just punch the node. "..
   "We won't get into detail about every task here, because there are more being added all the time, and you'll "..
   "have an oppertunity to try some different tasks out upon completing this short corse."

local page_3 = "Voting\n"..
   "Voting is one way to try and defeat the traitor. When a corpse is reported all players on a level will teleport "..
   "to that level's spawn location, and have a chance to discuss who they think the traitor is, and then vote. "..
   "A vote can also by triggered by using the 'Emergency Meeting' (usually located near the level's spawn point)\n"..
   "You vote using the /kick command. You can only vote for players on the level."..
   "If you kick yourself you'll be immediately put back into the main lobby."

lobby_help_1 =
   'formspec_version[3]'..
   'size[11,7]'..
   'bgcolor[#00000000;false]'..
   'background9[0,0;11,7;lobby_help_bg.png;true;16]'..
   'textarea[0.5,0.5;10.5,5;;;'..esc(page_1)..']'..
   'button[7.5,5;2.5,1;page_2;Next]'..
   'button_exit[4,5;3,1;exit;Exit]'

lobby_help_2 =
   'formspec_version[3]'..
   'size[11,7]'..
   'bgcolor[#00000000;false]'..
   'background9[0,0;11,7;lobby_help_bg.png;false;16]'..
   'textarea[0.5,0.5;10.5,5;;;'..esc(page_2)..']'..
   'button[7.5,5;2.5,1;page_3;Next]'..
   'button[1,5;2.5,1;page_1;Previous]'..
   'button_exit[4,5;3,1;exit;Exit]'

lobby_help_3 =
   'formspec_version[3]'..
   'size[11,7]'..
   'bgcolor[#00000000;false]'..
   'background9[0,0;11,7;lobby_help_bg.png;false;16]'..
   'textarea[0.5,0.5;10.5,5;;;'..esc(page_3)..']'..
   'button[1,5;2.5,1;page_2;Previous]'..
   'button_exit[4,5;3,1;proceed;Let\'s Go!]'

minetest.register_on_player_receive_fields(function(player, formname, fields)
   local name = player:get_player_name()
   if formname == 'lobby:help_1' then
      if fields.page_2 then
         minetest.show_formspec(name, 'lobby:help_2', lobby_help_2)
      end
   elseif formname == 'lobby:help_2' then
      if fields.page_1 then
         minetest.show_formspec(name, 'lobby:help_1', lobby_help_1)
      elseif fields.page_3 then
         minetest.show_formspec(name, 'lobby:help_3', lobby_help_3)
      end
   elseif formname == 'lobby:help_3' then
      if fields.page_2 then
         minetest.show_formspec(name, 'lobby:help_2', lobby_help_2)
      elseif fields.proceed then
         local privs = minetest.get_player_privs(name)
         privs.pro_player = true
         minetest.set_player_privs(name, privs)
         minetest.chat_send_player(name, 'Swell, enjoy the game, and please report any bugs to minetest@nathansalapat.com')
      end
   end
end)

function lobby.voting_formspec(survivors)
   local formspec =
   'size[12,7]'..
   'no_prepend[]'..
   'bgcolor[#080808BB;true]'..
   'textarea[1,1.5;11,6;;;Who dun it? make your pick. These players are on this map:'..
   '\n'..survivors..
   '\nYou can see the list of survivors at any time by using the /survivors command.'..
   '\nVote to kick the traitor with /kick <playername>, use /skip to skip voting.]'..
   'button_exit[4.5,5;3,1;go;Discuss]'
   return formspec
end

local text_body = [[
   Welcome to the exciting world of level building! You are only limited by your imagination, and to some degree the nodes available. (Send a message to Admin with any requests.)

   There are a few things you should know, they'll make your building experiences better/faster.

   When you claim a button it will be given a random map location, and a platform will be placed there. If you want to enter a different location you can, but no new platform will be placed. Starting out as a new builder you won't have worldedit, so you'll need to use the /placeblock chat command. This chat command will place a single block at your feet.

   Protect your area(s). Any builders can visit your level once you have it linked to a button, and could place/remove nodes if you don't protect the area. Use  /area_pos1 and /area_pos2 in alternate corners. You can always add extra areas or make a new larger area if need be.

   After you've built a little something send Admin an letter in the mailbox located outside of the post office and request worldedit, be sure and send some coordinates for your level. You'll likely be granted the privileges within several days.

   You view this information at any time by using the /level_help chat command.
]]

lobby.getting_started =
   'formspec_version[3]'..
   'size[12,10]'..
   'textarea[.5,.5;11,8;;;'..text_body..']'..
   'button_exit[4,9;4,1;close;Close This Dialog]'
