from django import template
from django.utils.safestring import mark_safe
from django.urls import reverse_lazy
from django.template.defaultfilters import pluralize
from django.db.models import Count, Q



from agenda_culturel.models import DuplicatedEvents

from .utils_extra import picto_from_name

register = template.Library()


@register.simple_tag
def show_badge_duplicated(placement="top"):

    nb_duplicated = DuplicatedEvents.not_fixed_qs().count()

    if nb_duplicated != 0:
        return mark_safe(
            '<a href="'
            + reverse_lazy("duplicates")
            + '?fixed=False" class="badge" data-placement="'
            + placement
            + '" data-tooltip="'
            + str(nb_duplicated)
            + " dupliqué"
            + pluralize(nb_duplicated)
            + ' à valider">'
            + picto_from_name("copy")
            + " "
            + str(nb_duplicated)
            + "</a>"
        )
    else:
        return ""
