from django import template
from django.utils.safestring import mark_safe
from django.urls import reverse_lazy
from django.template.defaultfilters import pluralize


from agenda_culturel.models import Message

from .utils_extra import picto_from_name

register = template.Library()


@register.simple_tag
def show_badge_messages(placement="top"):
    nb_open = Message.nb_open_messages()
    if nb_open != 0:
        return mark_safe(
            '<a href="'
            + reverse_lazy("messages")
            + '?closed=False&message_type=contact_form&message_type=event_report&message_type=from_contributor" class="badge" data-placement="'
            + placement
            + '" data-tooltip="'
            + str(nb_open)
            + " message"
            + pluralize(nb_open)
            + ' à traiter">'
            + picto_from_name("mail")
            + " "
            + str(nb_open)
            + "</a>"
        )
    else:
        return ""
