<div class="warning" id="kumascript-errors">
<p>
{{ ngettext(
  'There was a scripting error on this page. While it is being addressed by site editors, you can view partial content below.',
  'There were scripting errors on this page. While those are being addressed by site editors, you can view partial content below.',
  kumascript_errors|count)
}}

</p>
{% if request.user.is_authenticated() %}
  <button type="button" class="kumascript-detail-toggle" data-alternate-message="{{ _('Hide error information') }}">
    {{ ngettext(
      'More information about this error',
      'More information about these errors',
      kumascript_errors|count)
    }}
  </button>
  <div class="kumascript-details hidden">
      <p>{% trans %}
        Anyone with an MDN profile can edit a document to fix an error. Use the <a href="/docs/MDN/Kuma/Troubleshooting_KumaScript_errors">KumaScript troubleshooting guide</a> as a starting point.
      {% endtrans %}</p>

      <ul>
      {% for error in kumascript_errors %}
        <li>
            {% if error.args %}
                {% set error_type = error.args[0] %}
                {{ _('Error type:') }} <strong class="type">{{ error_type }}</strong><br>

                {% set error_meta = error.args[2] %}
                {% if error_meta %}
                    {% set template_name = error_meta.name %}

                    {% if '$' not in template_name %}
                        {% set template_slug = 'Template:{name}' | f(name=template_name) %}
                        {% set edit_url = url('wiki.edit_document', template_slug) %}
                        {% set new_url = url('wiki.new_document') + '?slug=Template:{name}' | f(name=template_name) %}
                    {% endif %}

                    {{ _('In macro:') }} <code>{{ template_name }}</code>

                    {% if 'status 404' in error.message %}
                        {% if new_url %}
                            (<a href="{{ new_url }}">{{ _('Create Template') }}</a>)
                        {% endif %}
                    {% elif edit_url  %}
                        (<a href="{{ edit_url }}">{{ _('Edit Template') }}</a>)
                    {% endif %}<br>

                    {{ _('Parsing macro:') }} <code>{{ template_name }}({% if error_meta.token %}{{ error_meta.token.args }}{% endif %})</code> (<a href="{{ url('wiki.edit_document', document.slug) }}">{{ _('Edit Document') }}</a>)<br>
                {% endif %}
            {% endif %}

            {{ _('Full text of error:') }}<br>
            <pre class="message brush: text">{{ error.message }}</pre>
        </li>
      {% endfor %}
      </ul>
  </div>
{% endif %}
</div>
