{% extends "admin/base_site.html" %}
{% load i18n admin_urls %}

{% block breadcrumbs %}
<div class="breadcrumbs">
  <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a> ›
  <a href="{% url 'admin:app_list' opts.app_label %}">{{ opts.app_config.verbose_name }}</a> ›
  <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a> ›
  {% trans 'Import from Odoo' %}
</div>
{% endblock %}

{% block content %}
{% if credential_error %}
  <div class="messagelist">
    <div class="error">{{ credential_error }}
      {% if profile_url %}
        <a href="{{ profile_url }}">{% trans 'Manage Odoo credentials' %}</a>
      {% endif %}
    </div>
  </div>
{% endif %}

{% if error %}
  <div class="messagelist">
    <div class="error">{{ error }}</div>
  </div>
{% endif %}

{% if debug_error %}
  <div class="messagelist">
    <div class="warning">
      <strong>Debug details</strong>
      <pre>{{ debug_error }}</pre>
    </div>
  </div>
{% endif %}

{% if form_error %}
  <div class="messagelist">
    <div class="error">{{ form_error }}</div>
  </div>
{% endif %}

{% if has_credentials %}
<form method="post">
  {% csrf_token %}
  <fieldset class="module aligned">
    <div class="form-row">
      {{ search_form.name.errors }}
      <label for="id_name">{% trans 'Name contains' %}</label>
      {{ search_form.name }}
    </div>
    <div class="form-row">
      {{ search_form.email.errors }}
      <label for="id_email">{% trans 'Email contains' %}</label>
      {{ search_form.email }}
    </div>
    <div class="form-row">
      {{ search_form.phone.errors }}
      <label for="id_phone">{% trans 'Phone contains' %}</label>
      {{ search_form.phone }}
    </div>
    <div class="form-row">
      {{ search_form.limit.errors }}
      <label for="id_limit">{% trans 'Result limit' %}</label>
      {{ search_form.limit }}
      {% if search_form.limit.help_text %}
        <p class="help">{{ search_form.limit.help_text }}</p>
      {% endif %}
    </div>
  </fieldset>
  <div class="submit-row">
    <button type="submit" name="perform_search" class="button">{% trans 'Search customers' %}</button>
  </div>

  {% if searched %}
    {% if customers %}
      <table class="adminlist">
        <thead>
          <tr>
            <th>{% trans 'Select' %}</th>
            <th>{% trans 'Name' %}</th>
            <th>{% trans 'Email' %}</th>
            <th>{% trans 'Phone' %}</th>
            <th>{% trans 'Mobile' %}</th>
            <th>{% trans 'City' %}</th>
            <th>{% trans 'Country' %}</th>
          </tr>
        </thead>
        <tbody>
          {% for customer in customers %}
            <tr>
              <td>
                <input
                  type="checkbox"
                  name="customer_ids"
                  value="{{ customer.id }}"
                  {% if customer.id|stringformat:'s' in selected_ids %}checked{% endif %}
                >
              </td>
              <td>{{ customer.name }}</td>
              <td>{{ customer.email }}</td>
              <td>{{ customer.phone }}</td>
              <td>{{ customer.mobile }}</td>
              <td>{{ customer.city }}</td>
              <td>{{ customer.country }}</td>
            </tr>
          {% empty %}
            <tr>
              <td colspan="7">{% trans 'No customers matched your search.' %}</td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
      <div class="submit-row">
        <button type="submit" name="import_action" value="import" class="button default">{% trans 'Import selected' %}</button>
        <button type="submit" name="import_action" value="continue" class="button">{% trans 'Import and continue' %}</button>
      </div>
    {% else %}
      <p>{% trans 'No customers matched your search.' %}</p>
    {% endif %}
  {% endif %}
</form>
{% endif %}
{% endblock %}
