{% extends 'jsondataferret/base.html' %}

{% block breadcrumbs %}
    <nav aria-label="breadcrumb">
      <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="{% url 'jsondataferret_index' %}">Home</a></li>
        <li class="breadcrumb-item"><a href="{% url 'jsondataferret_type_list' %}">Types</a></li>
        <li class="breadcrumb-item"><a href="{% url 'jsondataferret_type_index' public_id=type.public_id %}">Type {{ type.title }}</a></li>
        <li class="breadcrumb-item active" aria-current="page">Record {{ record.public_id }}</li>
      </ol>
    </nav>
{% endblock %}

{% block content %}

<h2>Type {{ type.title }} record {{ record.public_id }}</h2>


{% with fields_to_list=record.get_cached_data_fields %}
    <ul class="nav nav-tabs" role="tablist">
        <li class="nav-item active">
            <a class="nav-link active" href="#data-json" data-toggle="tab">JSON</a>
        </li>
        {% if fields_to_list %}
        <li class="nav-item">
            <a class="nav-link" href="#data-fields" data-toggle="tab">Fields</a>
        </li>
        {% endif %}
        {% if record.cached_jsonschema_validation_errors or record.cached_exists %}
        <li class="nav-item">
            <a class="nav-link" href="#data-json-validation" data-toggle="tab">
                JSON Validation
                {% if record.cached_jsonschema_validation_errors %}
                    <i class="fas fa-times-circle" style="color: red;"></i>
                {% else %}
                    <i class="fas fa-check-circle" style="color: green;"></i>
                {% endif %}
            </a>
        </li>
        {% endif %}
    </ul>
    <div class="tab-content ">
        <div class="tab-pane fade show active" id="data-json">
            <p>{{ record.get_cached_data_html | safe }}</p>
        </div>
        {% if fields_to_list %}
            <div class="tab-pane fade" id="data-fields">
                <table class="table">
                    {% for field_data in fields_to_list %}
                        <tr><th>{{ field_data.title }}</th><td>{{ field_data.value }}</td></tr>
                    {% endfor %}
                </table>
            </div>
        {% endif %}
        {% if record.cached_jsonschema_validation_errors or record.cached_exists %}
            <div class="tab-pane fade" id="data-json-validation">
                {% if record.cached_jsonschema_validation_errors %}
                    <table class="table">
                        <tr>
                            <th>Message</th>
                            <th>Data Path</th>
                            <th>Schema Path</th>
                        </tr>
                        {% for err in record.cached_jsonschema_validation_errors %}
                            <tr>
                                <td>
                                    {{ err.message }}
                                </td>
                                <td>
                                    {{ err.path_str }}
                                </td>
                                <td>
                                    {{ err.schema_path_str }}
                                </td>

                            </tr>
                        {% endfor %}
                    </table>
                {% else %}
                    <p>JSON Validation passed <i class="fas fa-smile"></i></p>
                {% endif %}
            </div>
        {% endif %}
    </div>
{% endwith %}

{% if json_schema_available %}
    <p><a href="{% url 'jsondataferret_record_edit_json_schema' type_id=type.public_id record_id=record.public_id %}" class="btn btn-primary">Edit</a></p>
{% endif %}
{% if download_form_available %}
    <p><a href="{% url 'jsondataferret_record_download_form' type_id=type.public_id record_id=record.public_id %}" class="btn btn-primary">Download as Spreadsheet</a></p>
    <p><a href="{% url 'jsondataferret_record_import_form' type_id=type.public_id record_id=record.public_id %}" class="btn btn-primary">Import Spreadsheet</a></p>
{% endif %}
<p><a href="{% url 'jsondataferret_record_moderate' type_id=type.public_id record_id=record.public_id %}" class="btn btn-primary">Moderate</a></p>
<p><a href="{% url 'jsondataferret_record_event_list' type_id=type.public_id record_id=record.public_id %}" class="btn btn-primary">Events</a></p>

{% endblock %}
