<?php
if ($this->Map_Map_isGdprConsentRequired()) {
    echo $this->Map_Map_gdprConsentForm();
    return;
}
$this->Entity_Display_preRenderbyBundle($bundle->name, [], $settings['display']);
// Show map centered at searched location if any
if (isset($search_values['drts_search_location_address'])) {
    $search_value = $search_values['drts_search_location_address'];
    if (!empty($search_value['center'])
        && ($center = explode(',', $search_value['center']))
        && count($center) === 2
    ) {
        $settings['map']['default_location'] = ['lat' => $center[0], 'lng' => $center[1]];
    }
}
?>
<script type="text/javascript">
<?php if (\SabaiApps\Directories\Request::isXhr()):?>
jQuery(function($) {
<?php else:?>
document.addEventListener('DOMContentLoaded', function() {
    var $ = jQuery;
<?php endif;?>
    var settings = <?php echo $this->System_Util_jsonEncode($settings['map']);?>;
    var map = DRTS.Map.api.getMap('<?php echo $CONTEXT->getContainer();?>', settings);
    var params = <?php $url_params[\SabaiApps\Directories\Request::PARAM_CONTENT_TYPE] = 'json'; echo json_encode($url_params);?>;
    var fullmap = new DRTS.Map.fullmap(map, {
        url: '<?php echo $this->Url($CONTEXT->getRoute());?>',
        params: params,
        debounceDelay: <?php echo intval($settings['map_debounce_delay']);?>,
        minZoomForUpdate: <?php echo intval($settings['map_min_zoom_for_update']);?>,
        labelFullscreen: '<?php echo $this->H(__('Full screen', 'directories-pro')); ?>',
        labelExitFullscreen: '<?php echo $this->H(__('Exit full screen', 'directories-pro')); ?>',
        labelZoomIn: '<?php echo $this->H(__('Zoom in to load more markers', 'directories-pro')); ?>',
        labelGeolocationNotSupported: '<?php echo $this->H(__('Geolocation is not supported by this browser.', 'directories-pro')); ?>',
    });
});
</script>
<div class="drts-map-container">
    <?php $this->Action('map_before_map', [$CONTEXT]);?>
    <div class="drts-map-map drts-map-map-with-height" style="height:<?php echo intval($settings['map_height']);?>px;" data-height="<?php echo intval($settings['map_height']);?>px"></div>
    <?php $this->Action('map_after_map', [$CONTEXT]);?>
</div>