{% load static %}
{% load i18n %}
{% load mastodon %}
{% load thumb %}
<!DOCTYPE html>
<html lang="zh" class="classic-page">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ site_name }} - {% trans 'Data Management' %}</title>
    {% include "common_libs.html" %}
  </head>
  <body>
    {% include "_header.html" %}
    <main>
      <div class="grid__main">
        <article>
          <details>
            <summary>{% trans 'Import Marks and Reviews from Douban' %}</summary>
            <form action="{% url 'users:import_douban' %}"
                  method="post"
                  enctype="multipart/form-data">
              {% csrf_token %}
              {% blocktrans %}Select <code>.xlsx</code> exported from <a href="https://doufen.org" target="_blank" rel="noopener">Doufen</a>{% endblocktrans %}
              <input type="file" name="file" id="excel" required accept=".xlsx">
              <fieldset>
                <legend>{% trans "Import Method" %}</legend>
                <label for="import_mode_0">
                  <input id="import_mode_0" type="radio" name="import_mode" value="0" checked>
                  {% trans "Merge: only update when status changes from wishlist to in-progress, or from in-progress to complete." %}
                </label>
                <label for="import_mode_1">
                  <input id="import_mode_1" type="radio" name="import_mode" value="1">
                  {% trans "Overwrite: update all imported status." %}
                </label>
              </fieldset>
              <p>
                {% trans 'Visibility' %}:
                <br>
                <label for="id_visibility_0">
                  <input type="radio"
                         name="visibility"
                         value="0"
                         required=""
                         id="id_visibility_0"
                         checked>
                  {% trans 'Public' %}
                </label>
                <label for="id_visibility_1">
                  <input type="radio"
                         name="visibility"
                         value="1"
                         required=""
                         id="id_visibility_1">
                  {% trans 'Followers Only' %}
                </label>
                <label for="id_visibility_2">
                  <input type="radio"
                         name="visibility"
                         value="2"
                         required=""
                         id="id_visibility_2">
                  {% trans 'Mentioned Only' %}
                </label>
              </p>
              <input type="submit"
                     {% if import_status.douban_pending %} onclick="return confirm('{% trans "Another import is in progress, starting a new import may cause issues, sure to import?" %}')" value="{% trans "Import in progress, please wait" %}" {% else %} value="{% trans 'Import' %}" {% endif %} />
            </form>
            <div hx-get="{% url 'users:import_status' %}"
                 hx-trigger="load delay:1s"
                 hx-swap="outerHTML"></div>
          </details>
        </article>
        <article>
          <details>
            <summary>{% trans 'Import Shelf or List from Goodreads' %}</summary>
            <form action="{% url 'users:import_goodreads' %}" method="post">
              {% csrf_token %}
              <div>
                {% trans 'Link to Goodreads Profile / Shelf / List' %}
                <input type="url"
                       name="url"
                       value=""
                       placeholder="https://www.goodreads.com/user/show/12345-janedoe"
                       required>
                <input type="submit"  value="{% trans 'Import' %}" />
              </div>
              <ul>
                <li>
                  Profile <code>https://www.goodreads.com/user/show/12345-janedoe</code>
                  {% trans 'want-to-read / currently-reading / read books and their reviews will be imported.' %}
                </li>
                <li>
                  Shelf <code>https://www.goodreads.com/review/list/12345-janedoe?shelf=name</code>
                  {% trans 'Shelf will be imported as a new collection.' %}
                </li>
                <li>
                  List <code>https://www.goodreads.com/list/show/155086.Popular_Highlights</code>
                  {% trans 'List will be imported as a new collection.' %}
                </li>
                <li>
                  <mark>Who Can View My Profile</mark> must be set as <mark>anyone</mark> prior to import.
                </li>
              </ul>
            </form>
          </details>
        </article>
        <article>
          <details>
            <summary>{% trans 'Import from Letterboxd' %}</summary>
            <form action="{% url 'users:import_letterboxd' %}"
                  method="post"
                  enctype="multipart/form-data">
              {% csrf_token %}
              <ul>
                <li>
                  In letterboxd.com,
                  <a href="https://letterboxd.com/settings/data/"
                     target="_blank"
                     rel="noopener">click DATA in Settings</a>;
                  or in its app, tap Advanced Settings in Settings, tap EXPORT YOUR DATA
                </li>
                <li>
                  download file with name like <code>letterboxd-username-2018-03-11-07-52-utc.zip</code>, do not unzip.
                </li>
              </ul>
              <br>
              <input type="file" name="file" required accept=".zip">
              <p>
                {% trans 'Visibility' %}:
                <br>
                <label for="l_visibility_0">
                  <input type="radio"
                         name="visibility"
                         value="0"
                         required=""
                         id="l_visibility_0"
                         checked>
                  {% trans 'Public' %}
                </label>
                <label for="l_visibility_1">
                  <input type="radio"
                         name="visibility"
                         value="1"
                         required=""
                         id="l_visibility_1">
                  {% trans 'Followers Only' %}
                </label>
                <label for="l_visibility_2">
                  <input type="radio"
                         name="visibility"
                         value="2"
                         required=""
                         id="l_visibility_2">
                  {% trans 'Mentioned Only' %}
                </label>
              </p>
              <input type="submit" value="{% trans 'Import' %}" />
              <small>
                {% trans 'Only forward changes(none->to-watch->watched) will be imported.' %}
                {% if letterboxd_task %}
                  <br>
                  {% trans 'Last import started' %}: {{ letterboxd_task.created_time }}
                  {% trans 'Status' %}: {{ letterboxd_task.get_state_display }}。
                  <br>
                  {{ letterboxd_task.message }}
                  {% if letterboxd_task.metadata.failed_urls %}
                    {% trans 'Failed links, likely due to Letterboxd error, you may have to mark them manually' %}
                    <br>
                    <textarea readonly>{% for url in letterboxd_task.metadata.failed_urls %}{{url}}&#10;{% endfor %}</textarea>
                  {% endif %}
                {% endif %}
              </small>
            </form>
          </details>
        </article>
        <article>
          <details>
            <summary>{% trans 'Import Podcast Subscriptions' %}</summary>
            <form action="{% url 'users:import_opml' %}"
                  method="post"
                  enctype="multipart/form-data">
              {% csrf_token %}
              <div>
                {% trans 'Import Method' %}：
                <label for="opml_import_mode_0">
                  <input id="opml_import_mode_0"
                         type="radio"
                         name="import_mode"
                         value="0"
                         checked>
                  {% trans 'Mark as listening' %}
                </label>
                <label for="opml_import_mode_1">
                  <input id="opml_import_mode_1" type="radio" name="import_mode" value="1">
                  {% trans 'Import as a new collection' %}
                </label>
                <br>
                {% trans 'Select OPML file' %}
                <input type="file" name="file" id="excel" required accept=".opml,.xml">
                <input type="submit"  value="{% trans 'Import' %}" />
              </div>
            </form>
          </details>
        </article>
        <article>
          <details>
            <summary>{% trans 'Export Data' %}</summary>
            <form action="{% url 'users:export_marks' %}"
                  method="post"
                  enctype="multipart/form-data">
              {% csrf_token %}
              <input type="submit"
                     {% if export_status.marks_pending %} value="{% trans 'Export in progress' %}" {% else %} value="{% trans 'Export marks and reviews' %}" {% endif %} />
              {% if export_status.marks_file %}
                <a href="{% url 'users:export_marks' %}" download>{% trans 'Download' %} {{ export_status.marks_date }}</a>
              {% endif %}
            </form>
          </details>
        </article>
        <article>
          <details>
            <summary>{% trans 'View Annual Summary' %}</summary>
            <div class="tag-list">
              {% for year in years %}
                <span>
                  <a href="{% url 'journal:wrapped' year %}">{{ year }}</a>
                </span>
              {% endfor %}
            </div>
          </details>
        </article>
        {% comment %}
        <article>
          <details>
            <summary>{% trans 'Reset visibility for all marks' %}</summary>
            <form action="{% url 'users:reset_visibility' %}" method="post">
              {% csrf_token %}
              <input type="submit"  value="{% trans 'Reset' %}" />
              <div>
                <input type="radio" name="visibility" id="visPublic" value="0" checked>
                <label for="visPublic">{% trans 'Public' %}</label>
                <input type="radio" name="visibility" id="visFollower" value="1">
                <label for="visFollower">{% trans 'Followers Only' %}</label>
                <input type="radio" name="visibility" id="visSelf" value="2">
                <label for="visSelf">{% trans 'Mentioned Only' %}</label>
              </div>
            </form>
          </details>
        </article>
        {% endcomment %}
      </div>
      {% include "_sidebar.html" with show_profile=1 identity=request.user.identity %}
    </main>
    {% include "_footer.html" %}
  </body>
</html>
