{% extends "_layout.html.j2" %}

{%- block title -%}
Your account
{%- endblock -%}

{%- block content -%}
<div class="panel">
    <h1>Manage your account</h1>
    {{ user_card }}
    {% match body %}
        {% when AccountBody::Unlocked { suspended, email_requirement, email, devices, oidc_enabled, dehydrated_device_id } %}
            {% if suspended %}
                <p class="card danger">
                    ⚠️ Your account has been suspended by your homeserver's administrator.
                    Some functionality may be restricted.
                </p>
            {% endif %}
            <section>
                {% if email_requirement.may_view() %}
                    <p>
                        {% if let Some(email) = email %}
                            Your account's associated email address is <code>{{ email }}</code>.
                        {% else %}
                            Your account has no associated email address.
                        {% endif %}
                        {% if email_requirement.may_change() %}
                            <a href="email/change/">Change your email</a>
                        {% endif %}
                    </p>
                {% endif %}
                {% if !oidc_enabled %}
                    <p>
                        <a href="password/change">Change your password</a>
                    </p>
                {% endif %}
            </section>

            <section>
                <a class="button fullwidth" href="logout">Log out</a>
            </section>

            <section>
                <details>
                    <summary>Your devices ({{ devices.len() }})</summary>
                    <div class="card-list" id="devices">
                        {% for device in devices %}
                            {{ device }}
                        {% else %}
                            <span>
                                Your account has no devices. <a href="https://matrix.org/ecosystem/clients">Choose a client</a>
                                and sign in to start chatting on Matrix.
                            </span>
                        {% endfor %}
                        {% if let Some(dehydrated_device_id) = dehydrated_device_id %}
                            <small>⊡ Your account has a dehydrated device. <a href="device/{{ dehydrated_device_id | urlencode_strict }}/">View details</a></small>
                        {% endif %}
                    </div>
                </details>
            </section>

            <section>
                <details>
                    <summary>Danger zone</summary>
                    <p>
                        Settings here <em class="negative">may affect the integrity of your account</em>.
                    </p>
                    <ul class="bullet-separated">
                        <li><a href="cross_signing_reset">Reset your digital identity</a></li>
                        <li><a href="deactivate">Deactivate your account</a></li>
                    </ul>
                </details>
            </section>
        {% when AccountBody::Locked %}
            <p class="card danger">
                ⚠️ Your account has been locked by your homeserver's administrator.
            </p>
            <section>
                <a class="button fullwidth" href="logout">Log out</a>
            </section>
    {% endmatch %}
</div>
{%- endblock -%}
