{% extends "generic/object.html" %}
{% load helpers %}
{% load plugins %}
{% load tz %}
{% load i18n %}
{% load l10n %}


{% block breadcrumbs %}
  {% include 'sop_phone/tools/breadcrumbs.html' with name=object|meta:"verbose_name"|bettertitle %}
{% endblock %}


{% block title %}{{object.name|bettertitle}}{% endblock %}


{% block content %}
<div class="row">
  <div class="col col-md-6">
    <div class="card">

      <h5 class="card-header">{{object|meta:"verbose_name"|bettertitle}}</h5>
      <table class="table table-hover attr-table">

        <tr>
          <th scope="row">{% trans "Name" %}</th>
            <td>
              {{ object.name }}
            </td>
        </tr>

        <tr>
          <th scope="row">{% trans "Status" %}</th>
          <td>
            {% badge object.get_status_display bg_color=object.get_status_color %}
          </td>

        <tr>
          <th scope="row">{% trans "Description" %}</th>
          <td>
            {{object.description|placeholder}}
          </td>
        </tr>

        <tr>
          <th scope="row">{% trans "Phone numbers maintained" %}</th>
            <td>
              {{num_did}} number(s)
            </td>
        </tr>

<!--_______________________________________________
    litterally like /dcim/site.html NetBox template
    -->
        <tr>
          <th scope="row">{% trans "Time Zone" %}</th>
          <td>
            {% if object.time_zone %}
              {{ object.time_zone }} ({% trans "UTC" %} {{ object.time_zone|tzoffset }})<br />
              <small class="text-muted">{% trans "Site time" %}: {% timezone object.time_zone %}{% now 'Y-m-d H:i' %}{% endtimezone %}</small>
            {% else %}
              {{ ''|placeholder }}
            {% endif %}
          </td>
        </tr>

        <tr>
          <th scope="row">{% trans "Physical Address" %}</th>
          <td class="d-flex justify-content-between align-items-start">
            {% if object.physical_address %}
              <span>{{ object.physical_address|linebreaksbr }}</span>
              {% if config.MAPS_URL %}
                <a href="{{ config.MAPS_URL }}{{ object.physical_address|urlencode }}" target="_blank" class="btn btn-primary btn-sm d-print-none">
                  <i class="mdi mdi-map-marker"></i> {% trans "Map" %}
                </a>
              {% endif %}
            {% else %}
              {{ ''|placeholder }}
            {% endif %}
          </td>
        </tr>

        <tr>
          <th scope="row">{% trans "Shipping Address" %}</th>
          <td class="d-flex justify-content-between align-items-start">
            {% if object.shipping_address %}
              <span>{{ object.shipping_address|linebreaksbr }}</span>
              {% if config.MAPS_URL %}
                <a href="{{ config.MAPS_URL }}{{ object.shipping_address|urlencode }}" target="_blank" class="btn btn-primary btn-sm d-print-none">
                  <i class="mdi mdi-map-marker"></i> {% trans "Map" %}
                </a>
              {% endif %}
            {% else %}
              {{ ''|placeholder }}
            {% endif %}
          </td>
        </tr>

        <tr>
          <th scope="row">{% trans "GPS Coordinates" %}</th>
          <td class="position-relative">
            {% if object.latitude and object.longitude %}
              {% if config.MAPS_URL %}
                <div class="position-absolute top-50 end-0 me-2 translate-middle-y d-print-none">
                  <a href="{{ config.MAPS_URL }}{{ object.latitude|unlocalize }},{{ object.longitude|unlocalize }}" target="_blank" class="btn btn-primary btn-sm">
                    <i class="mdi mdi-map-marker"></i> {% trans "Map" %}
                  </a>
                </div>
                {% endif %}
              <span>{{ object.latitude }}, {{ object.longitude }}</span>
            {% else %}
              {{ ''|placeholder }}
            {% endif %}
          </td>
        </tr>
<!--_______________________________________________
-->

        
      </table>
    </div>
    
    {% include 'inc/panels/comments.html' %}

  </div>

  <div class="col col-md-6">
  
    <!-- __________________________________________________
      related objects inc/panels/related_objects.html
    -->
    <div class="card">
      <h2 class="card-header">{% trans "Related Objects" %}</h2>
      <ul class="list-group list-group-flush" role="presentation">
        {% for qs, filter_param in related_models %}
          {% with viewname=qs.model|validated_viewname:"list" %}
            {% if viewname is not None %}

            <!-- __________________________________________________
              i just added theses lines to link the site ids 
            -->
              {% if qs.model|meta:"verbose_name_plural"|bettertitle == "Sites" and site_ids %}
                <a href="/dcim/sites/?{% for site_id in site_ids %}id={{site_id.site__id}}{% if not forloop.last %}&{% endif %}{% endfor %}"
                class="list-group-item list-group-item-action d-flex justify-content-between">
              {% else %}
            <!-- this is the original </a> for all others params -->
              <a href="{% url viewname %}?{{ filter_param }}={{ object.pk }}" class="list-group-item list-group-item-action d-flex justify-content-between">
            <!-- __________________________________________________
              and the endif token
            -->
              {% endif %}
            <!--__________________________________________________-->
              {{ qs.model|meta:"verbose_name_plural"|bettertitle }}
              {% with count=qs.count %}
                {% if count %}
                  <span class="badge text-bg-primary rounded-pill">{{ count }}</span>
                {% else %}
                  <span class="badge text-bg-light rounded-pill">&mdash;</span>
                {% endif %}
              {% endwith %}
            </a>
            {% endif %}
          {% endwith %}
        {% endfor %}
      </ul>
    </div>


  </div>

  {% if site %}
  <div class="col col-md-12">
    <div class="card">
      
      <h2 class="card-header">
        <a href="{% url site|viewname:"list" %}?site_id={{restricted}}">{{site|meta:"verbose_name_plural"|bettertitle}}</a>
      </h2>
    

      {% if restricted %}
      <div class="htmx-container table-responsive"
        hx-get="{% url site|viewname:"list" %}?embedded=True&{{restricted}}"
        hx-target="this"
        hx-trigger="load" hx-select=".htmx-container" hx-swap="outerHTML"
      ></div>
      {% endif %}

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

</div>

{% endblock content %}
