/* global DefaultOverview, View, UcpController, DefaultItem, DefaultDetails */
var ItemView = Namespace.declare("tla.EAM.layer3.WODAViews",
    class ItemView extends View {
        static get ACTION_OPEN_LINK() { return "actionId:public:ItemView.openLink[Open Link]"; }
        get name() {
            if (!this.model) {
                return this.constructor.name;
            }
            if (!this.properties) {
                return null;
            }
            let name = this.properties.name || this.model.name || this.model.id || this.model.constructor.name;

            if (Thinglish.isClass(this.model)) {
                name = `Class: ${name}`;
            }

            if (!this.properties.name) {
                if (Array.isArray(this.model)) {
                    name = Thinglish.getTypeName(this.model);
                }
            }

            return name;
        }
        set name(newValue) {
            if (!this.properties) {
                return;
            }
            this.properties.name = newValue;
        }

        get cssClasses() {
            return this.properties.cssClasses || '';
        }
        get href() {
            return this.properties.href || '#';
        }
        set href(newValue) {
            this.properties.href = newValue;
        }
        get target() {
            return this.properties.target || '_self';
        }
        set target(newValue) {
            this.properties.target = newValue;
        }
        get badge() {
            let badge = this.properties.badge;
            if (Array.isArray(this.model)) {
                badge = new String(this.model.length).valueOf();
            }
            if (!badge) {
                badge = "1";
            }
            return badge;
        }
        set badge(newValue) {
            this.properties.badge = newValue;
        }

        get description() {
            const description = this.properties.description || Thinglish.lookupInObject(this, "ucpComponent.type.ucpComponentDescriptor.properties.description") || '';

            if (Thinglish.lookupInObject(this, "model.type.name")) {
                return `${this.model.type.name}: ${description}`;
            }

            return description;
        }
        set description(newValue) {
            this.properties.description = newValue;
            this.update();
        }
    }
);

var OverView = Namespace.declare("tla.EAM.layer3.WODAViews",
    class OverView extends View {
        static get ACTION_SHOW() {
            return "actionId:public:OverView.show[Show Overview]:primary";
        }

        static get DEFAULT_PAGINATION_SIZE() {
            return 40;
        }

        get paginationSize() {
            if (this._private.pageSize === undefined) {
                this._private.pageSize = OverView.DEFAULT_PAGINATION_SIZE;
            }
            return this._private.pageSize;
        }
        set paginationSize(newValue) {
            if (this._private.pageSize === undefined) {
                this._private.pageSize = OverView.DEFAULT_PAGINATION_SIZE;
            }
            this._private.pageSize = newValue;
        }
        get nextPage() {}

        get currentObject() {
            return this._private.currentObject;
        }

        get list() {
            console.warn('========== no list implemented for this component ============');
            return {
                model: {},
                update: () => {}
            };
        }

        set filterCondition(val) {
            this._private.filterCondition = val.trim();
        }
        get filterCondition() {
            return this._private.filterCondition || '';
        }


    }
);

var DetailsView = Namespace.declare("tla.EAM.layer3.WODAViews",
    class DetailsView extends View {
        static get ACTION_SHOW() {
            return "actionId:public:DetailsView.show[Show Details]:primary";
        }
        static get ACTION_OPEN() { return "actionId:public:DetailsView.open[Open]:success"; }


    }
);


var EditView = Namespace.declare("tla.EAM.layer3.WODAViews",
    class EditView extends View {}
);

var WODAViews = Namespace.declare("tla.EAM.layer3",
    class WODAViews extends Interface {
        static get dependencies() { return []; }
        static get defaultImplementationClass() {
            return UcpController;
        }

        getItemView() {
            if (this.itemView) {
                return this.itemView;
            }

            this.itemView = DefaultItem.getInstance();
            return this.itemView;
        }
        getOverView() {
            this.overView = this.overView || DefaultOverview.getInstance();
            return this.overView;
        }
        getDetailsView() {
            this.detailsView = this.detailsView || DefaultDetails.getInstance();
            return this.detailsView;
        }
        getActionView() {
            this.actionView = this.actionView || null;
            return this.actionView;
        }
    }
);
