package app.GUI;

/**
 * Created by Petr Flégl on 5.3.2017.
 */

import org.primefaces.model.UploadedFile;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import javax.faces.model.SelectItemGroup;
import javax.inject.Named;
import java.util.ArrayList;
import java.util.List;

@Named
@ManagedBean
public class MultiSelectView {

    private List<SelectItem> categories;
    private String selection;

    public String getTable() {
        return table;
    }

    public void setTable(String table) {
        this.table = table;
    }

    public String[] getTables() {
        return tables;
    }

    public void setTables(String[] tables) {
        this.tables = tables;
    }

    private String table;
    private String tables []= {
            "Table1", "Table3", "Table4", "Table5", "Table6", "Table7", "Table8", "Table9", "Table10", "DashboardPanelWidget"
    };

    private UploadedFile file;

    public UploadedFile getFile() {
        return file;
    }

    public void setFile(UploadedFile file) {
        this.file = file;
    }

    @PostConstruct
    public void init() {
        categories = new ArrayList<SelectItem>();
        SelectItemGroup group1 = new SelectItemGroup("Tabulky");
        SelectItemGroup group2 = new SelectItemGroup("Group 2");
        SelectItemGroup group3 = new SelectItemGroup("Group 3");
        SelectItemGroup group4 = new SelectItemGroup("Group 4");

        SelectItemGroup group11 = new SelectItemGroup("Table1");
        SelectItemGroup group12 = new SelectItemGroup("Table3");
        SelectItemGroup group13 = new SelectItemGroup("Table4");
        SelectItemGroup group14 = new SelectItemGroup("Table5");
        SelectItemGroup group15 = new SelectItemGroup("Table6");
        SelectItemGroup group16 = new SelectItemGroup("Table7");
        SelectItemGroup group17 = new SelectItemGroup("Table8");
        SelectItemGroup group18 = new SelectItemGroup("Table9");
        SelectItemGroup group19 = new SelectItemGroup("Table10");
        SelectItemGroup group20 = new SelectItemGroup("DashboardPanelWidget");
        SelectItemGroup group21 = new SelectItemGroup("OilT");
        SelectItemGroup group22 = new SelectItemGroup("ElektroT");
        SelectItemGroup group23 = new SelectItemGroup("ProcesStatusTable");
        SelectItemGroup group24 = new SelectItemGroup("CalendarEvent");

        SelectItemGroup group30 = new SelectItemGroup("Group 2.1");

        SelectItem option31 = new SelectItem("Option 3.1", "Option 3.1");
        SelectItem option32 = new SelectItem("Option 3.2", "Option 3.2");
        SelectItem option33 = new SelectItem("Option 3.3", "Option 3.3");
        SelectItem option34 = new SelectItem("Option 3.4", "Option 3.4");

        SelectItem option41 = new SelectItem("Option 4.1", "Option 4.1");

        SelectItem option211 = new SelectItem("Option 2.1.1", "Option 2.1.1");
        group21.setSelectItems(new SelectItem[]{option211});

        SelectItemGroup tables = new SelectItemGroup("Tabulky");
        tables.setSelectItems(new SelectItem[]{
                new SelectItem("Table1","Tabulka 1"),
                new SelectItem("Table3","Tabulka 3"),
                new SelectItem("Table4","Tabulka 4"),
                new SelectItem("Table5","Tabulka 5"),
                new SelectItem("Table6","Tabulka 6"),
                new SelectItem("Table7","Tabulka 7"),
                new SelectItem("Table8","Tabulka 8"),
                new SelectItem("Table9","Tabulka 9"),
                new SelectItem("Table10", "Tabulka 10"),
                new SelectItem("DashboardPanelWidget", "Tabulka Oken"),
                new SelectItem("OilT", "Tabulka Olej"),
                new SelectItem("ElektroT", "Tabulka El."),
                new SelectItem("ProcesStatusTable", "Tabulka Statusů"),
                new SelectItem("CalendarEvent", "Tabulka událostí"),
        });

        group1.setSelectItems(new SelectItem[]{group11, group12, group13, group14, group15, group16, group17, group18, group19, group20, group21, group22, group23, group24});
        group2.setSelectItems(new SelectItem[]{group30});
        group3.setSelectItems(new SelectItem[]{option31, option32, option33, option34});
        group4.setSelectItems(new SelectItem[]{option41});

      categories.add(tables);
    }

    public List<SelectItem> getCategories() {
        return categories;
    }

    public String getSelection() {

        return selection;
    }
    public void setSelection(String selection) {
        this.selection = selection;
    }

    public void handleChange(ValueChangeEvent e){
        selection=(String)e.getNewValue();
    }
}
