Ext.define("Portfolio.designer.ui.wizard.view.Main", {
	extend: "Ext.panel.Panel",

	alias: "widget.designer.ui.wizard.view.main",

	layout: "card",

	border: false,

	config: {
		designer: null,
		entity: null,
		model: null,
		columnManager: null,
		entityPropertyManager: null,
		keyManager: null,
		relationManager: null,
		constraintsManager: null,
		formDesigner: null,
		newEntity: true
	},

	requires: [
		"Portfolio.designer.ui.domainModelEntityPropertyManager",
		"Portfolio.designer.ui.domainModelEntityColumnManager",
		"Portfolio.designer.ui.domainModelEntityKeyManager",
		"Portfolio.designer.ui.domainModelEntityRelationManager",
		"Portfolio.designer.ui.constraints.view.Manager"
	],

	initComponent: function() {

		var i_self = this;
		i_self.callParent(arguments);
		i_self.add(i_self.createCards());
	},

	createCards: function() {

		var i_self = this;
		var o_entity = {};
		var i_designer = i_self.getDesigner();
		var o_model = i_designer.model;
		var a_required = o_model.required || [];

		a_required = a_required || [];

		var a_cards = [];

		var i_entityPropertyManager = Ext.create("Portfolio.designer.ui.domainModelEntityPropertyManager", {
			name: "card-1",
			title: "Entity",
			designer: i_designer,
			entityManager: i_self,
			entity: o_entity
		});

		i_self.setEntityPropertyManager(i_entityPropertyManager);

		// entity columns
		// --------------
		var i_columnManager = Ext.create("Portfolio.designer.ui.domainModelEntityColumnManager", {
			name: "card-0",
			title: "Columns",
			designer: i_designer,
			entityManager: i_self,
			entity: o_entity
		});

		i_self.setColumnManager(i_columnManager);

		// entity keys
		// -----------
		var i_keyManager = Ext.create("Portfolio.designer.ui.domainModelEntityKeyManager", {
			name: "card-2",
			title: "Keys / Index",
			designer: i_designer,
			entityManager: i_self,
			entity: o_entity
		});

		i_self.setKeyManager(i_keyManager);

		// entity relations
		// ----------------
		var i_relationManager = Ext.create("Portfolio.designer.ui.domainModelEntityRelationManager", {
			name: "card-3",
			title: "Relations",
			designer: i_designer,
			model: i_self.getModel() || "",
			entityManager: i_self,
			entity: o_entity
		});

		i_self.setRelationManager(i_relationManager);

		// entity relations
		// ----------------
		var i_constraintsManager = Ext.widget("designer.ui.constraints.manager", {
			name: "card-4",
			designer: i_designer,
			entityManager: i_self,
			entity: o_entity,
			title: ip2.i18n({
				da: "Constraints",
				en: "Constraints"
			})
		});

		i_self.setConstraintsManager(i_constraintsManager);

		a_cards.push(i_columnManager);
		a_cards.push(i_entityPropertyManager);
		a_cards.push(i_keyManager);
		a_cards.push(i_relationManager);
		a_cards.push(i_constraintsManager);

		return a_cards;
	},

	setChanged: Ext.emptyFn
});

