package info.bukova.isspst.ui.signeddocs;

import info.bukova.isspst.DateTimeUtils;
import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.SignedDocument;
import info.bukova.isspst.data.SignedDocumentItem;
import org.zkoss.zul.*;

public class SignedDocsTreeRenderer implements TreeitemRenderer<SignedDocsTreeNode> {
    public void render(Treeitem item, SignedDocsTreeNode data, int index) throws Exception {

        int deep = data.getDeep();

        boolean node1 = (deep == 1);//data.getParent().getParent() == null;
        boolean node3 = (deep == 3);//data.isLeaf();
        boolean node2 = (deep == 2);//!node1 && !node3;
        boolean node4 = (deep == 4);//!node1 && !node3;

        SignedDocumentItem signedDocumentItem = data.getData();
        SignedDocument signedDocument = signedDocumentItem.getSignedDocument();

        Treerow tr = new Treerow();
        tr.setContext("popupMenu");

        item.appendChild(tr);
        tr.appendChild(new Treecell(node1 ? signedDocument.getAgendaName() : ""));
        tr.appendChild(new Treecell(node2 ? DateTimeUtils.getFormatedYear(signedDocument.getSignDate()) : ""));
        tr.appendChild(new Treecell(node3 ? DateTimeUtils.getFormatedDate(signedDocument.getSignDate()) : ""));
        tr.appendChild(new Treecell(node4 ? signedDocument.getNumser() : ""));
        tr.appendChild(new Treecell(node4 ? signedDocument.getDescription() : ""));
        tr.appendChild(new Treecell(node4 ? signedDocumentItem.getReportName() : data.getLeafsCount() + " souborů"));
//        tr.appendChild(new Treecell(node3 ? signedDocumentItem.getFileName() : ""));

        switch (deep) {
            case 1 : tr.setSclass("signed-doc-agenda");   break;
            case 2 : tr.setSclass("signed-doc-year");     break;
            case 3 : tr.setSclass("signed-doc-date");     break;
            case 4 : tr.setSclass("");                    break;
        }
    }
}
