define(['scripts/knockout-3.3.0','scripts/ACTComponent.js'], function(ko, ACTComponent) {

    function ButtonsComponentViewModel(params, element) {
		this.base = new ACTComponent($(element), params);
	
		this.element = element;
		this.buttons = ko.observableArray([]);
		this.message = ko.observable("");

		this.base.onRefresh = function(obj) {
			params.ready(false);
			for (var i=0;i<obj.Buttons.length;i++) {
				var buttonObj = obj.Buttons[i];
				if (buttonObj.TriggerClick) {
					var $currentButtonElement = $(element).find("." + buttonObj.Name);
					$currentButtonElement.trigger("click");
				}

				buttonObj.click = function(e) {
					params.baseModel.onTriggerAction("TriggerClick", [this.Name]);
					this.__click();
				}
				this.base.addCallback(buttonObj, "__click", "Clicked", []);
			}

			this.message(obj.Message);
			this.buttons(obj.Buttons);
			params.ready(true);
		}.bind(this);

		this.base.initialize();
		params.ready(true);
    }

	return {
		createViewModel: function(params, componentInfo) {
            return new ButtonsComponentViewModel(params, componentInfo.element);
        }
	};

});

