{% set request = notification.context.request %}
{% set parent_community = request.receiver %}
{% set community = request.topic %}
{% set user = notification.context.executing_user %}
{% set ui = config.SITE_UI_URL %}
{% set msg_ctx = {
    "community_id": community.slug,
    "community_title": community.metadata.title,
    "parent_community_id": parent_community.slug,
    "parent_community_title": parent_community.metadata.title,
    "request_id": request.id,
    "username": user.username or user.profile.full_name,
    "ui": ui,
} %}

{# TODO: use request.links.self_html when issue issue is resolved: https://github.com/inveniosoftware/invenio-rdm-records/issues/1327 #}
{% set request_link = "{ui}/communities/{parent_community_id}/requests/{request_id}".format(**msg_ctx) %}
{% set account_settings_link = invenio_url_for("invenio_notifications_settings.index") %}

{%- block subject -%}
{{ _('⛔️ Subcommunity request declined for "{community_title}" to join "{parent_community_title}"').format(**msg_ctx) }}
{%- endblock subject -%}

{%- block html_body -%}
<table style="font-family:'Lato',Helvetica,Arial,sans-serif;border-spacing:15px">
    <tr>
        <td>{{ _('The community manager @{username} declined the request for "{community_title}" to join as a subcommunity of "{parent_community_title}".').format(**msg_ctx) }}
        </td>
    </tr>
    <tr>
        <td><a href="{{ request_link }}" class="button">{{ _("View the request")}}</a></td>
    </tr>
    <tr>
        <td><strong>—<strong></td>
    </tr>
    <tr>
        <td style="font-size:smaller">{{ _("This is an auto-generated message. To manage notifications, visit your")}} <a href="{{ account_settings_link }}">{{ _("account settings")}}</a>.</td>
    </tr>
</table>
{%- endblock html_body %}

{%- block plain_body -%}
{{ _('The community manager @{username} declined the request for "{community_title}" to join as a subcommunity of "{parent_community_title}".').format(**msg_ctx) }}

{{ _("View the request at:") }} {{ request_link }}

—
{{ _("This is an auto-generated message. To manage notifications, visit your account settings at: ") }}{{ account_settings_link }}
{%- endblock plain_body %}

{# Markdown for Slack/Mattermost/chat #}
{%- block md_body -%}
{{ _('The community manager @{username} declined the request for "{community_title}" to join as a subcommunity of "{parent_community_title}".').format(**msg_ctx) }}

[{{ _("View the request") }}]({{ request_link }})

—
{{ _("This is an auto-generated message. To manage notifications, visit your") }} [{{ _("account settings") }}]({{ account_settings_link }}).
{%- endblock md_body %}
