{% extends 'tags-layout.html' %}

{% from 'macros.html' import info_popover, visualize_metadata_value, visualize_score  %}

{% block menu %}
{{ prepare_menu('Metadata') }}
{% endblock %}

{% block tags_title %}
<h2 class="h4">Metadata</h2>
{% endblock %}

{% block tags_action %}
<a class="btn btn-primary" href="{{ url_for('prepare.metadata_audit_trail', seriesid=series.series_id) }}">Audit trail</a>
{% endblock %}

{% block tags_content %}

{% if metadata_score is not none %}
<div class="alert alert-info">
    <a href="{{ url_for('.show_checks', sourcename=source_name, seriesid=series.series_id) }}#metadata-checks">Metadata score</a>: {{ metadata_score }}%
</div>
{% endif %}

{% if metadata %}
<table class="ts-table table table-borderless">
    <thead class="thead-secondary">
        <tr class="border-top border-bottom">
            <th scope="col">Metadata</th>
            <th scope="col">Configured value</th>
            <th scope="col">Calculated value</th>
        </tr>
    </thead>
    <tbody>
        {% for k, v in metadata.iter_names() if metadata.is_shown(k) %}
        <tr class="border-bottom">
            <th scope="row">
                {{ k|capitalize }}
                {% if k in spec and spec.get_field(k) is not none %}
                {{ info_popover('Sensor spec manually updated.', 'plus-circle') }}
                {% endif %}
            </th>
            {{ visualize_metadata_value(k, v)}}
            <td>
                {% if analysis_state %}
                {% if calculated_metadata.get_field_by_name(k) is not none %}
                {% if k == 'process type' or k == 'data type' %}
                {{ calculated_metadata.get_field_by_name(k).value }}
                {% else %}
                {{ calculated_metadata.get_field_by_name(k)|numberformat }}
                {% endif %}
                {% else %}
                {% endif %}
                {% else %}
                -
                {% endif %}
            </td>
        </tr>
        {% endfor %}
    </tbody>
</table>

<p>Manually <a href="{{ url_for('sensor_specs.update_sensor_specs', seriesid=series.series_id) }}">enter</a> sensor specs.</p>
{% endif %}
{% endblock %}
