<% extends 'layout.html' %>

<% block content %>
<div id="mailpoet_subscribers_export" class="wrap">
  <h1 class="title">
    <%= __('Export') %>
    <a class="page-title-action" href="?page=mailpoet-subscribers#/"><%= __('Back to Subscribers') %></a>
  </h1>
  <% if segments is empty %>
  <div class="error">
    <p><%= __("Yikes! Couldn't find any subscribers") %></p>
  </div>
  <% endif %>
  <div class="inside">
    <!-- Template data -->
  </div>
</div>
<script id="mailpoet_subscribers_export_template" type="text/x-handlebars-template">
  <div id="export_result_notice" class="updated mailpoet_hidden">
    <!-- Result message -->
  </div>
  <table class="form-table">
    <tbody>
    {{#if exportConfirmedOption}}
    <tr>
      <th scope="row">
        <%= __('Export confirmed subscribers only') %>
      </th>
      <td>
        <div>
          <label>
            <input type="radio"
                   name="option_confirmed" value=1><%= __('Yes') %>
          </label>
          &nbsp;
          <label>
            <input type="radio"
                   name="option_confirmed" value=0 checked><%= __('No') %>
          </label>
        </div>
      </td>
    </tr>
    {{/if}}
    {{#if segments}}
    <tr>
      <th scope="row">
        <label for="export_lists">
          <%= __('Pick one or multiple lists') %>
        </label>
      </th>
      <td>
        <select id="export_lists" data-placeholder="<%= _x('Select', 'Verb') %>" multiple="multiple"></select>
      </td>
    </tr>
    {{/if}}
    <tr>
      <th scope="row">
        <label for="export_columns">
          <%= __('List of fields to export') %>
        </label>
      </th>
      <td>
        <select id="export_columns" data-placeholder="<%= _x('Select', 'Verb') %>" multiple="multiple"></select>
      </td>
    </tr>
    {{#if groupBySegmentOption}}
    <tr class="mailpoet_group_by_list mailpoet_hidden">
      <th scope="row">
        <%= __('Group subscribers by list') %>
      </th>
      <td>
        <input type="checkbox" name="option_group_by_list" checked>
      </td>
    </tr>
    {{/if}}
    <tr>
      <th scope="row">
        <%= __('Format') %>
      </th>
      <td>
        <label>
          <input type="radio" name="option_format"
           value="csv"
           checked><%= __('CSV file') %>
        </label>
        &nbsp;
        <label>
          <input type="radio" name="option_format"
           value="xlsx"><%= __('Excel file') %>
        </label>
      </td>
    </tr>
    <tr class="mailpoet_export_process">
      <th scope="row">
        <a href="javascript:;"
         class="button-primary button-disabled wysija mailpoet_export_process"><%= __('Export') %></a>
      </th>
    </tr>
    </tbody>
  </table>
</script>
</div>

<%= stylesheet('importExport.css') %>

<script type="text/javascript">
  var
    segments = <%= segments|raw %>,
    segmentsWithConfirmedSubscribers =
      <%= segmentsWithConfirmedSubscribers|raw %>,
    subscriberFieldsSelect2 =
      <%= subscriberFieldsSelect2|raw %>,
    exportData = {
     segments: segments.length || null,
     segmentsWithConfirmedSubscribers: segmentsWithConfirmedSubscribers.length || null,
     exportConfirmedOption: true,
     groupBySegmentOption: (segments.length > 1 || segmentsWithConfirmedSubscribers.length > 1) ? true : null
    };
</script>
<% endblock %>

<% block translations %>
<%= localize({
  'serverError': __('Server error:'),
  'exportMessage' : __('%1$s subscribers were exported. Get the exported file [link]here[/link].')
}) %>
<% endblock %>
