package de.otto.edison.togglz.configuration;

import de.otto.edison.navigation.NavBar;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.togglz.console.TogglzConsoleServlet;

import static de.otto.edison.navigation.NavBarItem.bottom;
import static de.otto.edison.navigation.NavBarItem.navBarItem;

@Configuration
@EnableConfigurationProperties(value = {TogglzProperties.class})
@ConditionalOnProperty(prefix = "edison.togglz.console", name = "enabled", havingValue = "true", matchIfMissing = true)
public class TogglzConsoleConfiguration {

    public static final String TOGGLES_URL_PATTERN = "/toggles/console/*";

    private TogglzProperties properties;

    public TogglzConsoleConfiguration(TogglzProperties properties) {
        this.properties = properties;
    }

    @Bean
    public ServletRegistrationBean<?> togglzServlet(final @Value("${edison.application.management.base-path:/internal}") String prefix,
                                                    final NavBar rightNavBar) {

        // Register Togglz Console in the right "Admin" navigation bar:
        rightNavBar.register(navBarItem(bottom(), "Feature Toggles", prefix + "/toggles/console"));
        // Register TogglzConsoleServlet:
        TogglzConsoleServlet togglzConsoleServlet = new TogglzConsoleServlet();
        togglzConsoleServlet.setValidateCSRFToken(properties.getConsole().isValidateCSRFToken());
        return new ServletRegistrationBean<>(togglzConsoleServlet, prefix + TOGGLES_URL_PATTERN);
    }
}

@@ -977,164 +977,8 @@
 %22;%0A%0A
-    private TogglzProperties properties;%0A%0A    public TogglzConsoleConfiguration(TogglzProperties properties) %7B%0A        this.properties = properties;%0A    %7D%0A%0A
     
@@ -1195,16 +1195,51 @@
 htNavBar
+, final TogglzProperties properties
 ) %7B%0A%0A   

fix toggles tests