package com.nateyolles.sling.publick.components.foundation;

import javax.script.Bindings;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.scripting.SlingBindings;
import org.apache.sling.scripting.sightly.pojo.Use;

public class Button implements Use {

    private Resource resource;
    private SlingHttpServletRequest request;
    private String cssClass;

    @Override
    public void init(Bindings bindings) {
        resource = (Resource)bindings.get(SlingBindings.RESOURCE);
        request = (SlingHttpServletRequest)bindings.get(SlingBindings.REQUEST);

        ValueMap properties = resource.adaptTo(ValueMap.class);
        String size = properties.get("size", String.class); //large, default, small, extraSmall
        String style = properties.get("style", String.class); //default, primary, success, info, warning, danger, link
        boolean block = properties.get("block", Boolean.class);
        
        StringBuilder css = new StringBuilder("btn");
        
        if (size != null) {
            if (size.equals("large")) {
                css.append(" btn-lg");
            } else if (size.equals("small")) {
                css.append(" btn-sm");
            } else if (size.equals("extraSmall")) {
                css.append(" btn-xs");
            }
        }

        if (block) {
            css.append(" btn-block");
        }

        if (style != null) {
            if (style.equals("primary")) {
                css.append(" btn-primary");
            } else if (style.equals("success")) {
                css.append(" btn-success");
            } else if (style.equals("info")) {
                css.append(" btn-info");
            } else if (style.equals("warning")) {
                css.append(" btn-warning");
            } else if (style.equals("link")) {
                css.append(" btn-lnk");
            } else {
                css.append(" btn-default");
            }
        }

        cssClass = css.toString();
    }

    public String getCssClass() {
        return cssClass;
    }
}
@@ -89,61 +89,8 @@
 s;%0A%0A
-import org.apache.sling.api.SlingHttpServletRequest;%0A
 impo
@@ -289,151 +289,896 @@
 e;%0A%0A
-public class Button implements Use %7B%0A%0A    private Resource resource;%0A    private SlingHttpServletRequest request;%0A    private String cssClass;%0A
+/**%0A * Button backed class for Sightly component.%0A *%0A * The Button component is based on Bootstrap and styled as such.%0A */%0Apublic class Button implements Use %7B%0A%0A    /**%0A     * The current component as a resource.%0A     */%0A    private Resource resource;%0A%0A    /**%0A     * The Bootstrap matched CSS class for the button.%0A     */%0A    private String cssClass;%0A%0A    /**%0A     * Initialization of the component.%0A     * %0A     * Reads the resource, gets the properties and creates the CSS%0A     * for the component.%0A     *%0A     * Options for %22size%22 are:%0A     * %3Cul%3E%0A     * %3Cli%3Elarge%0A     * %3Cli%3Edefault%0A     * %3Cli%3Esmall%0A     * %3Cli%3EextraSmall%0A     * %3C/ul%3E%0A     *%0A     * Options for %22style%22 are:%0A     * %3Cul%3E%0A     * %3Cli%3Edefault%0A     * %3Cli%3Eprimary%0A     * %3Cli%3Esuccess%0A     * %3Cli%3Einfo%0A     * %3Cli%3Ewarning%0A     * %3Cli%3Edanger%0A     * %3Cli%3Elink%0A     * %3C/ul%3E%0A     *%0A     * Options for %22block%22 are true/false.%0A     */
 %0A   
@@ -1300,88 +1300,8 @@
 CE);
-%0A        request = (SlingHttpServletRequest)bindings.get(SlingBindings.REQUEST);
 %0A%0A  
@@ -2699,24 +2699,124 @@
 g();%0A    %7D%0A%0A
+    /**%0A     * Return the button's CSS class.%0A     *%0A     * @return the button's CSS class.%0A     */%0A
     public S

Comment Button component