{% extends 'preferences/layout.html' %}
{% load i18n %}
{% load utilities %}

{% block title %}{% trans "Export BookWyrm Account" %}{% endblock %}

{% block header %}
{% trans "Export BookWyrm Account" %}
{% endblock %}

{% block panel %}
<div class="block content">
    <div class="block content">
        <p> {% trans "You can create an export file here. This will allow you to migrate your data to another BookWyrm account." %}</p>
    </div>
        <div class="block mx-5 columns">
            <div class="column is-half">
                <h2 class="is-size-5">{% trans "Your file will include:" %}</h2>
                <ul>
                    <li>{% trans "User profile" %}</li>
                    <li>{% trans "Most user settings" %}</li>
                    <li>{% trans "Reading goals" %}</li>
                    <li>{% trans "Shelves" %}</li>
                    <li>{% trans "Reading history" %}</li>
                    <li>{% trans "Book reviews" %}</li>
                    <li>{% trans "Statuses" %}</li>
                    <li>{% trans "Your own lists and saved lists" %}</li>
                    <li>{% trans "Which users you follow and block" %}</li>
                </ul>
            </div>
            <div class="column is-half">
                <h2 class="is-size-5">{% trans "Your file will not include:" %}</h2>
                <ul>
                    <li>{% trans "Direct messages" %}</li>
                    <li>{% trans "Replies to your statuses" %}</li>
                    <li>{% trans "Groups" %}</li>
                    <li>{% trans "Favorites" %}</li>
                </ul>
            </div>
        </div>
        <p class="block">{% trans "In your new BookWyrm account can choose what to import: you will not have to import everything that is exported." %}</p>
        <p class="notification is-warning">
            {% spaceless %}
            {% trans "If you wish to migrate any statuses (comments, reviews, or quotes) you must either set the account you are moving to as an <strong>alias</strong> of this one, or <strong>move</strong> this account to the new account, before you import your user data." %}
            {% endspaceless %}
        </p>
    {% if not site.user_exports_enabled %}
    <p class="notification is-danger">
        {% trans "New user exports are currently disabled." %}
        {% if perms.bookwyrm.edit_instance_settings %}
        <br/>
        {% url 'settings-imports' as url %}
        {% blocktrans trimmed %}
            User exports settings can be changed from <a href="{{ url }}">the Imports page</a> in the Admin dashboard.
        {% endblocktrans %}
    {% endif%}
    </p>
    {% elif next_available %}
    <p class="notification is-warning">
        {% blocktrans trimmed %}
        You will be able to create a new export file at {{ next_available }}
        {% endblocktrans %}
    </p>
    {% else %}
    <form name="export" method="POST" href="{% url 'prefs-user-export' %}">
        {% csrf_token %}
        <button type="submit" class="button">
            <span class="icon icon-download" aria-hidden="true"></span>
            <span>{% trans "Create user export file" %}</span>
        </button>
    </form>
    {% endif %}

</div>
<div class="content block">
    <h2 class="title">{% trans "Recent Exports" %}</h2>
    <p class="content">
    {% trans "User export files will show 'complete' once ready. This may take a little while. Click the link to download your file." %}
    </p>
    <div class="table-container">
        <table class="table is-striped is-fullwidth">
            <tr>
                <th>
                    {% trans "Date" %}
                </th>
                <th>
                    {% trans "Status" %}
                </th>
                <th colspan="2">
                    {% trans "Size" %}
                </th>
            </tr>
            {% if not jobs %}
            <tr>
                <td colspan="4">
                    <em>{% trans "No recent imports" %}</em>
                </td>
            </tr>
            {% endif %}
            {% for export in jobs %}
            <tr>
                <td>{{ export.job.updated_date }}</td>
                <td>
                    <span
                        {% if export.job.status == "stopped" or export.job.status == "failed" %}
                        class="tag is-danger"
                        {% elif export.job.status == "pending" %}
                        class="tag is-warning"
                        {% elif export.job.complete %}
                        class="tag"
                        {% else %}
                        class="tag is-success"
                        {% endif %}
                    >
                        {% if export.job.status %}
                        {{ export.job.status }}
                            {{ export.job.status_display }}
                        {% elif export.job.complete %}
                            {% trans "Complete" %}
                        {% else %}
                            {% trans "Active" %}
                        {% endif %}
                    </span>
                </td>
                <td>
                    {% if export.size %}
                    <span>{{ export.size|get_file_size }}</span>
                    {% endif %}
                </td>
                <td>
                    {% if export.url %}
                    <a href="{{ export.url }}">
                        <span class="icon icon-download" aria-hidden="true"></span>
                        <span class="is-hidden-mobile">
                            {% trans "Download your export" %}
                        </span>
                    </a>
                    {% elif export.unavailable %}
                    {% trans "Archive is no longer available" %}
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </table>
    </div>

    {% include 'snippets/pagination.html' with page=jobs path=request.path %}
</div>
{% endblock %}
