var Button = Namespace.declare("com.twitter.Bootstrap",
    class Button extends UcpComponent {
        static get implements() { return []; };
        static start() {}

        static get dependencies() {
            return [
                "/EAMD.ucp/Components/com/twitter/Bootstrap/3.3.7/Bootstrap.component.xml"
            ];
        }

        static get TEXT_ALIGNMENT() { return Object.freeze({ LEFT: "pull-left", CENTER: "", RIGHT: "pull-right" }) }


        constructor() {
            super();
            /*
            this.text = "From Button class.js";
            this.cssClasses = "btn-default";
            this.textAlignment = Button.TEXT_ALIGNMENT.CENTER;
            if (!this.clickmethodname) {
                this.clickmethodname = "select";
            }
            */
        }

        init() {
            if (this._private.isInitialized) {
                return;
            }

            super.init();

            this.model = {
                cssClasses: "btn-default",
                textAlignment: Button.TEXT_ALIGNMENT.CENTER,
                text: "this.text",
                onClickMethodName: "onClick",
                action: undefined
            }
            Thinglish.defineAlias(this, "model.text", "displayName");
            Thinglish.defineAlias(this, "model.footer", "description");
            Thinglish.defineAlias(this, "firstIndex", "badge");


            return this;
        }

        get name() {
            return this.text;
        }

        set name(newValue) {
            if (this.properties) {
                this.properties.text = newValue;
            } else {
                this.text = newValue;
            }
        }

        setButtonType(cssClasses) {
            this.properties.cssClasses = cssClasses;
        }

        /*
        setButtonText(txt) {
            this.properties.text = txt;
        }
        */

        async onClick() {
            console.debug(this.name + " was clicked");
            if (this.model.action) {
                let result = await this.model.action.do();
                if (result != undefined && this.model.action.actionId != Action.lookup(What.ACTION_PUSH).actionId)
                    Action.do(What.ACTION_PUSH, result);
            }
        }

        submitClicked() {
            console.debug("The page will now be submitted");
        }

        resetClicked() {
            console.debug("The page will now be reset");
        }

        setAction(action) {
            if (!action) return;
            this.model.text = action.displayName;
            this.documentElement.onclick = action.do.bind(action);
            //if (action.severity !== "primary")
            this.setButtonType("btn btn-" + action.severity)
            this.model.action = action;
            this.update();
        }

    }
)