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

    function ExtensionsManagerComponentViewModel(params, element) {
		this.base = new ACTComponent($(element), params);
		this.containerWidth = ko.observable(100);
		this.containerHeight = ko.observable(100);
		this.applications = ko.observableArray([]);
	
		this.base.onRefresh = function(obj) {
			var nRows = 1
			this.containerWidth(obj.ColumnsCount*110);
			
			addCarre = function(app, data) {
				var i = app.length;
				var row = Math.floor(i/obj.ColumnsCount);
				var col = i%obj.ColumnsCount;
				var left = col*110+5;
				var top = row*110+5;
				data.left = left;
				data.top = top;
				app[i] = data;
			};

			this.base.addCallback(obj, "clickLog", "LogClicked", []);
			this.base.addCallback(obj, "clickReload", "ReloadClicked", []);
			
			app = [];
			addCarre(app,{name: "Log", click: obj.clickLog, backColor: "#cccccc", image: "images/log.png"});
			addCarre(app,{name: "Reload", click: obj.clickReload, backColor: "#cccccc", image: "images/reload.png"});
			
			this.base.addCallback(obj, "clickBack", "BackClicked", []);
			this.clickBack = obj.clickBack;
		
			this.applications(app);
			
		}.bind(this);		

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

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

});

