window.forecastTab = Object.assign({}, window.forecastTab, {  
    forecastMaps: {  
        styleHandle: function(feature, context){
            // get props from hideout
	    const {bounds, colorscale, style, colorProp} = context.props.hideout;
            // get value the determines the color
            const value = feature.properties[colorProp];
	    for (let i = 0; i < bounds.length; ++i) {
		if (value > bounds[i]) {
	            // set the fill color according to the class
		    style.fillColor = colorscale[i];
		}
	    }
            return style;
        },
	pointToLayer: function(feature, latlng, context){
            const {min, max, colorscale, circleOptions, colorProp} = context.props.hideout;
            // set color based on color prop.
            circleOptions.fillColor = feature.properties[colorProp];
            // sender a simple circle marker.
            return L.circleMarker(latlng, circleOptions);
        },
	bindTooltip: function(feature, layer, context) {
            const props = feature.properties;
            // delete props.cluster;
            layer.bindTooltip(JSON.stringify(props.value), { opacity: 1.0 })
        }
    },
    wasMaps: {
        styleHandle: function(feature, context){
            // get props from hideout
	    const {bounds, colorscale, style, colorProp} = context.props.hideout;
            // get value the determines the color
            const value = feature.properties[colorProp];
	    style.fillColor = colorscale[value];
            return style;
        },
    }
});

window.evaluationTab = Object.assign({}, window.evaluationTab, {  
    evaluationMaps: {  
	pointToLayer: function(feature, latlng, context){
            const {circleOptions} = context.props.hideout;
            // sender a simple circle marker.
            return L.circleMarker(latlng, circleOptions);
        },
    }
});

window.observationsTab = Object.assign({}, window.observationsTab, {  
    observationsMaps: {  
	pointToLayer: function(feature, latlng, context){
            const {colorscale, circleOptions, colorProp} = context.props.hideout;
            const value = feature.properties[colorProp];
            circleOptions.fillColor = colorscale[value];
            // sender a simple circle marker.
            return L.circleMarker(latlng, circleOptions);
        },
    }
});

$(document).ready(function () {
    $(document).on('click', ".leaflet-popup-close-button", function () {
	elements = document.getElementsByClassName("leaflet-popup-close-button");
	
	for (let i = 0; i < elements.length; i++) {
	    var elem = elements[i];
	    // elem.replaceWith(elem.clone());
	    alert(elem.innerHTML);
	}

	alert('Closing!');
        elements[0].close();
    });
});

// Functions to fullscreen iframe
function requestFullScreen(element) {
    var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen;
    requestMethod.call(element);
}

function exitFullScreen() {
    const element = window.parent.document
    const cancelFullScreen = element.exitFullscreen || element.mozCancelFullScreen || element.webkitExitFullscreen || element.msExitFullscreen;
    cancelFullScreen.call(element);
};

// Wait for click to go fullscreen
$(document).ready(function () {
        $(document).on('click', "#fullscreen-tab", function () {
                var element = window.parent.document.getElementById('product-iframe');
                if(window.parent.document.fullscreenElement!=null){
                    console.log('Triggering exit');
                    exitFullScreen();
                }else {
                    console.log('Triggering fullscreen');
                    requestFullScreen(element);
                }
                });
});

// Add logos for the animated gifs
$(document).ready(function () {
	$(document).on('click', "#slider-graph", function () {
		const logos = document.getElementById('logos');
		if(!logos) {
			var img = new Image();
			img.src = './assets/images/logoline.png';
			img.style.position = 'absolute';
			img.style.width = '40rem';
			img.style.height = '5rem';
			img.style.top = '0';
			img.style.left = '23rem';
			img.style.zIndex = '999';
			img.setAttribute('id','logos');
			img.style.display = 'none';

			// Get the element to overlay the image on
			var div = document.querySelectorAll('.leaflet-map-pane')[0];

			// Append the image to the element
			div.appendChild(img);
		}
	});
});
