/**
 * @class Roo.gui.StatusPanel
 * @extends Ext.Panel
 *
 * The StatusPanel is located aboove the large map and provides with information about actions the user
 * has taken.
 *
 * @author ssmeman
 * @version 1.0
 */

/**
 * @constructor
 * @param {Object} config Configuration options
 */
Roo.gui.StatusPanel = Ext.extend(Ext.Panel, {
	buttonShow: messages.statusPanel.buttonShow()
	,buttonIdentify: messages.statusPanel.buttonIdentify()

	,id: 'statusPanel'
	,region: 'north'
	,height: 36

	,initComponent:function() {

		var config = {
			border: false
			,layout: 'column'
			,defaults: {
				border: false
			}
			,items: [{
				xtype: 'panel'
				,id: 'statusBar'
				,style: 'margin-left:28px; padding:3px'
				,cls: 'x-panel'
				,columnWidth: 1
			},{
				xtype: 'panel'
				,id: 'navPanel'
				,style: 'margin-right:10px; text-align:right;'
				,width: 170
				,defaults: {
					xtype: 'button'
					,hidden: true
				}
				,items: [{
					id: 'searchresult-button'
					,text: this.buttonShow
					,handler: function(target, event) {
						// TODO do this without coupling (events)
						Roo.currentPlan = {};
						var map = Ext.getCmp('largemapPanel');
						map.clearMapFilters();
						map.moveExtendToSearchResult();

						Ext.getCmp('infoPanel').getLayout().setActiveItem('planGridPanel');
						closePlanTreeWindow();
					}
				},{
					id: 'identifyresult-button'
					,text: this.buttonIdentify
					,handler: function(target, event) {
						// TODO do this without coupling (events)
						Roo.currentPlan = {};
						Ext.getCmp('largemapPanel').clearMapFilters();
						Ext.getCmp('infoPanel').getLayout().setActiveItem('about-panel');
						closePlanTreeWindow();
						target.hide();
					}
				}]
			}]
		};

		Ext.apply(this, config);
		Ext.apply(this.initialConfig, config);

		// call parent initComponent
		Roo.gui.StatusPanel.superclass.initComponent.apply(this, arguments);

		// Statusbar related event handling
		eventHub.on({
			scope: this
			,'foundLocation': function(location) {
				this.setStatus({
					text: messages.statusPanel.msg.foundLocation()
					,text2: location.name
				});
			}
			,'selectedPlan': function(plan) {
				this.setStatus({
					text: plan.typePlan
					,text2: plan.naam
				});
			}
			,'selectedPlanAuthentic': function(plan) {
				this.setStatus({
					text: messages.statusPanel.msg.selectedPlanAuthentic()
					,text2: plan.naam
				});
			}
			,'foundPlans': function(record, query) {
				if (record.length == 1) {
					text2 = messages.statusPanel.msg.foundSinglePlan(record.length);
				} else {
					text2 = messages.statusPanel.msg.foundMultiplePlans(record.length);
				}

				this.setStatus({
					text: messages.statusPanel.msg.foundPlans(query)
					,text2: text2
				});
			}
			,'checkedGebruiksmogelijkheid': function(layer) {
				this.setStatus({
					text: messages.statusPanel.msg.checkedGebruiksmogelijkheid() + ' ' +
						(layer.value ? messages.statusPanel.msg.checkedGebruiksmogelijkheid.show() : messages.statusPanel.msg.checkedGebruiksmogelijkheid.hide())
					,text2: layer.title
				});
			}
			,'receivedUrlParameters': function(parameters) {
				if (parameters.boundingBox) {
					console.info("StatusPanel.on(receivedUrlParamters): boundingbox=%s", parameters.boundingBox);
				}
			}
			,'expandedGebruiksmogelijkhedenPanel': function(layers) {
				this.setStatus({
					text: messages.statusPanel.msg.expandedGebruiksmogelijkheid()
					,text2: ''
				});
			}
			,'collapsedGebruiksmogelijkhedenPanel': function(layers) {
				this.setStatus({
					text: messages.statusPanel.msg.collapsedGebruiksmogelijkheid()
					,text2: ''
				});
			}

			,'changedFilter': function(parameters) {

				switch (parameters.filter) {
				case 'JURIDISCH':
					this.setStatus({
						text: messages.statusPanel.msg.statusFilter()
						,text2: messages.statusPanel.msg.statusFilter.activated()
					});
					break;
				case 'ACTUEEL':
					this.setStatus({
						text: messages.statusPanel.msg.statusFilter()
						,text2: messages.statusPanel.msg.statusFilter.deactivated()
					});
					break;
				default:
					this.setStatus();
					break;
				}
				Ext.getCmp('searchresult-button').hide();
				Ext.getCmp('identifyresult-button').hide();
			}
		});

	} // e/o function initComponent

	,setStatus: function(obj) {
		var tmpl;
		var el = Ext.getCmp('statusBar').getEl();

		if (obj !== undefined) {
			tmpl = new Ext.XTemplate('<span style="font-size:90%; font-weight:bold">{text}<tpl if="this.hasTwoLines(text2)">:</tpl></span>&nbsp;<span style="font-size:90%">{text2}</span>', {hasTwoLines:function(line2){ return line2 != undefined && line2 != '';}});
			tmpl.overwrite(el, obj);
		} else {
			tmpl = new Ext.XTemplate('');
			tmpl.overwrite(el, {});
		}

		el.setStyle({
			'font-family' : 'Verdana,Arial,Helvetica,sans-serif',
			'font-size' : '12px'
		});
	}
});	// e/o extend

// register xtype
Ext.reg('statusPanel', Roo.gui.StatusPanel);
