{% from 'macros.j2.html' import import_information_symbol %}

<div class="hidden"  id="related-objects-entries" data-sampledb-root-object-index="{{ related_objects_index_by_object_ref[object_ref] }}">
{% for current_object_ref, subtree in related_objects_subtrees.items() %}
  {% set referenced_objects = [] %}
  {% for referenced_object_ref in subtree.referenced_objects %}
    {% do referenced_objects.append(related_objects_index_by_object_ref[referenced_object_ref]) %}
  {% endfor %}
  {% set referencing_objects = [] %}
  {% for referencing_object_ref in subtree.referencing_objects %}
    {% do referencing_objects.append(related_objects_index_by_object_ref[referencing_object_ref]) %}
  {% endfor %}
  {% set object = related_object_by_object_ref.get(current_object_ref) %}
  {% set object_name = object.name | get_translated_text('–') if object is not none and object.name is not none else '–' %}
  {% set object_id = current_object_ref.object_id or '–' %}
  <span id="related-objects-entry-{{ related_objects_index_by_object_ref[current_object_ref] }}" data-sampledb-object-index="{{ related_objects_index_by_object_ref[current_object_ref] }}" data-sampledb-referenced-objects="{{ referenced_objects | tojson }}" data-sampledb-referencing-objects="{{ referencing_objects | tojson }}" {% if current_object_ref.is_local %}data-sampledb-is-local="true" data-sampledb-object-name="{{ object_name }}" data-sampledb-object-id="{{ object.object_id }}"{% endif %}>
    {% if current_object_ref.is_local %}
      <a href="{{ url_for('.object', object_id=current_object_ref.object_id) }}">{{ object_name }} &bullet; #{{ current_object_ref.object_id }}</a>
      {% if object is not none %}
        {{ import_information_symbol(object) }}
      {% endif %}
    {% elif current_object_ref.component_uuid is not none %}
      {% if current_object_ref.component_uuid != config['FEDERATION_UUID'] %}
        {% set object_ref = FederationObjectRef(fed_id=current_object_ref.object_id, component_uuid=current_object_ref.component_uuid) %}
        #{{ current_object_ref.object_id }} @ {{ object_ref.component.get_name() }}
        {{ import_information_symbol(object_ref) }}
      {% else %}
        <a href="{{ url_for('frontend.object', object_id=current_object_ref.object_id) }}">#{{  current_object_ref.object_id }}</a>
      {% endif %}
    {% else %}
      {% if current_object_ref.eln_object_url %}
        <a href="{{ current_object_ref.eln_object_url }}">
      {% endif %}
      {{ _('Object') }} #{{ current_object_ref.object_id }} @
      {% if not current_object_ref.eln_object_url %}
        <a href="{{ current_object_ref.eln_source_url }}">
      {% endif %}
      {{ current_object_ref.eln_source_url }}
      </a>
    {% endif %}
  </span>
{% endfor %}
</div>
