{% extends '@bazar/entries/index-dynamic.twig' %}

{% set necessary_fields = (params.necessary_fields|default([]))|merge ([ params.geolocationfield ]) %}

{% block assets %}
  {{ include_css('styles/vendor/leaflet/leaflet.css') }}
  {{ include_css('styles/vendor/leaflet-markercluster/leaflet.markercluster.css') }}
  {{ include_css('styles/vendor/leaflet-fullscreen/leaflet-fullscreen.css') }}
  {{ include_javascript('javascripts/vendor/leaflet-draw/leaflet.draw.css') }}

  {{ include_css('tools/bazar/presentation/styles/bazarcarto.css') }}

  {{ include_javascript('javascripts/vendor/leaflet/leaflet.min.js') }}
  {{ include_javascript('javascripts/vendor/leaflet-markercluster/leaflet-markercluster.min.js') }}
  {{ include_javascript('javascripts/vendor/leaflet-providers/leaflet-providers.js') }}
  {{ include_javascript('javascripts/vendor/leaflet-fullscreen/leaflet-fullscreen.js') }}
  {{ include_javascript('tools/bazar/libs/vendor/leaflet/ajax/dist/leaflet.ajax.min.js') }}
  {{ include_javascript('javascripts/vendor/vue2-leaflet/vue2-leaflet.js') }}

  {{ include_javascript('javascripts/vendor/leaflet-draw/leaflet.draw.js') }}
  {{ include_javascript('tools/bazar/presentation/javascripts/components/BazarMap.js', false, true) }}

{% endblock %}

{% block display_entries %}
  <Bazar-Map :params="params" class="bazar-map">
    {% if params.entrydisplay == 'popup' %}
      {% set templateName = (params.popuptemplate == 'custom') ? (params.popupcustomtemplate ?? '_map_popup_html.twig') : (params.popuptemplate ?? '_map_popup_html.twig') %}
      {% set templateName = templateName|slice(-5) != '.twig' ? templateName ~ '.twig' : templateName %}
      {{ include("@bazar/entries/index-dynamic-templates/#{templateName}") }}
    {% endif %}
  </Bazar-Map>
{% endblock %}
