package com.ejie.ad74a.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;

import com.ejie.x38.util.StaticsContainer;

@Configuration
public class MvcConfig {

	/**
	 * Gestiona la locale (idioma) mediante una cookie.
	 * 
	 * @param webApplicationContext Contexto de la aplicación Web.
	 * @return La cookie de idioma.
	 */
	@Bean
	public CookieLocaleResolver localeResolver(WebApplicationContext webApplicationContext) {
		final CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
		cookieLocaleResolver.setCookieName("language");
		cookieLocaleResolver.setCookieHttpOnly(false);
		cookieLocaleResolver.setCookieSecure(StaticsContainer.isCookieSecure());
		cookieLocaleResolver.setCookiePath(
				(StaticsContainer.isCookiePathRoot() ? "/" : webApplicationContext.getServletContext().getContextPath())
						+ "; SameSite=Lax;");
		return cookieLocaleResolver;
	}

}