{% load humanize madlibs comparatives stats %}

{% if not stat_wrapper == 'false' %}<a class="stat {{ stat_type }}{% if wrapper_class %} {{ wrapper_class }}{% endif %}">{% endif %}
    <span class="{% if stat_class %}{{ stat_class }}{% else %}primary{% endif %}">
        <span class="value">
            {% if not stat.values.this %}
                {{ HURUMAP.na_label }}
            {% else %}
                {% if stat_type == 'name' %}
                    {{ stat.name }}
                {% else %}
                    {% statvalue stat.values.this %}
                    {% if stat_suffix %} <span class="stat-suffix">{{ stat_suffix }}</span>{% endif %}
                {% endif %}
                {% if stat.error.this_ratio >= 10 %}<sup>&dagger;</sup>{% endif %}
            {% endif %}

            {% if not stat_class == 'secondary' %}
                {% if stat.error.this %}
                    <span class="context moe">&plusmn;{% statvalue stat.error.this %}</span>
                {% endif %}

                {% if stat.numerators.this %}
                <span class="context">({% statvalue stat.numerators.this isnumerator=True %}{% if stat.numerator_error.this %}&nbsp;&nbsp;&plusmn;{% statvalue stat.numerator_errors.this isnumerator=True %}{% endif %})</span>
                {% endif %}
            {% endif %}
        </span>
        <span class="name">{% if stat_type == 'name' %}{{ stat_name }}{% else %}{{ stat.name }}{% endif %}</span>

        {% if stat_class == 'secondary' %}
            <span class="context">
                {% if stat.error.this %}
                    &plusmn;{% statvalue stat.error.this %}
                {% endif %}

                {% if stat.numerators.this %}
                <span class="push-right">({% statvalue stat.numerators.this isnumerator=True %}{% if stat.numerator_error.this %}&nbsp;&nbsp;&plusmn;{% statvalue stat.numerator_errors.this isnumerator=True %}{% endif %})</span>
                {% endif %}
            </span>
        {% endif %}
    </span>

    {% if geography.comparatives and stat.values.this and not stat_class == 'secondary' %}
    <ul class="context-phrases">
        {% for sumlev in geography.comparatives %}
            {% build_comparative_item sumlev stat stat_type geography decimals %}
        {% endfor %}
    </ul>
    {% endif %}
{% if not stat_wrapper == 'false' %}</a>{% endif %}
