<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
$_helper = $this->helper('FiloBlu\Storelocator\Helper\Data');
?>

<script src="<?php echo $_helper->getConfig('filoblu_storelocator_section/general/gmaps_api_url') ?>?language=<?php echo explode("_", \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\Locale\Resolver')->getLocale())[0] ?>&key=<?php echo $_helper->getConfig('filoblu_storelocator_section/general/gmaps_api_key') ?><?php if ($_helper->getConfig('filoblu_storelocator_section/search/gmaps_search_autocomplete_enabled')): ?>&libraries=places <?php endif; ?>"></script>


<script>
    requirejs(["filoblustorelocator"], function () {
         window.FiloBlu.StoreLocator.initGMap({
            // gmap param
            center: {
                lat: parseFloat('<?php echo $_helper->getConfig('filoblu_storelocator_section/map_options/gmaps_default_center') ?>'.split(';')[0]),
                lng: parseFloat('<?php echo $_helper->getConfig('filoblu_storelocator_section/map_options/gmaps_default_center') ?>'.split(';')[1])
            },
            zoom: <?php echo $_helper->getConfig('filoblu_storelocator_section/map_options/gmaps_default_zoom') ?>,
            minZoom: <?php echo $_helper->getConfig('filoblu_storelocator_section/map_options/gmaps_min_zoom') ?>,
            maxZoom: <?php echo $_helper->getConfig('filoblu_storelocator_section/map_options/gmaps_max_zoom') ?>,
            mapContainerId: 'map',
            mapTypeId: '<?php echo $_helper->getConfig('filoblu_storelocator_section/map_options/gmaps_type') ?>',
<?php echo($_helper->getConfig('filoblu_storelocator_section/map_options/gmaps_style') ? $_helper->getConfig('filoblu_storelocator_section/map_options/gmaps_style') . "," : "") ?>
            zoomControl: <?php echo($_helper->getConfig('filoblu_storelocator_section/map_options/gmaps_ui_zoomControl_enabled') ? "true" : "false") ?>,
            mapTypeControl: <?php echo($_helper->getConfig('filoblu_storelocator_section/map_options/gmaps_ui_mapTypeControl_enabled') ? "true" : "false") ?>,
            streetViewControl: <?php echo($_helper->getConfig('filoblu_storelocator_section/map_options/gmaps_ui_streetViewControl_enabled') ? "true" : "false") ?>,
            rotateControl: <?php echo($_helper->getConfig('filoblu_storelocator_section/map_options/gmaps_ui_rotateControl_enabled') ? "true" : "false") ?>,
            scaleControl: <?php echo($_helper->getConfig('filoblu_storelocator_section/map_options/gmaps_ui_scaleControl_enabled') ? "true" : "false") ?>,
            fullscreenControl: <?php echo($_helper->getConfig('filoblu_storelocator_section/map_options/gmaps_ui_fullscreenControl_enabled') ? "true" : "false") ?>,
            listShopDetails: <?php echo($_helper->getConfig('filoblu_storelocator_section/general/shop_details') ? "true" : "false") ?>,
            // custom params
            gmapApiUrl: '<?php echo $_helper->getConfig('filoblu_storelocator_section/general/gmaps_api_url') ?>',
            gmapGeolocationApiUrl: '<?php echo $_helper->getConfig('filoblu_storelocator_section/geolocation/gmaps_geolocation_api_url') ?>',
            gmapApiKey: '<?php echo $_helper->getConfig('filoblu_storelocator_section/general/gmaps_api_key') ?>',
            gmapLanguage: '<?php echo explode("_", \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\Locale\Resolver')->getLocale())[0] ?>',
            // geolocation
            gmapGeoLocation: <?php echo($_helper->getConfig('filoblu_storelocator_section/geolocation/gmaps_geolocation_enabled') ? "true" : "false") ?>,
            gmapGeoLocationZoom: <?php echo $_helper->getConfig('filoblu_storelocator_section/geolocation/gmaps_geolocation_zoom') ?>,
            gmapGeoLocationMarker: <?php echo($_helper->getConfig('filoblu_storelocator_section/geolocation/gmaps_geolocation_marker_enabled') ? "true" : "false") ?>,
            gmapGeoLocationMarkerAnimation: <?php echo($_helper->getConfig('filoblu_storelocator_section/geolocation/gmaps_geolocation_marker_animation_enabled') ? "true" : "false") ?>,
            gmapGeoLocationMarkerImage: '<?php echo($_helper->getConfig('filoblu_storelocator_section/geolocation/gmaps_geolocation_marker_image') ? $this->getBaseUrlConfigImage() . $_helper->getConfig('filoblu_storelocator_section/geolocation/gmaps_geolocation_marker_image') : "") ?>',
            gmapGeoLocationDistance: <?php echo($_helper->getConfig('filoblu_storelocator_section/geolocation/gmaps_geolocation_distance_enabled') ? "true" : "false") ?>,
            gmapGeoLocationDuration: <?php echo($_helper->getConfig('filoblu_storelocator_section/geolocation/gmaps_geolocation_duration_enabled') ? "true" : "false") ?>,
            gmapGeoLocationTravelMode: '<?php echo $_helper->getConfig('filoblu_storelocator_section/geolocation/gmaps_geolocation_travelmode') ?>',
            gmapGeoLocationUnitSystem: <?php echo $_helper->getConfig('filoblu_storelocator_section/geolocation/gmaps_geolocation_unitsystem') ?>,
            gmapGeoLocationGetDirections: <?php echo($_helper->getConfig('filoblu_storelocator_section/geolocation/gmaps_geolocation_getdirections_enabled') ? "true" : "false") ?>,
            gmapGeoLocationGetDirectionsPanelId: 'gmapGetDirectionsPanel',
            gmapMarkersMarkerImage: '<?php echo($_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_marker_image') ? $this->getBaseUrlConfigImage() . $_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_marker_image') : "") ?>',
            gmapStoresImageDir: '<?php echo $this->getBaseUrlStoresImage() ?>',
            // cluster
            gmapMarkersClusterMarker: <?php echo($_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_cluster_marker_enabled') ? "true" : "false") ?>,
            gmapMarkersClusterMarkerGridSize: <?php echo $_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_cluster_marker_gridSize') ?>,
            gmapMarkersClusterMarkerMaxZoom: <?php echo($_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_cluster_marker_maxZoom') ? $_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_cluster_marker_maxZoom') : "null") ?>,
            gmapMarkersClusterMarkerZoomOnClick: <?php echo($_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_cluster_marker_zoomOnClick') ? "true" : "false") ?>,
            gmapMarkersClusterMarkerAverageCenter: <?php echo($_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_cluster_marker_averageCenter') ? "true" : "false") ?>,
            gmapMarkersClusterMarkerMinimumClusterSize: <?php echo $_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_cluster_minimumClusterSize') ?>,
            gmapMarkersClusterMarkerImage: '<?php echo($_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_cluster_image') ? $this->getBaseUrlConfigImage() . $_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_cluster_image') : $this->getViewFileUrl('FiloBlu_Storelocator::images/cluster_marker.png')) ?>',
            gmapMarkersClusterMarkerImageWidth: <?php echo $_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_cluster_image_width') ?>,
            gmapMarkersClusterMarkerImageHeight: <?php echo $_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_cluster_image_height') ?>,
            gmapMarkersClusterMarkerTextColor: '<?php echo $_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_cluster_textColor') ?>',
            gmapMarkersClusterMarkerTextSize: <?php echo $_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_cluster_textSize') ?>,
            gmapMarkersClusterMarkerTextOffsetWidth: <?php echo $_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_cluster_text_offsetWidth') ?>,
            gmapMarkersClusterMarkerTextOffsetHeight: <?php echo $_helper->getConfig('filoblu_storelocator_section/markers/gmaps_markers_cluster_text_offsetHeight') ?>,
            // search
            gmapSearchAutocomplete: <?php echo($_helper->getConfig('filoblu_storelocator_section/search/gmaps_search_autocomplete_enabled') ? "true" : "false") ?>,
            gmapSearchAutocompleteId: 'gmapSearch',
            gmapSearchAutocompleteType: '<?php echo $_helper->getConfig('filoblu_storelocator_section/search/gmaps_search_autocomplete_type') ?>',
            gmapSearchAutocompleteZoom: <?php echo $_helper->getConfig('filoblu_storelocator_section/search/gmaps_search_autocomplete_zoom') ?>,
            gmapSearchCountryId: 'gmapCountry',
            gmapSearchRegionId: 'gmapRegion',
            gmapSearchCityId: 'gmapCity',
            gmapSearchCountry: <?php echo($_helper->getConfig('filoblu_storelocator_section/search/gmaps_search_country_enabled') ? "true" : "false") ?>,
            gmapSearchCity: <?php echo($_helper->getConfig('filoblu_storelocator_section/search/gmaps_search_city_enabled') ? "true" : "false") ?>,
             gmapSearchRegion: <?php echo($_helper->getConfig('filoblu_storelocator_section/search/gmaps_search_region_enabled') ? "true" : "false") ?>,
            gmapSearchTags: <?php echo($_helper->getConfig('filoblu_storelocator_section/search/gmaps_search_tag_enabled') ? "true" : "false") ?>,
            gmapSearchTagsContainerClass: 'tag-info',
            // stores list
            gmapStoresListId: 'gmapStoresList',
            // stores list
            gmapWorkingTimes: <?php echo($_helper->getConfig('filoblu_storelocator_section/workingtimes/gmaps_working_times_enabled') ? "true" : "false") ?>,

            baseUrl: '<?php echo $this->getBaseUrl(); ?>'
        });
    });
</script>
