package com.evolute.siprp.client.panels.apps;

import com.evolute.siprp.client.panels.utils.AppConstants;
import com.evolute.siprp.client.panels.utils.navigation.NavigationConstants;
import com.evolute.siprp.client.panels.utils.navigation.PageNavigation;
import com.evolute.siprp.client.vo.Utilizador;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.Widget;

public class MainPanel extends Composite 
{

	private static MainPanelUiBinder uiBinder = GWT.create( MainPanelUiBinder.class );
	interface MainPanelUiBinder extends UiBinder< Widget, MainPanel > {  }

	@UiField protected InlineLabel lblUsername;
	@UiField protected InlineLabel lblName;
	@UiField protected AnchorSair lnkSair;
	@UiField protected Anchor lnkAnaliseAcidentesTrabalho;
	@UiField protected Anchor lnkPlanosActuacao;
	@UiField protected Image imgSiprp;
	@UiField protected Image imgAuchan;	

	private Utilizador userLogged;
	
	public MainPanel() 
	{
		initWidget( uiBinder.createAndBindUi( this ) );

		userLogged = PageNavigation.getProvider().getUserLogged();
		
		lblUsername.setText( userLogged.getUsername() );
		
		imgSiprp.setTitle( "SIPRP" );
		imgSiprp.setUrl( AppConstants.IMAGES_FOLDER + "SIPRP_logo_small.jpg" );
		imgAuchan.setTitle( "Auchan" );
		imgAuchan.setUrl( AppConstants.IMAGES_FOLDER + "logo_empresa32.jpg" );
		imgAuchan.setHeight( "40" );
		
		lblName.setText( userLogged.getNome() );
		lnkAnaliseAcidentesTrabalho.setText( "An\u00E1lise de Acidentes de Trabalho" );
		lnkPlanosActuacao.setText( "Planos de Actua\u00E7\u00E3o" );
	}
	

	@UiHandler( { "lnkAnaliseAcidentesTrabalho", "lnkPlanosActuacao" } )
	protected void onClick( ClickEvent e ) 
	{
		if ( e.getSource().equals( lnkAnaliseAcidentesTrabalho ) )
		{
			PageNavigation.goPage( NavigationConstants.ANALISE_ACIDENTES_TRABALHO_PANEL );
		}
		else if ( e.getSource().equals( lnkPlanosActuacao ) )
		{
			//TODO:
			Window.alert( "TODO" );
		}
	}
	
}
