{#
Copyright 2024, 2025 New Vector Ltd.
Copyright 2022-2024 The Matrix.org Foundation C.I.C.

SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
-#}

{% set consent_page = true %}

{% extends "base.html" %}

{% block content %}
  {% set client_name = client.client_name or client.client_id %}

  <header class="page-heading">
    {% if client.logo_uri %}
    <img class="consent-client-icon image" referrerpolicy="no-referrer" src="{{ client.logo_uri }}" />
    {% else %}
    <div class="consent-client-icon generic">
      {{ icon.web_browser() }}
    </div>
    {% endif %}

    <div class="header">
      <h1 class="title">
        {{ _('mas.consent.continue_to', client_name=client_name) }}
      </h1>
      <p class="text [&>span]:whitespace-nowrap [&>span]:text-[var(--cpd-color-text-link-external)]">
        {{ _("mas.consent.this_will_setup", client_name=client_name, client_uri=((client.client_uri or grant.redirect_uri) | simplify_url), server_name=branding.server_name) }}
      </p>
    </div>
  </header>

  {% call(scopes) scope.unsafe_scopes(scopes=grant.scope.split(" ")) %}
    {% if scopes is not empty %}
      <section class="flex flex-col gap-3">
        <p class="text-center cpd-text-body-md-regular">
          {{ _('mas.consent.scope_list_preface', client_name=client_name) }}
        </p>
        <div class="consent-scope-list">
          {{ scope.list(scopes=scopes) }}
        </div>
      </section>
    {% endif %}
  {% endcall %}

  {% set initial -%}
    {%- if matrix_user.display_name -%}
      {{- matrix_user.display_name[0] | upper -}}
    {%- else -%}
      {{- matrix_user.mxid[1] | upper -}}
    {%- endif -%}
  {%- endset %}

  <section class="flex items-center p-4 gap-4 border border-[var(--cpd-color-gray-400)] rounded-xl">
    <div class="avatar-placeholder" data-color="{{ matrix_user.mxid | id_color_hash }}">{{ initial }}</div>
    <div class="flex flex-col">
      <div class="text-primary cpd-text-body-lg-semibold">{{ matrix_user.display_name or current_session.user.username }}</div>
      <div class="text-secondary cpd-text-body-md-regular">{{ matrix_user.mxid }}</div>
    </div>
  </section>

  <section class="flex flex-col gap-6">
    <form method="POST" class="cpd-form-root">
      <input type="hidden" name="csrf" value="{{ csrf_token }}" />
      {{ button.button(text=_("action.continue")) }}
    </form>

    {% call logout.button(csrf_token=csrf_token, post_logout_action=action) %}
      <button type="submit" class="cpd-button primary" data-kind="secondary" data-size="lg" type="submit">
        {{ _("mas.consent.use_another_account") }}
      </button>
    {% endcall %}

    {{ back_to_client.link(
      text=_("action.cancel"),
      kind="tertiary",
      uri=grant.redirect_uri,
      mode=grant.response_mode,
      params=dict(error="access_denied", state=grant.state)
    ) }}
  </section>
{% endblock content %}
