{%- import "utils.html" as utils with context -%}
{% extends "layout.html" %}

{% block head %}
<title>{{ local_actor.display_name }} - Notifications</title>
{% endblock %}

{% macro notif_actor_action(notif, text) %}
    <div class="actor-action">
        <a href="{{ url_for("admin_profile") }}?actor_id={{ notif.actor.ap_id }}">{{ notif.actor.display_name | clean_html(notif.actor) | safe }}</a> {{ text }}
        <span title="{{ notif.created_at.isoformat() }}">{{ notif.created_at | timeago }}</span>
    </div>
{% endmacro %}

{% block content %}
    <div class="box">
    <h2>Notifications</h2>
    </div>
    <div id="notifications">
    {%- for notif in notifications %}
    <div>
            {%- if notif.notification_type.value == "new_follower" %}
                {{ notif_actor_action(notif, "followed you") }}
                {{ utils.display_actor(notif.actor, actors_metadata) }}
            {%- elif notif.notification_type.value == "pending_incoming_follower" %}
                {{ notif_actor_action(notif, "sent a follow request") }}
                {{ utils.display_actor(notif.actor, actors_metadata, pending_incoming_follow_notif=notif) }}
            {% elif notif.notification_type.value == "rejected_follower" %}
            {% elif notif.notification_type.value == "unfollow" %}
                {{ notif_actor_action(notif, "unfollowed you") }}
                {{ utils.display_actor(notif.actor, actors_metadata) }}
            {%- elif notif.notification_type.value == "follow_request_accepted" %}
                {{ notif_actor_action(notif, "accepted your follow request") }}
                {{ utils.display_actor(notif.actor, actors_metadata) }}
            {%- elif notif.notification_type.value == "follow_request_rejected" %}
                {{ notif_actor_action(notif, "rejected your follow request") }}
                {{ utils.display_actor(notif.actor, actors_metadata) }}
            {% elif notif.notification_type.value == "like" %}
                {{ notif_actor_action(notif, "liked a post") }}
                {{ utils.display_object(notif.outbox_object) }}
           {% elif notif.notification_type.value == "undo_like" %}
                {{ notif_actor_action(notif, "unliked a post") }}
                {{ utils.display_object(notif.outbox_object) }}
            {% elif notif.notification_type.value == "announce" %}
                {{ notif_actor_action(notif, "shared a post") }}
                {{ utils.display_object(notif.outbox_object) }}
           {% elif notif.notification_type.value == "undo_announce" %}
                {{ notif_actor_action(notif, "unshared a post") }}
                {{ utils.display_object(notif.outbox_object) }}
            {% elif notif.notification_type.value == "mention" %}
                {{ notif_actor_action(notif, "mentioned you") }}
                {{ utils.display_object(notif.inbox_object) }}
            {% elif notif.notification_type.value == "new_webmention" %}
                <div class="actor-action" title="{{ notif.created_at.isoformat() }}">
                    new webmention from 
                    {% set facepile_item = notif.webmention.as_facepile_item %}
                    {% if facepile_item %}
                        <a href="{{ facepile_item.actor_url }}">{{ facepile_item.actor_name }}</a>
                    {% endif %}
                    <a style="font-weight:bold;" href="{{ notif.webmention.source }}">{{ notif.webmention.source }}</a>
                </div>
                {{ utils.display_object(notif.outbox_object) }}
            {% elif notif.notification_type.value == "updated_webmention" %}
                <div class="actor-action" title="{{ notif.created_at.isoformat() }}">
                    updated webmention from 
                    {% set facepile_item = notif.webmention.as_facepile_item %}
                    {% if facepile_item %}
                        <a href="{{ facepile_item.actor_url }}">{{ facepile_item.actor_name }}</a>
                    {% endif %}
                    <a style="font-weight:bold;" href="{{ notif.webmention.source }}">{{ notif.webmention.source }}</a>
                </div>
                {{ utils.display_object(notif.outbox_object) }}
            {% elif notif.notification_type.value == "deleted_webmention" %}
                <div class="actor-action" title="{{ notif.created_at.isoformat() }}">
                    deleted webmention from 
                    {% set facepile_item = notif.webmention.as_facepile_item %}
                    {% if facepile_item %}
                        <a href="{{ facepile_item.actor_url }}">{{ facepile_item.actor_name }}</a>
                    {% endif %}
                    <a style="font-weight:bold;" href="{{ notif.webmention.source }}">{{ notif.webmention.source }}</a>
                </div>
                {{ utils.display_object(notif.outbox_object) }}
            {% else %}
            <div class="actor-action">
                Implement {{ notif.notification_type }}
            </div>
            {%- endif %}
    </div>
    {%- endfor %}
    </div>
{% endblock %}