{% extends "@ChillMain/layout.html.twig" %}

{% block title %}{{ 'saved_export.My saved exports'|trans }}{% endblock %}

{% block content %}
    <div class="col-md-10 exports-list">

        {{ include('@ChillMain/Export/_navbar.html.twig', {'current' : 'my'}) }}

        <div class="container mt-4">

            {% if total == 0 %}
                <p class="chill-no-data-statement" >{{ 'saved_export.Any saved export'|trans }}</p>
            {% endif %}

            {% for group, saveds in grouped_exports %}
                {% if group != '_' %}
                    <h2 class="display-6">{{ group }}</h2>
                    <div class="row flex-bloc">
                        {% for s in saveds %}
                            <div class="item-bloc">
                                <div class="item-row card-body">
                                    <p class="card-subtitle"><strong>{{ s.export.title|trans }}</strong></p>
                                    <h2 class="card-title">{{ s.saved.title }}</h2>

                                    <div class="createdBy">{{ 'saved_export.Created on %date%'|trans({'%date%': s.saved.createdAt|format_datetime('long', 'short')}) }}</div>

                                    <div class="card-text my-3">
                                        {{ s.saved.description|chill_markdown_to_html }}
                                    </div>

                                    <div>
                                        <ul class="record_actions">
                                            <li>
                                                <div class="dropdown">
                                                    <button class="btn btn-outline-primary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                                                        {{ 'Actions'|trans }}
                                                    </button>
                                                    <ul class="dropdown-menu">
                                                        <li><a href="{{ chill_path_add_return_path('chill_main_export_saved_edit', {'id': s.saved.id }) }}" class="dropdown-item"><i class="fa fa-pencil"></i> {{ 'saved_export.update_title_and_description'|trans }}</a></li>
                                                        <li><a href="{{ chill_path_add_return_path('chill_main_export_new', {'alias': s.saved.exportAlias,'from_saved': s.saved.id }) }}" class="dropdown-item"><i class="fa fa-pencil"></i> {{ 'saved_export.update_filters_aggregators_and_execute'|trans }}</a></li>
                                                        <li><a href="{{ path('chill_main_export_generate_from_saved', { id: s.saved.id }) }}" class="dropdown-item"><i class="fa fa-cog"></i> {{ 'saved_export.execute'|trans }}</a></li>
                                                        <li><a href="{{ chill_path_add_return_path('chill_main_export_saved_delete', {'id': s.saved.id }) }}" class="dropdown-item"><i class="fa fa-trash"></i> {{ 'Delete'|trans }}</a></li>
                                                    </ul>
                                                </div>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        {% endfor %}
                    </div>
                {% endif %}
            {% endfor %}

            {% if grouped_exports|keys|length > 1 and grouped_exports['_']|default([])|length > 0 %}
                <h2 class="display-6">{{ 'Ungrouped exports'|trans }}</h2>
            {% endif %}

            <div class="row flex-bloc">
                {% for saveds in grouped_exports['_']|default([]) %}
                    {% for s in saveds %}
                        <div class="item-bloc">
                            <div class="item-row card-body">
                                <p class="card-subtitle"><strong>{{ s.export.title|trans }}</strong></p>
                                <h2 class="card-title">{{ s.saved.title }}</h2>

                                <div class="createdBy">{{ 'saved_export.Created on %date%'|trans({'%date%': s.saved.createdAt|format_datetime('long', 'short')}) }}</div>

                                <div class="card-text my-3">
                                    {{ s.saved.description|chill_markdown_to_html }}
                                </div>

                                <div>
                                    <ul class="record_actions">
                                        <li><a href="{{ chill_path_add_return_path('chill_main_export_saved_delete', {'id': s.saved.id }) }}" class="btn btn-delete"></a></li>
                                        <li><a href="{{ chill_path_add_return_path('chill_main_export_saved_edit', {'id': s.saved.id }) }}" class="btn btn-edit"></a></li>
                                        <li><a href="{{ path('chill_main_export_generate_from_saved', { id: s.saved.id }) }}" class="btn btn-action"><i class="fa fa-cog"></i></a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    {% endfor %}
                {% endfor %}
            </div>
        </div>
    </div>
{% endblock %}
