{% 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 "Account Information" %}</title>
    {% include "common_libs.html" %}
  </head>
  <body>
    {% include "_header.html" %}
    <main>
      <div class="grid__main">
        <article>
          <details>
            <summary>{% trans "Display name, avatar and other information" %}</summary>
            <form action="{% url 'users:profile' %}?next={{ request.path }}"
                  method="post"
                  {% if request.user.mastodon and not request.user.preference.mastodon_skip_userinfo %}onsubmit="return confirm('{% trans "Updating profile information here will turn off automatic sync of display name, bio and avatar from your Mastodon instance. Sure to continue?" %}')"{% endif %}
                  enctype="multipart/form-data">
              <label>
                {% trans "Username" %}
                <input value="{{ request.user.username }}"
                       aria-invalid="false"
                       readonly
                       disabled />
              </label>
              {% include "_field.html" with field=profile_form.name %}
              {% include "_field.html" with field=profile_form.summary %}
              {% include "_field.html" with field=profile_form.icon %}
              {% include "_field.html" with field=profile_form.discoverable %}
              {% include "_field.html" with field=profile_form.manually_approves_followers %}
              {% csrf_token %}
              <input type="submit" value="{% trans 'Save' %}" id="save">
            </form>
          </details>
        </article>
        {% if allow_any_site %}
          <article>
            <details>
              <summary>{% trans 'Email' %}</summary>
              <form action="{% url 'users:register' %}?next={{ request.path }}"
                    method="post">
                <input value="{{ request.user.username }}" type="hidden" name="username" />
                <fieldset>
                  <label>
                    {% trans "Email address" %}
                    <input type="email"
                           name="email"
                           _="on input remove [@disabled] from #save_email then remove [@aria-invalid] end"
                           {% if request.user.email_account %}value="{{ request.user.email_account.handle }}" aria-invalid="false"{% endif %}
                           placeholder="email"
                           autocomplete="email" />
                    <small>
                      {% if request.session.pending_email %}
                        {% blocktrans with pending_email=request.session.pending_email %}Please click the confirmation link in the email sent to {{ pending_email }}; if you haven't received it for more than a few minutes, please input and save again.{% endblocktrans %}
                      {% elif not request.user.email_account %}
                        {% trans "Email is recommended as a backup login method, if you log in via a Fediverse instance" %}
                      {% endif %}
                    </small>
                  </label>
                </fieldset>
                {% csrf_token %}
                <input type="submit" value="{% trans 'Save' %}" disabled id="save_email">
              </form>
            </details>
          </article>
          <article>
            <details>
              <summary>{% trans "Fediverse (Mastodon)" %}</summary>
              <form action="{% url 'mastodon:reconnect' %}" method="post">
                {% csrf_token %}
                <fieldset>
                  {% if request.user.mastodon %}
                    <label>
                      <i class="fa-brands fa-mastodon"></i> {% trans "Verified Identity" %}
                      <input type="input"
                             {% if request.user.mastodon %}aria-invalid="false"{% endif %}
                             value="{{ request.user.mastodon.handle | default:'-' }}"
                             readonly>
                      <small>
                        {% if request.user.mastodon.last_refresh %}
                          {% trans "Last updated" %} {{ request.user.mastodon.last_refresh }}
                        {% endif %}
                      </small>
                    </label>
                  {% else %}
                    <p>
                      {% blocktrans %}If you have not yet registered with any Federated instance, you may <a href="https://joinmastodon.org/zh/servers" target="_blank">choose an instance</a> and register.{% endblocktrans %}
                    </p>
                  {% endif %}
                  <label>
                    {% if request.user.mastodon %}
                      {% trans "To associate with another federated identity, please enter the domain name of the instance where the new identity is located." %}
                    {% else %}
                      {% trans "If you have registered with a Federated instance, please enter the instance domain name." %}
                    {% endif %}
                    <input type="input"
                           name="domain"
                           value=""
                           placeholder="e.g. mastodon.online"
                           _="on input remove [@disabled] from #bind end">
                  </label>
                  <input type="submit"
                         value="{% trans 'Go to target instance and authorize with the identity' %}"
                         disabled
                         id="bind" />
                  <small>
                    {% if request.user.mastodon %}
                      {% blocktrans %}After replacing the association, you may use the new Fediverse identity to log in and control data visibility. Existing data such as tags, comments, and collections will not be affected.{% endblocktrans %}
                    {% else %}
                      {% trans "Once associated with Fediverse identity, you can discover more users and use the full features of this site." %}
                    {% endif %}
                  </small>
                </fieldset>
              </form>
              {% if request.user.mastodon %}
                <form action="{% url 'mastodon:disconnect' %}"
                      method="post"
                      onsubmit="return confirm('{% trans "Once disconnected, you will no longer be able login with this identity. Are you sure to continue?" %}')">
                  {% csrf_token %}
                  <input type="submit"
                         value="{% trans 'Disconnect with this identity' %}"
                         class="secondary" />
                </form>
              {% endif %}
            </details>
          </article>
          {% if enable_threads %}
            <article>
              <details>
                <summary>{% trans "Threads.net" %}</summary>
                <form action="{% url 'mastodon:threads_reconnect' %}" method="post">
                  {% csrf_token %}
                  <fieldset>
                    {% if request.user.threads %}
                      <label>
                        <i class="fa-brands fa-threads"></i> {% trans "Verified threads.net account" %}
                        <input type="input"
                               aria-invalid="false"
                               value="{{ request.user.threads.handle }}"
                               readonly>
                        <small>
                          {% if request.user.threads.last_refresh %}
                            {% trans "Last updated" %} {{ request.user.threads.last_refresh }}
                          {% endif %}
                        </small>
                      </label>
                    {% endif %}
                    <input type="submit"
                           value="{% if request.user.threads %} {% trans 'Link with a different threads.net account' %} {% else %} {% trans "Link with a threads.net account" %} {% endif %} " />
                  </fieldset>
                </form>
                {% if request.user.threads %}
                  <form action="{% url 'mastodon:threads_disconnect' %}"
                        method="post"
                        onsubmit="return confirm('{% trans "Once disconnected, you will no longer be able login with this identity. Are you sure to continue?" %}')">
                    {% csrf_token %}
                    <input type="submit"
                           value="{% trans 'Disconnect with Threads' %}"
                           class="secondary" />
                  </form>
                {% endif %}
              </details>
            </article>
          {% endif %}
          {% if enable_bluesky %}
            <article>
              <details>
                <summary>{% trans "Bluesky (ATProto)" %}</summary>
                <form action="{% url 'mastodon:bluesky_reconnect' %}" method="post">
                  {% csrf_token %}
                  <fieldset>
                    {% if request.user.bluesky %}
                      <label>
                        <i class="fa-brands fa-bluesky"></i> {% trans "Verified ATProto identity" %}
                        <input type="input"
                               aria-invalid="false"
                               value="@{{ request.user.bluesky.handle }} {{ request.user.bluesky.uid }}"
                               readonly>
                        <small>
                          {% if request.user.bluesky.last_refresh %}
                            {% trans "Last updated" %} {{ request.user.bluesky.last_refresh }}
                          {% endif %}
                        </small>
                      </label>
                    {% endif %}
                    <input required
                           name="username"
                           autofocus
                           placeholder="{% trans 'Bluesky Login ID' %}"
                           autocorrect="off"
                           autocapitalize="off"
                           autocomplete="off"
                           spellcheck="false" />
                    <input required
                           type="password"
                           name="password"
                           placeholder="{% trans 'Bluesky app password' %}"
                           autocorrect="off"
                           autocapitalize="off"
                           autocomplete="off"
                           spellcheck="false" />
                    <input type="submit"
                           value="{% if request.user.bluesky %} {% trans 'Link with a different ATProto identity' %} {% else %} {% trans "Link with an ATProto identity" %} {% endif %} " />
                    <small>{% blocktrans %}App password can be created on <a href="https://bsky.app/settings/app-passwords" target="_blank">bsky.app</a>.{% endblocktrans %}</small>
                  </fieldset>
                </form>
                {% if request.user.bluesky %}
                  <form action="{% url 'mastodon:bluesky_disconnect' %}"
                        method="post"
                        onsubmit="return confirm('{% trans "Once disconnected, you will no longer be able login with this identity. Are you sure to continue?" %}')">
                    {% csrf_token %}
                    <input type="submit"
                           value="{% trans 'Disconnect with ATProto identity' %}"
                           class="secondary" />
                  </form>
                {% endif %}
              </details>
            </article>
          {% endif %}
        {% endif %}
        {% if request.user.social_accounts.all %}
          <article>
            <details>
              <summary>{% trans 'Sync and import social account' %}</summary>
              <form action="{% url 'users:sync_mastodon_preference' %}"
                    method="post"
                    enctype="multipart/form-data">
                {% csrf_token %}
                <fieldset>
                  <label>
                    <input type="checkbox"
                           name="mastodon_sync_userinfo"
                           {% if not request.user.preference.mastodon_skip_userinfo %}checked{% endif %}>
                    {% trans 'Sync display name, bio and avatar' %}
                  </label>
                </fieldset>
                <fieldset>
                  <label>
                    <input type="checkbox"
                           name="mastodon_sync_relationship"
                           {% if not request.user.preference.mastodon_skip_relationship %}checked{% endif %}>
                    {% trans 'Sync follow, mute and block' %}
                  </label>
                </fieldset>
                <input type="submit" value="{% trans 'Save sync settings' %}" />
                <small>
                  {% trans "New follow, mute and blocks in the associated identity may be automatically imported; removal has to be done manually." %}
                </small>
              </form>
              <form action="{% url 'users:sync_mastodon' %}"
                    method="post"
                    enctype="multipart/form-data">
                {% csrf_token %}
                <small>{% trans "Click button below to start sync now." %}</small>
                <input type="submit" value="{% trans 'Sync now' %}" />
                <small>
                  {% if request.user.mastodon.last_refresh %}
                    {% trans "Last updated" %} {{ request.user.mastodon.last_refresh }}
                  {% endif %}
                </small>
              </form>
            </details>
          </article>
        {% endif %}
        <article>
          <details>
            <summary>{% trans 'Users you are following' %}</summary>
            {% include 'users/relationship_list.html' with id="follow" list=request.user.identity.following_identities.all %}
          </details>
        </article>
        <article>
          <details>
            <summary>{% trans 'Users who follow you' %}</summary>
            {% include 'users/relationship_list.html' with id="follower" list=request.user.identity.follower_identities.all %}
          </details>
        </article>
        <article>
          <details>
            <summary>{% trans 'Users who request to follow you' %}</summary>
            {% include 'users/relationship_list.html' with id="follow_request" list=request.user.identity.requested_follower_identities.all %}
          </details>
        </article>
        <article>
          <details>
            <summary>{% trans 'Users you are muting' %}</summary>
            {% include 'users/relationship_list.html' with id="mute" list=request.user.identity.muting_identities.all %}
          </details>
        </article>
        <article>
          <details>
            <summary>{% trans 'Users you are blocking' %}</summary>
            {% include 'users/relationship_list.html' with id="block" list=request.user.identity.blocking_identities.all %}
          </details>
        </article>
        {% if allow_any_site %}
          <article>
            <details>
              <summary>{% trans 'Delete Account' %}</summary>
              <form action="{% url 'users:clear_data' %}"
                    method="post"
                    onsubmit="return confirm('{% trans "Once deleted, account data cannot be recovered. Sure to proceed?" %}');">
                {% csrf_token %}
                <div>
                  {% blocktrans %}Enter full <code>username@instance.social</code> or <code>email@domain.com</code> to confirm deletion.{% endblocktrans %}
                  <input type="email"
                         name="verification"
                         _="on input remove [@disabled] from #delete end"
                         value=""
                         autocomplete="off"
                         required
                         aria-invalid="true"
                         aria-describedby="invalid-helper"
                         placeholder="Gargron@mastodon.social">
                  <small id="invalid-helper">{% trans "Once deleted, account data cannot be recovered." %}</small>
                  {% if import_status.douban_pending %}
                    <input type="submit" value="{% trans "Importing in progress, can't delete now." %}" disabled />
                  {% else %}
                    <input type="submit"
                           value="{% trans 'Permanently Delete' %}"
                           class="contrast"
                           disabled
                           id="delete" />
                  {% endif %}
                </div>
              </form>
            </details>
          </article>
        {% endif %}
      </div>
      {% include "_sidebar.html" with show_profile=1 identity=request.user.identity %}
    </main>
    {% include "_footer.html" %}
  </body>
</html>
