Ext.define("IceCap.ux.form.field.SimpleComboBox", {

	extend: "Ext.form.field.ComboBox",

	alias: [
		"widget.COMBOBOX"
	],

	valueField: "key",

	displayField: "value",

	typeAhead: true,

	mode: "local",

	forceSelection: true,

	triggerAction: "all",

	selectOnFocus: true,

	minChars: 1,

	config: {
		valueMap: []
	},

	listeners: {
		keydown: {
			fn: function(i_field, i_event) {

				var n_key = i_event.getKey();
				
				if (i_field.isExpanded) {
					if (n_key == Ext.event.Event.DOWN || n_key == Ext.event.Event.UP) {
						i_event.stopEvent();
					}
				}
			}
		}
	},

	initComponent: function() {

		var i_self = this;
		var i_store = i_self.createStore();

		i_self.store = i_store;
		i_self.callParent();
	},

	createStore: function() {

		var i_self = this;

		var a_data = [];

		var a_valueData = i_self.getValueMap();

		Ext.Array.each(a_valueData, function(a_value) {

			if (a_value.length >= 2) {
				var o_data = {
					key: a_value[0],
					value: a_value[1]
				};

				a_data.push(o_data);
			}
		});

		var i_store = Ext.create("Ext.data.Store", {
			fields: [
				{
					name: "key",
					type: "auto"
				},
				{
					name: "value",
					type: "auto"
				}
			],
			autoLoad: true,
			data: a_data
		});

		return i_store;
	}
});
