{% extends "layouts/" + render_mode + ".html" %}
{% block title %}{{ message }}{% endblock %}
{% block content %}
<div id="mailbox-settings" class="content-normal"
     style="position: relative; max-width: 42em;">
<form class="standard" method="POST"
      action="{{ U('/settings/mailbox/') }}">{{ csrf_field|safe }}

  <script type="text/javascript">
  </script>

  <p class="message paragraph-important modal-basic-settings-title">
    {% if result.recurse %}
      <span class="icon-search"></span>
      <input type="hidden" name="recurse" value="true">
      {{_("Search Folder")}}:
      {%- for path in result.paths %}
        <input type="hidden" name="path" value="{{ path }}"> {{ path }}
      {%- endfor %}
    {% else %}
      <span class="icon-settings"></span>
      {{_("Mailbox Settings")}}:
      {%- for path in result.adding %}
        <input type="hidden" name="path" value="{{ path }}"> {{ path }}
      {%- endfor %}
      {%- for path, info in result.configure %}
        <input type="hidden" name="path" value="{{ path }}"> {{ path }}
      {%- endfor %}
    {% endif %}
  </p>
  {% if result.recurse %}
  <p>FIXME: <i>
    This folder contains {{ result.adding|length }} new mailboxes.
    This folder contains {{ result.configure|length }} mailboxes already in your pile.
    Add them to your mailpile using the settings below?
  </i></p><hr>
  {% endif %}
  <div class="modal-basic-settings">

    <div class="left" style="width: 18em; margin-right: 1em;">
      <label>Mailbox role</label>
      <input type="hidden" name="guess_tags" value="False">
      <select name='apply_tags' style="width: 100%;">
        <option value='' {% if not result.apply_tags %}selected{% endif %}>{{_("Archives")}}</option>
        {% for tid in config.tags %}
          {%- set tag = config.tags[tid] %}
          {%- if tag.display == 'priority' %}
        <option value='{{ tid }}' {% if tid in result.apply_tags %}selected{% endif %}>{{ tag.name }}</option>
          {%- endif %}
        {%- endfor %}
      </select>

    {%- if not result.has_source %}
      <label>Account</label>
      <select name='profile' style="width: 100%;">
        {% set profile_data = mailpile('profiles').result %}
        {% for rid in profile_data.rids %}
          {% set profile = profile_data.profiles[profile_data.rids[rid]] %}
        <option value='{{ rid }}' {% if rid == result.profile %}selected{% endif %}>{{ profile.fn }} &lt;{{ profile.email.0.email }}&gt;</option>
        {% endfor %}
      </select>
    {%- endif %}
    </div>

    <div class="right">
      <label>Search settings</label>
      <ul>
        <li><input type="checkbox" name="auto_index" value="true" {% if result.auto_index %}checked{% endif %}>
            <span class="checkbox">{{_("Add messages to search engine")}}</span></li>
      </ul>

      <label>Mailbox settings</label>
      <ul>
        <li><input type="checkbox" name="local_copy" value="true" {% if result.local_copy %}checked{% endif %}>
            <span class="checkbox">{{_("Copy mail to Mailpile secure storage")}}</span></li>
        {# FIXME: delete from source #}
      </ul>
    </div>

  </div>

  <div>
    <hr style="margin-bottom: 10px;">
    <button class="button-primary right" type="submit">
      <span class="icon-checkmark"></span>
      {% if result.recurse %}
        {{_("Configure Mailboxes")}}
      {% else %}
        {{_("Save")}}
      {% endif %}
    </button>
  </div>

</form>
</div>
{% endblock %}
