{#
/**
 * Copyright © 2003-2024 The Galette Team
 *
 * This file is part of Galette (https://galette.eu).
 *
 * Galette is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Galette is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
 */
#}
{% extends 'page.html.twig' %}

{% block content %}
        <div class="ui icon info visible message">
            <i class="info circle blue icon" aria-hidden="true"></i>
            <div class="content">
                {{ _T("Each selected export will be stored into a separate file in the exports directory.") }}
            </div>
        </div>
        <form class="form" action="{{ url_for("doExport") }}" method="post" enctype="multipart/form-data">

{% set written_exports = flash.getMessage('written_exports') %}

{% if written is iterable and written|length > 0 %}
        <div class="ui icon success visible message with-transition">
            <i class="download icon" aria-hidden="true"></i>
            <div class="content">
                <p>{{ _T('The following files have been written on disk:') }}</p>
                <ul>
    {% for ex in written %}
                    <li>{{ ex|raw }}</li>
    {% endfor %}
                </ul>
            </div>
        </div>
{% endif %}

{% if existing|length > 0 %}
            <div class="ui basic fitted segment">
                <div class="ui styled fluid accordion row">
                    <div class="active title">
                        <i class="jsonly displaynone icon dropdown" aria-hidden="true"></i>
                        {{ _T('Existing exports') }}
                    </div>
                    <div class="active content field">
                        <p>{{ _T('The following exports already seems to exist on the disk:') }}</p>
                        <table class="listing ui celled striped table">
                            <thead>
                                <tr>
                                    <th class="id_row">#</th>
                                    <th>{{ _T('Name') }}</th>
                                    <th>{{ _T('Date') }}</th>
                                    <th>{{ _T('Size') }}</th>
                                    <th class="actions_row"></th>
                                </tr>
                            </thead>
                            <tbody>
        {% for export in existing %}
                                <tr>
                                    <td data-scope="id">
                                        {{ loop.index }}
                                    </td>
                                    <td data-scope="row">
                                        <a href="{{ url_for("getCsv", {"type": "export", "file": export.name}) }}">{{ export.name }}</a>
                                    </td>
                                    <td data-col-label="{{ _T('Date') }}">
                                        {{ export.date }}
                                    </td>
                                    <td data-col-label="{{ _T('Size') }}">
                                        {{ export.size }}
                                    </td>
                                    <td class="actions_row">
                                        <a
                                            href="{{ url_for("removeCsv", {"type": "export", "file": export.name}) }}"
                                            class="delete "
                                        >
                                            <i class="ui trash red icon tooltip" aria-hidden="true"></i>
                                            <span class="ui special popup">{{ _T('Remove \'%file\' from disk')|replace({'%file': export.name}) }}</span>
                                        </a>
                                    </td>
                                </tr>
        {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
{% endif %}
            <div class="ui basic fitted segment">
                <div class="ui styled fluid accordion row">
                    <div class="active title">
                        <i class="jsonly displaynone icon dropdown" aria-hidden="true"></i>
                        {{ _T('Parameted exports') }}
                    </div>
                    <div class="active content field">
{% if parameted|length > 0 %}
                        <p>{{ _T('Which parameted export(s) do you want to run?') }}</p>
                        <table class="ui celled striped table">
                            <thead>
                                <tr>
                                    <th class="small_head"/>
                                    <th>{{ _T('Name') }}</th>
                                    <th>{{ _T('Description') }}</th>
                                </tr>
                            </thead>
                            <tbody>
    {% for param in parameted %}
                                <tr>
                                    <td class="collapsing" data-scope="id">
                                        <input type="checkbox" name="export_parameted[]" id="{{ param.id }}" value="{{ param.id }}"/>
                                    </td>
                                    <td data-scope="row">
                                        <label for="{{ param.id }}">{{ param.name }}</label>
                                    </td>
                                    <td data-col-label="{{ _T('Description') }}">
                                        <label for="{{ param.id }}">{{ param.description }}</label>
                                    </td>
                                </tr>
    {% endfor %}
                            </tbody>
                        </table>
{% else %}
                        <p>{{ _T('No parameted exports are available.') }}</p>
{% endif %}
                    </div>
                </div>
            </div>
            <div class="ui basic fitted segment">
                <div class="ui styled fluid accordion row">
                    <div class="active title">
                        <i class="jsonly displaynone icon dropdown" aria-hidden="true"></i>
                        {{ _T('Galette tables exports') }}
                    </div>
                    <div class="active content field">
                        <p>{{ _T('Additionnaly, which table(s) do you want to export?') }}</p>
                        <table class="same ui celled striped table">
                            <thead>
                                <tr>
                                    <th class="small_head"/>
                                    <th>{{ _T('Table name') }}</th>
                                </tr>
                            </thead>
                            <tbody>
    {% for table in tables_list %}
                                <tr>
                                    <td class="collapsing">
                                        <input type="checkbox" name="export_tables[]" id="{{ table }}" value="{{ table }}"/>
                                    </td>
                                    <td class="left">
                                        <label for="{{ table }}">{{ table }}</label>
                                    </td>
                                </tr>
    {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div class="ui basic center aligned segment">
                <button type="submit" name="valid" class="ui labeled icon primary button">
                    <i class="download icon" aria-hidden="true"></i>
                    {{ _T('Continue') }}
                </button>
                {% include "components/forms/csrf.html.twig" %}
            </div>
        </form>
{% endblock %}

{% block javascripts %}
        <script type="text/javascript">
            $(function() {
                {% include "elements/js/removal.js.twig" with {
                single_action: "true"
            } %}
            });
        </script>
{% endblock %}
