{% load combo gnm l10n assets %}
{% with lieu_d_accueil=json is_place_page=page|is_place_page place_page=cell|place_page %}
  {% get_tile_picture_size page as size %}
  <div class="tile lieu-d-accueil {% if is_place_page %}is-place{% endif %}" data-place-type="lieu-d-accueil" data-tile-cache="300">
    {% if is_place_page %}
      {% placeholder "infos-pratiques" name="Infos pratiques" render=False %}
      {% placeholder "galerie" name="Galerie photos" render=False %}
      <div class="tile-picture" style="background-image: url({% asset_url place_page.picture "picture:banner:lieu-d-accueil" size=size crop="center" %})"></div>
    {% else %}
      <div class="tile-picture" style="background-image: url({% asset_url place_page.picture "picture:lieu-d-accueil" size=size crop="center" %})"></div>
    {% endif %}
    <div class="tile-head">
      <div class="tile-title">
        <h2>{{ json.fields.nom_lal }}</h2>
        <span class="producer" style="background-image: url({% asset_url "logo:toodego" %})">Toodego</span>
      </div>
    </div>
    {% if is_place_page %}
      <div class="tile-content">

        <div class="place-info">
          {% include "combo/json/includes/share.html" with place=lieu_d_accueil url=cell|place_page_url %}
          {% placeholder "infos-pratiques" %}
        </div>

        <div class="place-data">
          <div class="adresse">
            <h3>Adresse</h3>
            <div>
              {{ lieu_d_accueil.fields.numero }} {{ lieu_d_accueil.fields.voie }}<br>
              {{ lieu_d_accueil.fields.postcode }} {{ lieu_d_accueil.fields.ville }}
            </div>

            {% localize off %}
              <a class="action-goto" data-lat="{{lieu_d_accueil.geolocations.base.lat}}" data-lng="{{lieu_d_accueil.geolocations.base.lon}}" href="/m-y-rendre/?to={{cell.id}}">M’y rendre</a>
            {% endlocalize %}
          </div>

          {% if lieu_d_accueil.fields.telephone_structure %}
            <div class="phone">
              <h3>Téléphone</h3>
              <div>{{ lieu_d_accueil.fields.telephone_structure }}</div>
              <a class="action-call" href="tel:{{lieu_d_accueil.fields.telephone_structure}}">Appeler</a>
            </div> <!-- phone -->
          {% endif %}

          {% include "combo/json/includes/horaires.html" with place=lieu_d_accueil %}

          {% if lieu_d_accueil.fields.horaire_rdv_conseil_raw and "LAL 2" in json.fields.niveau_service_raw %}
            <div class="horaires horaires-rdv">
              <h3>Horaires de prise de rendez-vous</h3>
              {% get_mairie_opening_hours lieu_d_accueil card_field="horaire_rdv_conseil_raw" as opening_hours %}
              <table class="horaires">
                {% for day, hours in opening_hours %}
                  <tr><th>{{day}}</th><td>{{hours.am|default_if_none:"fermé"}}</td><td>{{hours.pm|default_if_none:"fermé"}}</td></tr>
                {% endfor %}
              </table>

              <div>
                <a class="pk-button" href="{{ eservices_url }}logement-social-prise-de-rdv/?id_lieu={{ json.id }}"
                >Prendre un rendez-vous</a>
              </div>

            </div>
          {% endif %}
        </div>

        {% gnm_place_map lieu_d_accueil.geolocations.base.lat lieu_d_accueil.geolocations.base.lon %}
        {% placeholder "galerie" %}

      </div>
    {% else %}
      {% include "combo/dashboard_cell_icons.html" %}
      <div class="tile-content">
        {% if "LAL 1" in json.fields.niveau_service_raw %}<div>Première information</div>{% endif %}
        {% if "LAL 2" in json.fields.niveau_service_raw %}
          <div><a class="pk-button" href="{{ eservices_url }}logement-social-prise-de-rdv/?id_lieu={{ json.id }}"
          >Prendre un rendez-vous</a></div>
        {% endif %}
      </div>
      <div class="tile-actions">
        {% localize off %}
          <a class="action-goto" data-lat="{{lieu_d_accueil.geolocations.base.lat}}" data-lng="{{lieu_d_accueil.geolocations.base.lon}}" href="/m-y-rendre/?to={{cell.id}}">M’y rendre</a>
        {% endlocalize %}
        <a class="action-more-info" href="{{cell|place_page_url}}{{ json.id }}/">d’infos</a>

      </div>
    {% endif %}
  </div>
{% endwith %}
