package org.fit.vutbr.relaxdms.web.documents.tabs;

import org.fit.vutbr.relaxdms.web.documents.tabs.workflow.DocumentWorkflow;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.wicket.extensions.ajax.markup.html.tabs.AjaxTabbedPanel;
import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
import org.apache.wicket.extensions.markup.html.tabs.ITab;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.string.StringValue;
import org.fit.vutbr.relaxdms.web.BasePage;
import org.fit.vutbr.relaxdms.web.cp.menu.MenuItemEnum;
import org.jboss.logging.Logger;

/**
 *
 * @author Martin Kanis
 */
public class DocumentTabs extends BasePage implements Serializable { 
    
    private final Logger log = Logger.getLogger(getClass());
    
    private final String id;
    
    private Map diffMap;

    public DocumentTabs(PageParameters parameters) {
        super(parameters);
        id = getDocId(parameters);
        prepareTabs();
    }
    
    public DocumentTabs(PageParameters parameters, Map diffMap) {
        super(parameters);
        id = getDocId(parameters);
        this.diffMap = diffMap;
        prepareTabs();
    }
    
    private void prepareTabs() {
        List<ITab> tabs = new ArrayList<>();
        tabs.add(new AbstractTab(new Model<>("Document")) {
            @Override
            public Panel getPanel(String panelId) {
                return (diffMap == null) ?  new DocumentPage(panelId, id) :  new DocumentPage(panelId, id, diffMap);
            }
        });

        tabs.add(new AbstractTab(new Model<>("Metadata")) {
            @Override
            public Panel getPanel(String panelId) {
                return new DocumentInfo(panelId, id);
            }
        });

        tabs.add(new AbstractTab(new Model<>("Workflow")) {
            @Override
            public Panel getPanel(String panelId) {
                return new DocumentWorkflow(panelId, id);
            }
        });

        AjaxTabbedPanel ajaxTabbedPanel = new AjaxTabbedPanel("tabs", tabs) {
            @Override
            protected String getSelectedTabCssClass() {
                return "active";
            }

            @Override
            protected String getTabContainerCssClass() {
                return "nav nav-tabs";
            }
        };
        add(ajaxTabbedPanel);
    }
    
    private String getDocId(PageParameters parameters) {
        StringValue sv = parameters.get("id");
        
        if (sv.isNull() || sv.isEmpty()) {
            log.info("ID is null or empty");
        }
        return sv.toString();
    }

    @Override
    public MenuItemEnum getActiveMenu() {
        return MenuItemEnum.DOCUMENT;
    }
}

@@ -223,16 +223,65 @@
 il.Map;%0A
+import org.apache.wicket.ajax.AjaxRequestTarget;%0A
 import o
@@ -343,24 +343,24 @@
 abbedPanel;%0A
-
 import org.a
@@ -468,24 +468,137 @@
 .tabs.ITab;%0A
+import org.apache.wicket.markup.head.IHeaderResponse;%0Aimport org.apache.wicket.markup.head.JavaScriptHeaderItem;%0A
 import org.a
@@ -1157,16 +1157,210 @@
 diffMap;
+%0A    %0A    public static final String script = %22var el = document.getElementsByClassName('navigationTabs');%22%0A            + %22var list = el%5B0%5D.firstElementChild; list.className += 'nav nav-tabs';%22;
 %0A%0A    pu
@@ -2031,32 +2031,44 @@
 ;%0A            %7D%0A
+           %0A
         %7D);%0A%0A   
@@ -2812,18 +2812,467 @@
 %22nav
- nav-tabs%22
+igationTabs%22;%0A            %7D%0A            %0A            @Override%0A            protected void onAjaxUpdate(final AjaxRequestTarget target) %7B%0A                target.appendJavaScript(script);%0A            %7D%0A            %0A            @Override%0A            public void renderHead(IHeaderResponse response) %7B%0A                super.renderHead(response);%0A                response.render(JavaScriptHeaderItem.forScript(%22window.onload = function () %7B%22 + script + %22%7D%22, null))
 ;%0A  

Fix tabs css via javascript