{%- extends "_layout.html" %}

{%- block content %}

                <div>
                    {{ macros_page.render_breadcrumbs(item) }}

                    <div class="jumbotron bg-light" style="margin-top: 1em;">
                        <h2>{{ hawat_current_view.get_view_title() }}</h2>
                        <hr>
                        <form method="POST" class="form-horizontal d-grid row-gap-2" id="form-events-simple" action="{{ form_url }}">
                            {{ macros_form.render_form_item_default(form.filter, placeholder = _('Write your filtering rule here...')) }}
                            {{ macros_form.render_form_item_default(form.event, placeholder = _('Paste your IDEA event as raw JSON string...'), rows = 5) }}

                            <hr>

                            {{ macros_form.render_form_errors(form.csrf_token.errors) }}
                            {{ form.csrf_token }}

                            <div class="btn-toolbar" role="toolbar" aria-label="{{ _('Form submission buttons') }}">
                                <div class="btn-group" role="group">
                                    {{ form.submit(class_='btn btn-primary') }}
                                    <a role="button" class="btn btn-secondary" href="{{ url_for(request.endpoint) }}">
                                        {{ _('Clear') }}
                                    </a>
                                </div>
                            </div>
                        </form>
                    </div> <!-- .jumbotron -->

                </div>

    {%- if flag_filtered %}

        {%- if filter_result %}
            {%- call macros_site.render_alert('success', False) %}
            {{ _('Given event matches given filtering rule.') }}
            {%- endcall %}
        {%- else %}
            {%- call macros_site.render_alert('info', False) %}
            {{ _('Given event does NOT match given filtering rule.') }}
            {%- endcall %}
        {%- endif %}

            <div class="accordion" id="result-accordion">

                <div class="accordion-item">
                    <h3 class="accordion-header">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#filtering-result" aria-controls="filtering-result">
                            {{ _('Filtering result') }}
                        </button>
                    </h3>
                    <div id="filtering-result" class="accordion-collapse collapse" data-bs-parent="#result-accordion">
                        <div class="accordion-body">
<pre>
{{ filter_result | pprint }}
</pre>
                        </div>
                    </div>
                </div>

                <div class="accordion-item">
                    <h3 class="accordion-header">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#filtering-filter" aria-controls="filtering-filter">
                            {{ _('Filter tree') }}
                        </button>
                    </h3>
                    <div id="filtering-filter" class="accordion-collapse collapse" data-bs-parent="#result-accordion">
                        <div class="accordion-body">
                            <div class="rule-tree">
                                {{ filter_compiled_preview | safe }}
                            </div>
                            <hr>
                            <h4>{{ _('Textual representation') }}:</h4>
<pre>
{{ filter_compiled.__str__() }}
</pre>
                        </div>
                    </div>
                </div>

                <div class="accordion-item">
                    <h3 class="accordion-header">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#filtering-event" aria-controls="filtering-event">
                            {{ _('Filtered event') }}
                        </button>
                    </h3>
                    <div id="filtering-event" class="accoridion-collapse collapse" data-bs-parent="#result-accordion">
                        <div class="accordion-body">
<pre>
{{ event.to_json(indent = 4, sort_keys = True) }}
</pre>
                        </div>
                    </div>
                </div>

            </div>  <!-- #result-accordion -->
    {%- endif %}

    {%- if permission_can('developer') %}
            <hr>
        {%- if filter_exception %}
            {{ macros_site.render_raw_var('filter_exception',    filter_exception) }}
            {{ macros_site.render_raw_var('filter_exception_st', filter_exception_st) }}
        {%- endif %}
            {{ macros_site.render_raw_var('form_data',               form_data) }}
            {{ macros_site.render_raw_var('event',                   event) }}
            {{ macros_site.render_raw_var('filter_tree',             filter_tree) }}
            {{ macros_site.render_raw_var('filter_compiled',         filter_compiled) }}
            {{ macros_site.render_raw_var('filter_preview',          filter_preview) }}
            {{ macros_site.render_raw_var('filter_compiled_preview', filter_compiled_preview) }}
            {{ macros_site.render_raw_var('filter_result',           filter_result) }}
    {%- endif %}

{%- endblock content %}
