{% extends "issues/base.html" %}
{% load static %}
{% load stricter_templates %}
{% load humanize %}

{% block tab_content %}

<div class="flex">
    <div class="overflow-hidden">
        <div class="italic text-ellipsis whitespace-nowrap overflow-hidden">{{ event.ingested_at|date:"j M G:i T" }} (Event {{ event.digest_order|intcomma }} of {{ issue.digested_event_count|intcomma }} total{% if q %} — {{ event_qs_count|intcomma }} found by search{% endif %})</div>
    </div>

    <div class="ml-auto flex-none">
        <div class="flex place-content-end">
            {% include "issues/_event_nav.html" %}
        </div>
    </div>
</div>


{# NOTE if we store event.grouper on the event, we could also show that here #}

<h1 id="key-info" class="text-2xl font-bold mt-4">Key info</h1>

<div class="mb-6">
    {% for key, value in key_info %}
        <div class="flex {% if forloop.first %}border-slate-300 dark:border-slate-600 border-t-2{% endif %}">
            <div class="w-1/4 {% if not forloop.last %}border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %}">{{ key }}</div>
            <div class="w-3/4 {% if not forloop.last %} border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %} font-mono">{{ value|linebreaks }}</div>
        </div>
    {% endfor %}
</div>

{% if logentry_info %}
    <h1 id="logentry" class="text-2xl font-bold mt-4">Log Entry</h1>

    <div class="mb-6">
        {% for key, value in logentry_info %}
            <div class="flex {% if forloop.first %}border-slate-300 dark:border-slate-600 border-t-2{% endif %}">
                <div class="w-1/4 {% if not forloop.last %}border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %}">{{ key }}</div>
                <div class="w-3/4 {% if not forloop.last %} border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %} font-mono">{{ value|linebreaks }}</div>
            </div>
        {% endfor %}
    </div>
{% endif %}


{% if deployment_info %}
    <h1 id="deployment" class="text-2xl font-bold mt-4">Deployment</h1>

    <div class="mb-6">
        {% for key, value in deployment_info %}
            <div class="flex {% if forloop.first %}border-slate-300 dark:border-slate-600 border-t-2{% endif %}">
                <div class="w-1/4 {% if not forloop.last %}border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %}">{{ key }}</div>
                <div class="w-3/4 {% if not forloop.last %} border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %} font-mono">{{ value|linebreaks }}</div>
            </div>
        {% endfor %}
    </div>
{% endif %}

{% if event.get_tags %}
    <h1 id="tags" class="text-2xl font-bold mt-4">Tags</h1>

    <div class="mb-6">
        {% for tag in event.get_tags %}
            <div class="flex {% if forloop.first %}border-slate-300 dark:border-slate-600 border-t-2{% endif %}">
                <div class="w-1/4 {% if not forloop.last %}border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %}">{{ tag.value.key.key }}</div>
                <div class="w-3/4 {% if not forloop.last %} border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %} font-mono">{{ tag.value.value|linebreaks }}</div>
            </div>
        {% endfor %}
    </div>
{% endif %}

{% if parsed_data.user %}
    {# note: in the (September 2024) sentry.io interface, user info is displayed under 'contexts', but in the data it simply lives top-level as #}
    {# is implied by parsed_data.user -- I checked in a recent (September 2024) event.schema.json #}
    <h1 id="user" class="text-2xl font-bold mt-4">User</h1>

    <div class="mb-6">
        {% for key, value in parsed_data.user|items %}
            <div class="flex {% if forloop.first %}border-slate-300 dark:border-slate-600 border-t-2{% endif %}">
                <div class="w-1/4 {% if not forloop.last %}border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %}">{{ key }}</div>
                <div class="w-3/4 {% if not forloop.last %} border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %} font-mono">{{ value|linebreaks }}</div>
            </div>
        {% endfor %}
    </div>
{% endif %}

{% if parsed_data.request %}
    <h1 id="request" class="text-2xl font-bold mt-4">Request</h1>
    <div class="mb-6">

    <div>
        {% for key, value in parsed_data.request|items %}
            {% if key != "headers" and key != "env" %}{# we deal with these below #}
                <div class="flex {% if forloop.first %}border-slate-300 dark:border-slate-600 border-t-2{% endif %}">
                    <div class="w-1/4 {% if not forloop.last %}border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %}">{{ key }}</div>
                    <div class="w-3/4 {% if not forloop.last %} border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %} font-mono">{{ value|linebreaks }}</div>{# forloop.last doesn't work given the if-statement; we can fix that by pre-processing in the view #}
                </div>
            {% endif %}
        {% endfor %}
    </div>

    {% if parsed_data.request.headers %}
    <h3 class="font-bold mt-2">REQUEST HEADERS</h3>
    <div>
    {% for key, value in parsed_data.request.headers.items %}
    <div class="flex {% if forloop.first %}border-slate-300 dark:border-slate-600 border-t-2{% endif %} border-dotted">
        <div class="w-1/4 {% if not forloop.last %}border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %}">{{ key }}</div>
        <div class="w-3/4 {% if not forloop.last %} border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %} font-mono">{{ value|linebreaks }}</div>
    </div>
    {% endfor %}
    </div>
    {% endif %} {# end if parsed_data.request.headers #}

    {% if parsed_data.request.env %}
    <h3 class="font-bold mt-2">REQUEST ENV</h3>
    <div>

    {% for key, value in parsed_data.request.env.items %}
    <div class="flex {% if forloop.first %}border-slate-300 dark:border-slate-600 border-t-2{% endif %} border-dotted">
        <div class="w-1/4 {% if not forloop.last %}border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %}">{{ key }}</div>
        <div class="w-3/4 {% if not forloop.last %} border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %} font-mono">{{ value|linebreaks }}</div>
    </div>
    {% endfor %}

    </div>
    {% endif %} {# end if parsed_data.request.env #}
    </div>


{% endif %}

{% if contexts %}
    <h1 id="runtime" class="text-2xl font-bold mt-4">Contexts</h1>

    <div class="mb-6">
        {% for context_key, context in contexts|items %}
            <h3 class="font-bold mt-2">{{ context_key|upper }}</h3>
            {% for key, value in context|items %}
                <div class="flex {% if forloop.first %}border-slate-300 dark:border-slate-600 border-t-2{% endif %}">
                    <div class="w-1/4 {% if not forloop.last %}border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %}">{{ key }}</div>
                    <div class="w-3/4 {% if not forloop.last %} border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %} font-mono">{{ value|linebreaks }}</div>
                </div>
            {% endfor %}
        {% endfor %}
    </div>
{% endif %}

{% comment %}
earlier I said about "tracing": I don't believe much in this whole business of tracing, so I'm not going to display the associated data either

now that we "just display all contexts" this is no longer true... some of the feeling persists, but I don't think
that I'm so much anti-tracing that I want specifically exclude it from a generic loop. The data's there, let's just
show it (in a non-special way)
{% endcomment %}

{% comment %}
commented-out like it's 1999.
this is now part of the more general "contexts" handling right above this section.
the fact that we commented-out rather than clobbered reveals a small amount of doubt about whether this is the way.

{% if parsed_data.contexts.runtime %}
    {# sentry gives this prime location (even a picture)... but why... it's kinda obvious what you're working in right? Maybe I could put it at the top of the modules list instead. And check if there's any other relevant info in that runtime context (RTFM) #}
    <h1 id="runtime" class="text-2xl font-bold mt-4">Runtime</h1>

    <div class="mb-6">
        {% for key, value in parsed_data.contexts.runtime|items %}
            <div class="flex {% if forloop.first %}border-slate-300 dark:border-slate-600 border-t-2{% endif %}">
                <div class="w-1/4 {% if not forloop.last %}border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %}">{{ key }}</div>
                <div class="w-3/4 {% if not forloop.last %} border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %} font-mono">{{ value|linebreaks }}</div>
            </div>
        {% endfor %}
    </div>
{% endif %}
{% endcomment %}

{% if parsed_data.modules %}
    <h1 id="modules" class="text-2xl font-bold mt-4">Modules</h1>

    <div class="mb-6">
        {# we have observed that (emperically) the keys in most of the above are sorted in some kind of meaningful way from important to non-important #}
        {# however, for modules I'd rather just have an alphabetical list. #}
        {% for key, value in parsed_data.modules|sorted_items %}
            <div class="flex {% if forloop.first %}border-slate-300 dark:border-slate-600 border-t-2{% endif %}">
                <div class="w-1/4 {% if not forloop.last %}border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %}">{{ key }}</div>
                <div class="w-3/4 {% if not forloop.last %} border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %} font-mono">{{ value|linebreaks }}</div>
            </div>
        {% endfor %}
    </div>
{% endif %}

{% if parsed_data.sdk %}
    <h1 id="sdk" class="text-2xl font-bold mt-4">SDK</h1>

    <div class="mb-6">
        {% for key, value in parsed_data.sdk|items %}
            <div class="flex {% if forloop.first %}border-slate-300 dark:border-slate-600 border-t-2{% endif %}">
                <div class="w-1/4 {% if not forloop.last %}border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %}">{{ key }}</div>
                <div class="w-3/4 {% if not forloop.last %} border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %} font-mono">{{ value|linebreaks }}</div> {# the actual value may be a dict/list, but we'll just print it as a string; this is plenty of space for something as (hopefully) irrelevant as the SDK #}
            </div>
        {% endfor %}
    </div>
{% endif %}

{% if sourcemaps_images %}
    <h1 id="sourcemaps_images" class="text-2xl font-bold mt-4">Sourcemap IDs</h1>

    <div class="mb-6">
        {% for key, value in sourcemaps_images %}
            <div class="flex {% if forloop.first %}border-slate-300 dark:border-slate-600 border-t-2{% endif %}">
                <div class="w-1/4 {% if not forloop.last %}border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %}">{{ key }}</div>
                <div class="w-3/4 {% if not forloop.last %} border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %} font-mono">{{ value|linebreaks }}</div>
            </div>
        {% endfor %}
    </div>
{% endif %}

{% if parsed_data.extra %}
    <h1 id="extra" class="text-2xl font-bold mt-4">Extra</h1>

    <div class="mb-6">
        {% for key, value in parsed_data.extra|items %}
            <div class="flex {% if forloop.first %}border-slate-300 dark:border-slate-600 border-t-2{% endif %}">
                <div class="w-1/4 {% if not forloop.last %}border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %}">{{ key }}</div>
                <div class="w-3/4 {% if not forloop.last %} border-b-2 border-dotted border-slate-300 dark:border-slate-600{% endif %} font-mono">{{ value|linebreaks }}</div> {# the actual value may be a dict/list, but we'll just print it as a string; this is plenty of space for something as (hopefully) irrelevant #}
            </div>
        {% endfor %}
    </div>
{% endif %}


{% endblock %}
