package com.atlassian.stash.internal.web.locale;

import com.atlassian.fugue.Pair;
import com.atlassian.soy.renderer.SoyTemplateRenderer;
import com.atlassian.stash.internal.language.InternalLanguageService;
import com.atlassian.stash.internal.server.InternalApplicationPropertiesService;

import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import static com.atlassian.fugue.Pair.pair;

public class AdminLocaleFormFragment extends AbstractLocaleFormFragment {

    private final InternalApplicationPropertiesService propertiesService;

    public AdminLocaleFormFragment(InternalLanguageService languageService, InternalApplicationPropertiesService propertiesService, SoyTemplateRenderer soyTemplateRenderer) {
        super(languageService, soyTemplateRenderer);
        this.propertiesService = propertiesService;
    }

    @Override
    protected Pair<Locale, List<Map<String, Object>>> load(Map<String, Object> context) {
        return pair(propertiesService.getLocale(), Collections.<Map<String, Object>>emptyList());
    }

    @Override
    protected void save(Map<String, Object> context, Locale locale) {
        propertiesService.setLocale(locale);
    }
}
