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

    function LogComponentViewModel(params, element) {
		this.base = new ACTComponent($(element), params);
		this.element = element;
		this.ButtonClicked = params.Model.ButtonClicked;
		this.Started = params.Model.Started;

		this.base.onRefresh = function(obj) {
			$("#contentlog div#logmessage").html(obj.Content);
			params.ready(true);
		}.bind(this);

		this.base.onMessage = function(name, obj) {
			if (name == "Clear") {
				var $logMessage = $("#contentlog div#logmessage");
				$logMessage.remove();  // to make the clean faster cause don't update the browser for each div
				$logMessage.html(obj);
				$("#contentlog").append($logMessage);
			} else if (name == "Content") {
				$("#contentlog div#logmessage").append(obj);
			}
			$("#contentlog").scrollTop($("#contentlog")[0].scrollHeight);
		}.bind(this);

		this.base.initialize();
		this.base.addCallback(this, "click", "ButtonClicked", []);
		this.base.addCallback(this, "started", "Started", []);
		this.started();
    }

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

});

