package ru.gubber.googlemaps.server.web.views;

import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.tapio.googlemaps.GoogleMap;
import com.vaadin.tapio.googlemaps.client.LatLon;
import com.vaadin.tapio.googlemaps.client.overlays.GoogleMapInfoWindow;
import com.vaadin.tapio.googlemaps.client.overlays.GoogleMapMarker;
import com.vaadin.ui.*;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * Created with IntelliJ IDEA.
 * User: Gubber
 * Date: 06.03.14
 * Time: 18:45
 */
@Component(value = "mapView")
@SuppressWarnings("serial")
@Scope(value = "session")
public class MapView extends HorizontalLayout implements View {

    private GoogleMap googleMap;
    private GoogleMapMarker kakolaMarker = new GoogleMapMarker(
            "DRAGGABLE: Kakolan vankila", new LatLon(60.44291, 22.242415),
            true, null);
    private GoogleMapInfoWindow kakolaInfoWindow = new GoogleMapInfoWindow(
            "Kakola used to be a provincial prison.", kakolaMarker);
    private final String apiKey = "";

    public MapView() {
    }

    @PostConstruct
    public void init() {
    }

    @Override
    public void enter(ViewChangeListener.ViewChangeEvent viewChangeEvent) {
		setSizeFull();
        VerticalLayout content = new VerticalLayout();
        content.setSizeFull();
        addComponent(content);

        TabSheet tabs = new TabSheet();
        tabs.setSizeFull();
        content.addComponent(tabs);

        final VerticalLayout tab1 = new VerticalLayout();
        tab1.setSizeFull();
        tab1.setCaption("MAP");

        googleMap = new GoogleMap(new LatLon(60.440963, 22.25122), 10.0, apiKey);
        googleMap.setSizeFull();
        kakolaMarker.setAnimationEnabled(false);
        googleMap.addMarker(kakolaMarker);
        googleMap.addMarker("NOT DRAGGABLE: Iso-Heikkilä", new LatLon(
                60.450403, 22.230399), false, null);
        googleMap.setMinZoom(4.0);
        googleMap.setMaxZoom(16.0);

        kakolaInfoWindow.setWidth("400px");
        kakolaInfoWindow.setHeight("500px");

        tab1.addComponent(googleMap);
        tab1.setExpandRatio(googleMap, 1.0f);

        Panel console = new Panel();
        console.setHeight("100px");
        final CssLayout consoleLayout = new CssLayout();
        console.setContent(consoleLayout);
        tab1.addComponent(console);

        HorizontalLayout buttonLayoutRow1 = new HorizontalLayout();
        buttonLayoutRow1.setHeight("26px");
        tab1.addComponent(buttonLayoutRow1);

        HorizontalLayout buttonLayoutRow2 = new HorizontalLayout();
        buttonLayoutRow2.setHeight("26px");
        tab1.addComponent(buttonLayoutRow2);
        tabs.addTab(tab1);

        Label tab2 = new Label("Tab2!");
        tab2.setCaption("Tab 2");
        tabs.addTab(tab2);
    }
}