{% load helpers %}

{% with custom_fields=object.get_custom_fields %}
    {% if custom_fields %}
        <div class="card">
            <h5 class="card-header">Custom Fields</h5>
            <div class="card-body">
                <table class="table table-hover attr-table">
                    {% for field, value in custom_fields.items %}
                        <tr>
                            <td>
                              <span title="{{ field.description|escape }}">{{ field }}</span>
                            </td>
                            <td>
                                {% if field.type == 'integer' and value is not None %}
                                    {{ value }}
                                {% elif field.type == 'longtext' and value %}
                                    {{ value|markdown }}
                                {% elif field.type == 'boolean' and value == True %}
                                    {% checkmark value true="True" %}
                                {% elif field.type == 'boolean' and value == False %}
                                    {% checkmark value false="False" %}
                                {% elif field.type == 'url' and value %}
                                    <a href="{{ value }}">{{ value|truncatechars:70 }}</a>
                                {% elif field.type == 'json' and value %}
                                    <pre>{{ value|json }}</pre>
                                {% elif field.type == 'multiselect' and value %}
                                    {{ value|join:", " }}
                                {% elif field.type == 'object' and value %}
                                    <a href="{{ value.get_absolute_url }}">{{ value }}</a>
                                {% elif field.type == 'multiobject' and value %}
                                    <ul>
                                      {% for obj in value %}
                                        <li><a href="{{ obj.get_absolute_url }}">{{ obj }}</a></li>
                                      {% endfor %}
                                    </ul>
                                {% elif value %}
                                    {{ value }}
                                {% elif field.required %}
                                    <span class="text-warning">Not defined</span>
                                {% else %}
                                    <span class="text-muted">&mdash;</span>
                                {% endif %}
                            </td>
                        </tr>
                    {% endfor %}
                </table>
            </div>
        </div>
    {% endif %}
{% endwith %}
