{% extends '@CpCreationVitiCore/admin/base.html.twig' %}

{% block content %}
    <div class="page-header clearfix"><h1 class="pull-left">{{ 'emailing.list.title'|trans }}</h1><a class="btn btn-default pull-right" href="{{ path('admin_marketing_emailing') }}">{{ 'emailing.common.back'|trans }}</a></div>
    <div class="row">
        <div class="col-md-6">
            <form class="panel panel-default" method="post" action="{{ path('admin_marketing_emailing_list_create') }}">
                <input type="hidden" name="_token" value="{{ csrf_token('brevo_list_create') }}">
                <div class="panel-heading">{{ 'emailing.list.create'|trans }}</div>
                <div class="panel-body">
                    <div class="form-group"><label for="list-name">{{ 'emailing.list.name'|trans }}</label><input id="list-name" class="form-control" name="name" required></div>
                    <div class="form-group"><label for="folder-id">{{ 'emailing.list.folder'|trans }}</label><select id="folder-id" class="form-control" name="folder_id" required><option value="">{{ 'emailing.list.choose_folder'|trans }}</option>{% for folder in folders %}<option value="{{ folder.id }}">{{ folder.name }}</option>{% endfor %}</select></div>
                    <button class="btn btn-primary" type="submit">{{ 'emailing.list.create_action'|trans }}</button>
                </div>
            </form>
        </div>
        <div class="col-md-6">
            <form class="panel panel-default" method="post" enctype="multipart/form-data" action="{{ path('admin_marketing_emailing_list_import') }}">
                <input type="hidden" name="_token" value="{{ csrf_token('brevo_list_import') }}">
                <div class="panel-heading">{{ 'emailing.list.import_csv'|trans }}</div>
                <div class="panel-body">
                    <div class="form-group"><label for="import-list">{{ 'emailing.list.target'|trans }}</label><select id="import-list" class="form-control" name="list_id" required>{% for item in lists %}<option value="{{ item.id }}">{{ item.name }}</option>{% endfor %}</select></div>
                    <div class="form-group"><label for="contacts-file">{{ 'emailing.list.file'|trans }}</label><input id="contacts-file" type="file" name="contacts_file" accept=".csv,.txt" required><p class="help-block">{{ 'emailing.list.file_help'|trans }}</p></div>
                    <button class="btn btn-primary" type="submit">{{ 'emailing.list.import_action'|trans }}</button>
                </div>
            </form>
        </div>
    </div>
    <form class="panel panel-warning" method="post" action="{{ path('admin_marketing_emailing_list_sync') }}">
        <input type="hidden" name="_token" value="{{ csrf_token('brevo_list_sync') }}">
        <div class="panel-heading">{{ 'emailing.list.sync_title'|trans }}</div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-5"><label for="sync-source">{{ 'emailing.list.source'|trans }}</label><select id="sync-source" class="form-control" name="source"><option value="marketing_opt_in">{{ 'emailing.list.source_opt_in'|trans }}</option><option value="guest_purchasers">{{ 'emailing.list.source_guests'|trans }}</option></select></div>
                <div class="col-md-5"><label for="sync-list">{{ 'emailing.list.target'|trans }}</label><select id="sync-list" class="form-control" name="list_id">{% for item in lists %}<option value="{{ item.id }}">{{ item.name }}</option>{% endfor %}</select></div>
                <div class="col-md-2"><br><button class="btn btn-warning" type="submit">{{ 'emailing.list.sync_action'|trans }}</button></div>
            </div>
            <p class="help-block">{{ 'emailing.list.guest_warning'|trans }}</p>
        </div>
    </form>
    <div class="panel panel-default">
        <div class="panel-heading">{{ 'emailing.list.remote_lists'|trans }}</div>
        <table class="table table-striped"><thead><tr><th>{{ 'emailing.list.name'|trans }}</th><th>{{ 'emailing.list.subscribers'|trans }}</th><th>{{ 'emailing.list.created_at'|trans }}</th><th></th></tr></thead><tbody>{% for item in lists %}<tr><td><form class="form-inline" method="post" action="{{ path('admin_marketing_emailing_list_update', {listId: item.id}) }}"><input type="hidden" name="_token" value="{{ csrf_token('brevo_list_update_' ~ item.id) }}"><input class="form-control input-sm" name="name" value="{{ item.name }}" required> <button class="btn btn-default btn-sm" type="submit">{{ 'emailing.list.rename'|trans }}</button></form></td><td>{{ item.totalSubscribers|default(item.uniqueSubscribers|default('—')) }}</td><td>{{ item.createdAt|default('—') }}</td><td class="text-right"><form method="post" action="{{ path('admin_marketing_emailing_list_delete', {listId: item.id}) }}" onsubmit="return confirm('{{ 'emailing.list.delete_confirm'|trans|e('js') }}')"><input type="hidden" name="_token" value="{{ csrf_token('brevo_list_delete_' ~ item.id) }}"><button class="btn btn-danger btn-sm" type="submit">{{ 'emailing.list.delete'|trans }}</button></form></td></tr>{% else %}<tr><td colspan="4" class="text-muted">{{ 'emailing.list.empty'|trans }}</td></tr>{% endfor %}</tbody></table>
    </div>
{% endblock %}
