var BrowserFile = File;

var File = Namespace.declare("tla.EAM.layer3",
    class File extends Tree {
        static dependencies() {
            return [
                "/EAMD.ucp/Components/com/ceruleanCircle/EAM/5_ux/StructrES6Client/0.5.0/StructrES6Client.component.xml"
            ];
        }
        constructor() {
            super();
        }

        get eamLayer() { return 3 };

        get isFolder() {
            return false;
        }

        get path() {
            return this.parent;
        }


    }
);

var Folder = Namespace.declare("tla.EAM.layer3",
    class Folder extends File {
        static dependencies() {
            return [
                "/EAMD.ucp/Components/com/ceruleanCircle/EAM/5_ux/StructrES6Client/0.5.0/StructrES6Client.component.xml"
            ];
        }
        constructor() {
            super();
        }

        get eamLayer() { return 3 };

        get isFolder() {
            return true;
        }

    }
);



var DefaultFile = Namespace.declare("tla.EAM.layer3",
    class DefaultFile extends File {
        static dependencies() {
            return [
                "/EAMD.ucp/Components/com/ceruleanCircle/EAM/5_ux/StructrES6Client/0.5.0/StructrES6Client.component.xml"
            ];
        }
        constructor() {
            super();
        }

        get eamLayer() { return 2 };

        get isFolder() {
            return false;
        }

        get path() {
            return this.parent;
        }


    }
);


var StructrFile = Namespace.declare("org.structr.layer2",
    class StructrFile extends UcpComponent {
        static start() {}
        static dependencies() {
            return [
                "/EAMD.ucp/Components/com/twitter/Bootstrap/Breadcrumb/1.0.0/Breadcrumb.component.xml"
            ];
        }


        constructor() {
            super();
            Thinglish.implement(this, File);
        }

        init(structrObject) {
            if (this.isInitialized)
                return;
            //super.init();

            structrObject.properties.description = this.type.name;
            structrObject.ucpComponent = this;
            this.isInitialized = true;

            return this;
        }

        get properties() {
            return super.properties;
        }
        set properties(structrObject) {
            this.ucpModel = structrObject;
        }
    }
);

var StructrFolder = Namespace.declare("org.structr.layer2",
    class StructrFolder extends UcpComponent {
        static start() {}
        static dependencies() {
            return [
                "/EAMD.ucp/Components/com/twitter/Bootstrap/Breadcrumb/1.0.0/Breadcrumb.component.xml"
            ];
        }


        constructor() {
            super();
            Thinglish.implement(this, Folder);
        }

        init(structrObject) {
            if (this.isInitialized)
                return;
            //super.init();
            //this.ucpModel = structrObject;

            structrObject.properties.description = this.type.name;
            structrObject.ucpComponent = this;
            this.isInitialized = true;

            return this;
        }

        get properties() {
            return super.properties;
        }
        set properties(structrObject) {
            this.ucpModel = structrObject;
        }

        get overView() {
            return this.controller.getOverView(this.ucpModel);
        }
        createOverView() {
            return new DefaultFolderOverView();
        }

    }
);

var DefaultFolderOverView = Namespace.declare("tla.EAM.layer5",
    class DefaultFolderOverView extends OverView {
        init(object) {
            super.init(object);
            //            var ucpComponent = UcpComponentSupport.getUcpComponent4Object(object);

            return this;
        }

        get description() {
            var description = this.properties.description;
            if (!description) description = Thinglish.lookupInObject(this, "ucpComponent.type.ucpComponentDescriptor.properties.description");
            if (!description) description = "";
            if (Thinglish.lookupInObject(this, "model.type.name"))
                description = this.model.type.name + ": " + description;

            if (this.model instanceof StructrObject)
                description = "StructrObject: " + this.model.structrType;

            return description;
        }

        get typeName() {
            return Thinglish.getTypeName(this.model);
        }

        select() {
            console.debug("select", this.ucpModel._private.model);
        }

        append(element) {
            super.append(element);
            //if (Array.isArray(this.model))
            if (!this.breadcrum) {
                this.breadcrum = Breadcrumb.getInstance().init();
                this.breadcrum.model = this.model;
                this.breadcrum.defaultView.append(element);
            }
            this.slipList.appendItem(this.model);
            this.slipList.eventSupport.addEventListener("selected", this.ucpComponent, this.ucpComponent.handleSelection.bind(this.ucpComponent));
            /*else {
                // get all collections
                var p = null;
                var attributes = [];
                // StructrObjects properties from Structr
                var properties = this.model.properties;
                // StructrObject attributes locally
                //var test = this.properties;
                for (p in properties) {
                    attributes.push(p);
                    var value = properties[p];
                    if (Array.isArray(value)) {
                        this.slipList.appendItem({ name: p, description: "Collection of " + this.model.id, badge: value.length, model: value, href: "#" });
                    }
                }
            }*/

        }

        replace(element) {
            super.replace(element);
        }

        get slipList() {
            return this.documentElement.children[1].ucpView.ucpComponent;
        }

    }
);