var OverviewPanel = Namespace.declare("com.ceruleanCircle.EAM.5_ux.WODA",
    class OverviewPanel extends UcpComponent {
        static start() {}
        static dependencies() {
            return [
                "/EAMD.ucp/Components/com/twitter/Bootstrap/Panel/1.0.0/Panel.component.xml",
                "/EAMD.ucp/Components/com/ceruleanCircle/EAM/5_ux/WODA/OverviewPanel/DefaultOverview/1.0.0/DefaultOverview.component.xml"
            ];
        }


        constructor() {
            super();
            this.model = {
                    id: this.id,
                    css: "col-sm-4 fullHeight",
                    panel: {
                        classes: "fullHeight",
                        heading: "Overview",
                        overflow: "hidden",
                        footer: "All the Collections and Trees"
                    }
                }
                //this.controller.eventSupport.addEventListener("newView", this, this.newView.bind(this));
                //this.controller.eventSupport.addEventListener("selected", this, this.selected.bind(this));

        }

        init() {
            super.init();
            /*
            this.panel = Panel.getInstance();
            this.panel.model = {
                classes: "fullHeight",
                heading: "Overview",
                footer: "All the Collections and Trees"
            }
            this.add(this.panel);
            */
            this.overviewTab = DefaultOverview.getInstance();
            this.add(this.overviewTab);
            return this;
        }

        get panel() {
            return this.documentElement.children[0].weBeanNode.model.ucpComponent;
        }
        get container() {
            return this.panel.defaultView.container;
        }
        /*
        newView(event, item) {

        }
        */

        handleSelection(event, item) {
            console.log(this.constructor.name+": handleSelection",item);
            var i = null;
            if (Array.isArray(item) && item.length>0)
              i = item[0];
            else
              i = item;

            const overviewType = i.constructor.name+"Overview";
            if (overviewType.startsWith("Promise")) {
                i.then(promissedItem => { 
                    this.handleSelection(event, promissedItem)}
                );
            }
            else {
                    console.log(this.constructor.name+": handleSelection: checking for special Overview:",overviewType);
                    var aClass = null;
                    try {
                        aClass = eval(overviewType);
                    }
                    catch (error) {};
                    if (aClass) {
                        this.overviewTab.defaultView.remove();
                        this.overviewTab = new aClass();
                        this.add(this.overviewTab);
                    }

                    this.overviewTab.handleSelection(event, item);
            }
        }

    }
);