package net.silentchaos512.gems.lib;

import java.util.Calendar;
import java.util.List;
import java.util.Set;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.common.ForgeHooks;
import net.silentchaos512.gems.SilentGems;
import net.silentchaos512.lib.util.ChatHelper;
import net.silentchaos512.lib.util.PlayerHelper;

public class Greetings {

  public static boolean IS_BETA_BUILD = false;
  public static final String PREFIX = "[Silent's Gems] BETA: ";
  // @formatter:off
  public static final String[] LINES = new String[] {
      // Alpha
//      "Things may change, break, and/or dance to Macarena.",
//      "Catgirls not included. D:",
      "The flowers probably won't kill you.",
//      "That texture count...",
      "Try the donuts!",
      "May contain unintended &cR&6a&ei&an&9b&do&5w&fs!",
      "Shake well and refrigerate after opening.",
//      "May contain crazy people.",
//      "Bunny bowling. No regrets."

      // Beta
//      "Still dancing to Macarena!",
//      "Your free Windows 10 upgrade is ready!",
      "Drowning in [slightly fewer] JSON files...",
      "Download only from CurseForge!",

      // XCompat
      "Rabbit poop coffee!",
      "Now works on Minecraft 1.10.2! Because other modders are SOOO slow to update...",
      "It stares into your soul.",
      "Pot now included... flower pot, that is.",
      "Did you know Chaos Gems are finally back?",
      "Also try Extra Parts!",
      "Your wish has been granted!",
  };
  // @formatter:on

  static List<String> extraMessages = Lists.newArrayList();

  // For the strawpoll, so we don't spam players too much.
  static Set<String> strawpollNotifiedPlayers = Sets.newHashSet();

  /**
   * Adds messages to the player's chat log. Use addExtraMessage to add messages to the list.
   */
  public static void greetPlayer(EntityPlayer player) {

    if (IS_BETA_BUILD)
      doBetaGreeting(player);

    // Strawpoll notification (will stop displaying at the end of the year)
    Calendar cal = Calendar.getInstance();
    boolean strawpollNotExpired = cal.get(Calendar.YEAR) == 2016 && cal.get(Calendar.MONTH) == Calendar.DECEMBER;
    if (strawpollNotExpired && !strawpollNotifiedPlayers.contains(player.getName())) {
      player.sendMessage(ForgeHooks.newChatWithLinks(TextFormatting.DARK_PURPLE
          + "[Silent's Gems]" + TextFormatting.RESET + " Like the current textures? Or would you"
          + " prefer 16x16 textures like vanilla? I'd like to hear your opinions:"
          + " http://www.strawpoll.me/11872834"));
      strawpollNotifiedPlayers.add(player.getName());
    }

    for (String str : extraMessages)
      ChatHelper.sendMessage(player, "[Silent's Gems] " + str);
  }

  /**
   * Random, funny beta greetings. Will be disabled in version 2.1.
   */
  public static void doBetaGreeting(EntityPlayer player) {

    // Reset the random object, because it seems to yield the same value each time. Huh?
    SilentGems.instance.random.setSeed(System.currentTimeMillis());

    String line = LINES[SilentGems.random.nextInt(LINES.length)];
    line = PREFIX + line;
    line = line.replaceAll("&", "\u00a7");
    ChatHelper.sendMessage(player, TextFormatting.RED + line);
  }

  /**
   * Add an additional message to display when the player logs in to a world.
   */
  public static void addExtraMessage(String str) {

    extraMessages.add(str);
  }
}

@@ -535,12 +535,11 @@
 D = 
-fals
+tru
 e;%0A 
@@ -592,19 +592,20 @@
 s Gems%5D 
-BET
+ALPH
 A: %22;%0A  
@@ -680,25 +680,8 @@
 %5D %7B%0A
-      // Alpha%0A//
     
@@ -713,894 +713,35 @@
 ak, 
-and/or dance to Macarena.%22,%0A//      %22Catgirls not included. D:%22,%0A      %22The flowers probably won't kill you.%22,%0A//      %22That texture count...%22,%0A      %22Try the donuts!%22,%0A      %22May contain unintended &cR&6a&ei&an&9b&do&5w&fs!%22,%0A      %22Shake well and refrigerate after opening.%22,%0A//      %22May contain crazy people.%22,%0A//      %22Bunny bowling. No regrets.%22%0A%0A      // Beta%0A//      %22Still dancing to Macarena!%22,%0A//      %22Your free Windows 10 upgrade is ready!%22,%0A      %22Drowning in %5Bslightly fewer%5D JSON files...%22,%0A      %22Download only from CurseForge!%22,%0A%0A      // XCompat%0A      %22Rabbit poop coffee!%22,%0A      %22Now works on Minecraft 1.10.2! Because other modders are SOOO slow to update...%22,%0A      %22It stares into your soul.%22,%0A      %22Pot now included... flower pot, that is.%22,%0A      %22Did you know Chaos Gems are finally back?%22,%0A      %22Also try Extra Parts!%22,%0A      %22Your wish has been granted!%22,
+or spontaneously moonwalk.%22
 %0A  %7D
@@ -1202,51 +1202,27 @@
 on (
-will stop displaying at the end of the year
+new difficulty poll
 )%0A  
@@ -1325,17 +1325,17 @@
 ) == 201
-6
+7
  && cal.
@@ -1354,17 +1354,17 @@
 .MONTH) 
-=
+%3C
 = Calend
@@ -1370,13 +1370,12 @@
 dar.
-DECEM
+OCTO
 BER;
@@ -1598,135 +1598,107 @@
 ESET
- + %22 Like the current textures? Or would you%22%0A          + %22 prefer 16x16 textures like vanilla? I'd like to hear your opinions:
+%0A          + %22 I'm looking for some feedback on difficulty. Your vote would be greatly appreciated!
 %22%0A  
@@ -1738,15 +1738,15 @@
 me/1
-1872834
+3966373
 %22));

Update Greetings module (alpha warning, strawpoll)