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

import com.evolute.siprp.client.panels.apps.AnchorSair;
import com.evolute.siprp.client.panels.apps.AnaliseAcidentesTrabalho.actual.ActualPanel;
import com.evolute.siprp.client.panels.apps.AnaliseAcidentesTrabalho.concluido.ConcluidoPanel;
import com.evolute.siprp.client.panels.apps.AnaliseAcidentesTrabalho.seguimento.SeguimentoPanel;
import com.evolute.siprp.client.panels.utils.AppConstants;
import com.evolute.siprp.client.panels.utils.navigation.PageNavigation;
import com.evolute.siprp.client.panels.utils.permissoes.AccessConstants;
import com.evolute.siprp.client.panels.utils.permissoes.PermissionsController;
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 AnaliseAcidentesTrabalhoPanel extends Composite 
{

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

	
	@UiField protected Image imgSiprp;
	@UiField protected Image imgAuchan;
	@UiField protected AnchorSair lnkSair;
	@UiField protected Anchor lnkPlanosActuacao;
	@UiField protected InlineLabel lblUsername;
	
	@UiField protected Anchor lnkGerirUtilizadores;
	@UiField protected Anchor lnkAlterarDados;
	@UiField protected Anchor lnkAjuda;
	
	@UiField protected ActualPanel panelActual;
	@UiField protected SeguimentoPanel panelSeguimento;
	@UiField protected ConcluidoPanel panelConcluido;
	
	
	private Utilizador userLogged;
	private PermissionsController permsController;
	
	
	public AnaliseAcidentesTrabalhoPanel() 
	{		
		initWidget( uiBinder.createAndBindUi( this ) );
		permsController = PermissionsController.getController();
		
		if ( ! permsController.hasPermissionTo( AccessConstants.VIEW_ACTUAL_PANEL ) )
		{
			this.panelActual.setVisible( false );
		}
		if ( ! permsController.hasPermissionTo( AccessConstants.VIEW_SEGUIMENTO_PANEL ) )
		{
			this.panelSeguimento.setVisible( false );
		}
		if ( ! permsController.hasPermissionTo( AccessConstants.VIEW_CONCLUIDO_PANEL ) )
		{
			this.panelConcluido.setVisible( false );
		}
		
		initComponents();
	}

	private void initComponents()
	{
		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" );
		
		lnkPlanosActuacao.setText( "planos actua\u00E7\u00E3o>>" );
		lnkGerirUtilizadores.setText( "gerir utilizadores" );
		lnkAlterarDados.setText( "alterar dados utilizador" );
		lnkAjuda.setText( "ajuda" );
	}
	
	@UiHandler( { "lnkPlanosActuacao", "lnkGerirUtilizadores", "lnkAlterarDados", "lnkAjuda" } )
	protected void onClick( ClickEvent e ) 
	{
		if ( e.getSource().equals( lnkPlanosActuacao ) )
		{
			Window.alert( "planos actuacao..." );
		}
		else if ( e.getSource().equals( lnkGerirUtilizadores ) )
		{
			Window.alert( "gerir utilizadores" );
		}
		else if ( e.getSource().equals( lnkAlterarDados ) ) 
		{
			Window.alert( "alterar dados" );
		}
		else if ( e.getSource().equals( lnkAjuda ) ) 
		{
			Window.alert( "ajuda" );
		}
	}

}
