/*
 *  Copyright 2013-2050 Emmanuel BRUN (contact@amapj.fr)
 * 
 *  This file is part of AmapJ.
 *  
 *  AmapJ is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.

 *  AmapJ is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with AmapJ.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * 
 */
 package fr.amapj.view.views.login.passwordexpired;

import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

import fr.amapj.service.services.authentification.PasswordComplianceService.CheckComplianceType;
import fr.amapj.service.services.authentification.AuthentificationService.CheckResult;
import fr.amapj.view.engine.popup.corepopup.CorePopup;
import fr.amapj.view.engine.ui.AmapUI;

/**
 *  
 */

public class ExpiredPasswordStep1Popup extends CorePopup
{
	protected Button laterButton;
	
	protected Button nowButton;

	private AmapUI ui;

	private CheckResult checkResult;
	
	/**
	 * @param ui 
	 * @param type 
	 *  
	 */
	public ExpiredPasswordStep1Popup(AmapUI ui, CheckResult checkResult)
	{
		this.ui = ui;
		this.checkResult = checkResult;
		
		setHeight("50%");
		popupTitle = "Mot de passe expiré";
		setColorStyle(ColorStyle.RED);
	}
	
	protected void createButtonBar()
	{	
		if (checkResult.type==CheckComplianceType.SHOULD_CHANGE_PASSWORD)
		{
			laterButton = addButton("Changer le mot de passe plus tard",e->{ close(); ui.buildMainView();});
		}	
		addButtonBlank();
		
		nowButton = addDefaultButton("Changer le mot de passe maintenant",e->{ close(); new ExpiredPasswordStep2Popup(ui,checkResult).open();});
	}
	

	protected void createContent(VerticalLayout contentLayout)
	{
		String str1 = "Votre mot de passe a expiré ou est trop simple.<br/><br/>";
		if (checkResult.type==CheckComplianceType.SHOULD_CHANGE_PASSWORD)
		{
			str1 = str1+"Vous pouvez le changer tout de suite ou dans un delai de 7 jours après la première notification. ";
		}
		else
		{
			str1 = str1+"Vous devez le changer maintenant";
		}
		
		Label la = new Label(str1,ContentMode.HTML);	
		contentLayout.addComponent(la);
	}
	
}
