/*
 * The MIT License
 *
 * Copyright 2016 Pawel Marynowski.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package pattypan.panes;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import pattypan.Session;
import pattypan.UploadElement;
import pattypan.elements.WikiPane;

public class CheckPane extends WikiPane {

  Stage stage;
  VBox fileListContainer = new VBox(4);

  public CheckPane(Stage stage) {
    super(stage, 1.34);
    this.stage = stage;

    setContent();
  }

  public WikiPane getContent() {
    return this;
  }

  private WikiPane setContent() {
    addElement("check-intro", 40);

    for (UploadElement ue : Session.FILES_TO_UPLOAD) {
      Hyperlink label = new Hyperlink(ue.getData("name"));
      label.setOnAction(event -> {
        try {
          URI link = new URI("https://commons.wikimedia.org/wiki/Special:ExpandTemplates"
                  + "?wpRemoveComments=true"
                  + "&wpInput=" + URLEncoder.encode(ue.getWikicode(), "UTF-8")
                  + "&wpContextTitle=" + URLEncoder.encode(ue.getData("name"), "UTF-8"));
          Desktop.getDesktop().browse(link);
        } catch (IOException | URISyntaxException ex) {
        }
      });

      fileListContainer.getChildren().add(label);
    }

    addElement(new ScrollPane(fileListContainer));

    prevButton.linkTo("LoadPane", stage);
    nextButton.linkTo("LoginPane", stage);

    return this;
  }
}

@@ -1296,16 +1296,42 @@
 ncoder;%0A
+import javafx.scene.Node;%0A
 import j
@@ -1401,16 +1401,53 @@
 llPane;%0A
+import javafx.scene.layout.Priority;%0A
 import j
@@ -1554,16 +1554,52 @@
 lement;%0A
+import pattypan.elements.WikiLabel;%0A
 import p
@@ -1723,16 +1723,55 @@
 VBox(4);
+%0A  VBox detailsContainer = new VBox(4);
 %0A%0A  publ
@@ -1939,193 +1939,266 @@
 ate 
-WikiPane setContent() %7B%0A    addElement
+void setDetails(UploadElement ue) %7B%0A    %0A    WikiLabel title = new WikiLabel(ue.getData(%22name%22)).setClass
 (%22
-c
 he
-ck-intro%22, 40
+ader%22
 );%0A
-%0A
     
-for (UploadElement ue : Session.FILES_TO_UPLOAD) %7B%0A      Hyperlink label = new Hyperlink(ue.getData(%22name%22)
+Hyperlink preview = new Hyperlink(%22Preview%22);%0A    WikiLabel wikitext = new WikiLabel(ue.getWikicode()).setAlign(%22left%22
 );%0A    
+%0A
   
-label
+  preview
 .set
@@ -2217,18 +2217,16 @@
 nt -%3E %7B%0A
-  
       tr
@@ -2237,18 +2237,16 @@
         
-  
 URI link
@@ -2333,18 +2333,16 @@
         
-  
 + %22?wpRe
@@ -2372,26 +2372,24 @@
             
- 
- 
 + %22&wpInput=
@@ -2437,18 +2437,16 @@
 UTF-8%22)%0A
-  
         
@@ -2525,18 +2525,16 @@
 F-8%22));%0A
-  
         
@@ -2574,18 +2574,16 @@
 ;%0A      
-  
 %7D catch 
@@ -2628,19 +2628,389 @@
 %7B%0A      
-  %7D
+%7D%0A    %7D);%0A%0A    detailsContainer.getChildren().clear();%0A    detailsContainer.getChildren().addAll(title, preview, wikitext);%0A  %7D%0A  %0A  private WikiPane setContent() %7B%0A    addElement(%22check-intro%22, 40);%0A%0A    for (UploadElement ue : Session.FILES_TO_UPLOAD) %7B%0A      Hyperlink label = new Hyperlink(ue.getData(%22name%22));%0A      label.setOnAction(event -%3E %7B%0A        setDetails(ue);
 %0A      %7D
@@ -3008,25 +3008,24 @@
 ;%0A      %7D);%0A
-%0A
       fileLi
@@ -3068,16 +3068,20 @@
 ;%0A    %7D%0A
+    
 %0A    add
@@ -3087,17 +3087,47 @@
 dElement
-(
+Row(10,%0A            new Node%5B%5D%7B
 new Scro
@@ -3151,16 +3151,118 @@
 ntainer)
+, new ScrollPane(detailsContainer)%7D,%0A            new Priority%5B%5D%7BPriority.ALWAYS, Priority.ALWAYS%7D%0A    
 );%0A%0A    

add preview of raw wikicode