{% extends 'layout.html' %}
{% load i18n %}
{% load humanize %}

{% block title %}{% trans "Import Books" %}{% endblock %}

{% block content %}
<div class="block">
    <h1 class="title">{% trans "Import Books" %}</h1>
    <form class="box" name="import" action="/import" method="post" enctype="multipart/form-data">
        {% csrf_token %}

        <div class="columns">
        <div class="column is-half">

            <div class="field">
                <label class="label" for="source">
                    {% trans "Data source:" %}
                </label>

                <div class="select">
                    <select name="source" id="source" aria-describedby="desc_source">
                        <option value="Goodreads" {% if current == 'Goodreads' %}selected{% endif %}>
                            Goodreads (CSV)
                        </option>
                        <option value="Storygraph" {% if current == 'Storygraph' %}selected{% endif %}>
                            Storygraph (CSV)
                        </option>
                        <option value="LibraryThing" {% if current == 'LibraryThing' %}selected{% endif %}>
                            LibraryThing (TSV)
                        </option>
                        <option value="OpenLibrary" {% if current == 'OpenLibrary' %}selected{% endif %}>
                            OpenLibrary (CSV)
                        </option>
                        <option value="Calibre" {% if current == 'Calibre' %}selected{% endif %}>
                            Calibre (CSV)
                        </option>
                    </select>
                </div>

                <p class="help" id="desc_source">
                    {% trans 'You can download your Goodreads data from the <a href="https://www.goodreads.com/review/import" target="_blank" rel="noopener noreferrer">Import/Export page</a> of your Goodreads account.' %}
                </p>
            </div>

            <div class="field">
                <label class="label" for="id_csv_file">{% trans "Data file:" %}</label>
                {{ import_form.csv_file }}
            </div>
        </div>

        <div class="column is-half">
            <div class="field">
                <label class="label">
                    <input type="checkbox" name="include_reviews" checked> {% trans "Include reviews" %}
                </label>
            </div>
            <div class="field">
                <label class="label" for="privacy_import">
                    {% trans "Privacy setting for imported reviews:" %}
                </label>
                {% include 'snippets/privacy_select.html' with no_label=True privacy_uuid="import" %}
            </div>
        </div>
        </div>
        <button class="button is-primary" type="submit">{% trans "Import" %}</button>
    </form>
</div>

<div class="content block">
    <h2 class="title">{% trans "Recent Imports" %}</h2>
    {% if not jobs %}
    <p><em>{% trans "No recent imports" %}</em></p>
    {% endif %}
    <ul>
        {% for job in jobs %}
        <li><a href="{% url 'import-status' job.id %}">{{ job.created_date | naturaltime }}</a></li>
        {% endfor %}
    </ul>
</div>
{% endblock %}
