package com.axellience.vuegwt.client.vnode.builder;

import com.axellience.vuegwt.client.component.VueComponent;
import com.axellience.vuegwt.client.vnode.VNode;
import com.axellience.vuegwt.client.vnode.VNodeData;
import com.axellience.vuegwt.client.vue.VueJsConstructor;

/**
 * @author Adrien Baron
 */
public class VNodeBuilder
{
    private final CreateElementFunction function;

    public VNodeBuilder(CreateElementFunction function)
    {
        this.function = function;
    }

    /**
     * Create an empty VNode
     * @return a new empty VNode
     */
    public VNode el()
    {
        return this.function.create(null, null, null);
    }

    /**
     * Create a VNode with the given HTML tag
     * @param tag HTML tag for the new VNode
     * @param children Children
     * @return a new VNode of this tag
     */
    public VNode el(String tag, Object... children)
    {
        return this.function.create(tag, children, null);
    }

    /**
     * Create a VNode with the given HTML tag
     * @param tag HTML tag for the new VNode
     * @param data Information for the new VNode (attributes...)
     * @param children Children
     * @return a new VNode of this tag
     */
    public VNode el(String tag, VNodeData data, Object... children)
    {
        return this.function.create(tag, data, children);
    }

    /**
     * Create a VNode with the given Component
     * @param vueJsConstructor Constructor for the Component we want
     * @param children Children
     * @return a new VNode of this Component
     */
    public VNode el(VueJsConstructor<VueComponent> vueJsConstructor, Object... children)
    {
        return this.function.create(vueJsConstructor, children, null);
    }

    /**
     * Create a VNode with the given Component
     * @param vueComponentClass Class for the {@link VueComponent} we want
     * @param data Information for the new VNode (attributes...)
     * @param children Children
     * @return a new VNode of this Component
     */
    public VNode el(Class<VueComponent> vueComponentClass, VNodeData data, Object... children)
    {
        return this.function.create(vueComponentClass, data, children);
    }
}

@@ -46,16 +46,60 @@
 ilder;%0A%0A
+import com.axellience.vuegwt.client.VueGWT;%0A
 import c
@@ -252,16 +252,68 @@
 deData;%0A
+import com.axellience.vuegwt.client.vue.VueFactory;%0A
 import c
@@ -1465,32 +1465,42 @@
  with the given 
+%7B@link Vue
 Component%0A     *
@@ -1484,32 +1484,33 @@
 ink VueComponent
+%7D
 %0A     * @param v
@@ -1515,42 +1515,47 @@
  vue
-JsConstructor Constructor for the 
+ComponentClass Class for the %7B@link Vue
 Comp
@@ -1559,16 +1559,17 @@
 omponent
+%7D
  we want
@@ -1561,32 +1561,97 @@
 ponent%7D we want%0A
+     * @param data Information for the new VNode (attributes...)%0A
      * @param ch
@@ -1739,32 +1739,21 @@
 Node el(
-VueJsConstructor
+Class
 %3CVueComp
@@ -1762,29 +1762,46 @@
 ent%3E vue
-JsConstructor
+ComponentClass, VNodeData data
 , Object
@@ -1839,45 +1839,59 @@
 urn 
-this.function.create(vueJsConstructor
+el(VueGWT.getJsConstructor(vueComponentClass), data
 , ch
@@ -1888,38 +1888,32 @@
 , data, children
-, null
 );%0A    %7D%0A%0A    /*
@@ -1945,21 +1945,120 @@
 ith the 
-given
+%7B@link VueComponent%7D of the given %7B@link VueFactory%7D%0A     * @param vueFactory %7B@link VueFactory%7D for the
  Compone
@@ -2055,24 +2055,32 @@
 he Component
+ we want
 %0A     * @par
@@ -2086,133 +2086,414 @@
 ram 
-vueComponentClass Class for the %7B@link VueComponent%7D we want%0A     * @param data Information for the new VNode (attributes...)
+children Children%0A     * @return a new VNode of this Component%0A     */%0A    public VNode el(VueFactory%3CVueComponent%3E vueFactory, Object... children)%0A    %7B%0A        return el(vueFactory.getJsConstructor(), children, null);%0A    %7D%0A%0A    /**%0A     * Create a VNode with the %7B@link VueComponent%7D of the given %7B@link VueJsConstructor%7D%0A     * @param vueJsConstructor %7B@link VueJsConstructor%7D for the Component we want
 %0A   
@@ -2586,37 +2586,48 @@
 public VNode el(
-Class
+VueJsConstructor
 %3CVueComponent%3E v
@@ -2632,38 +2632,21 @@
  vue
-ComponentClass, VNodeData data
+JsConstructor
 , Ob
@@ -2712,28 +2712,21 @@
 (vue
-ComponentClass, data
+JsConstructor
 , ch
@@ -2723,27 +2723,33 @@
 ructor, children
+, null
 );%0A    %7D%0A%7D%0A

Update VNodeBuilder to support VueFactories