package chylex.javacheck.report;
import java.util.Map;
import javax.swing.JOptionPane;
import net.minecraftforge.fml.relauncher.FMLRelaunchLog;
import net.minecraftforge.fml.relauncher.IFMLCallHook;
import org.apache.commons.lang3.JavaVersion;
import org.apache.commons.lang3.SystemUtils;

public final class JavaCheckerReporter implements IFMLCallHook{
	public static JavaVersion minVersion = null;
	
	@Override
	public Void call() throws Exception{
		if (!SystemUtils.isJavaVersionAtLeast(minVersion)){
			FMLRelaunchLog.severe(getConsoleReport());
			JOptionPane.showMessageDialog(null, "<html>"+getWindowReport()+"</html>","Outdated Java",JOptionPane.ERROR_MESSAGE);
            		throw new OutdatedJavaException();
		}
		
		return null;
	}

	@Override
	public void injectData(Map<String,Object> data){}
	
	static String getConsoleReport(){
		return new StringBuilder(242).append("\n")
		.append("\n!! DO NOT REPORT !!\n\n")
		.append("Pixelmon requires Java "+minVersion.toString()+" or newer, you are using ").append(SystemUtils.JAVA_VERSION).append(".\n")
		.append("If you are running Windows you can\n")
		.append("visit https://java.com/download/ for the latest version.\n")
		.append("Please, uninstall the old version first to prevent further issues.")
		.append("\n")
		.append("If you are running OSX Lion (10.7) or newer, Please use the following launcher\n")
		.append("http://launcher.mojang.com/download/Minecraft-staging.dmg")
		.append("\n\n!! DO NOT REPORT !!\n")
		.toString();
	}
	
	static String getWindowReport(){
		return new StringBuilder(230)
		.append("Pixelmon requires Java "+minVersion.toString()+" or newer, you are using ").append(SystemUtils.JAVA_VERSION).append(".<br>")
		.append("If you are running Windows you can<br>")
		.append("visit <span style=\"color:red\">https://java.com/download/</span> for the latest version.<br>")
		.append("Please, uninstall the old version first to prevent further issues.")
		.append("<br>")
		.append("If you are running OSX Lion (10.7) or newer, Please use the following launcher<br>")
		.append("<span style=\"color:red\">http://launcher.mojang.com/download/Minecraft-staging.dmg</span>")
		.toString();
	}
}

@@ -30,62 +30,8 @@
 rt;%0A
-import java.util.Map;%0Aimport javax.swing.JOptionPane;%0A
 impo
@@ -83,16 +83,16 @@
 nchLog;%0A
+
 import n
@@ -227,16 +227,168 @@
 emUtils;
+%0Aimport org.lwjgl.Sys;%0A%0Aimport javax.swing.*;%0Aimport javax.swing.event.HyperlinkEvent;%0Aimport javax.swing.event.HyperlinkListener;%0Aimport java.util.Map;
 %0A%0Apublic
@@ -646,84 +646,417 @@
 ));%0A
+%0A
 %09%09%09J
-OptionPane.showMessageDialog(null, %22%3Chtml%3E%22+getWindowReport()+%22%3C/html%3E%22,
+EditorPane ep = new JEditorPane(%22text/html%22, %22%3Chtml%3E%22+getWindowReport()+%22%3C/html%3E%22);%0A%09%09%09ep.addHyperlinkListener(new HyperlinkListener()%0A%09%09%09%7B%0A%09%09%09%09@Override%0A%09%09%09%09public void hyperlinkUpdate(HyperlinkEvent e)%0A%09%09%09%09%7B%0A%09%09%09%09%09if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))%0A%09%09%09%09%09%09Sys.openURL(e.getURL().toString());%0A%09%09%09%09%7D%0A%09%09%09%7D);%0A%09%09%09ep.setEditable(false);%0A%09%09%09JOptionPane.showMessageDialog(null, ep, 
 %22Out
@@ -1067,16 +1067,17 @@
 d Java%22,
+ 
 JOptionP
@@ -1100,20 +1100,10 @@
 E);%0A
-            
+%0A%09
 %09%09th
@@ -1291,11 +1291,8 @@
 der(
-242
 ).ap
@@ -1982,11 +1982,8 @@
 der(
-230
 )%0A%09%09
@@ -2207,24 +2207,62 @@
 color:red%5C%22%3E
+%3Ca href=%5C%22https://java.com/download%5C%22%3E
 https://java
@@ -2277,16 +2277,20 @@
 nload/%3C/
+a%3E%3C/
 span%3E fo
@@ -2544,24 +2544,34 @@
 color:red%5C%22%3E
+%3Ca href=%5C%22
 http://launc
@@ -2615,16 +2615,80 @@
 ging.dmg
+%5C%22%3Ehttp://launcher.mojang.com/download/Minecraft-staging.dmg%3C/a%3E
 %3C/span%3E%22

make links clickable