from django.template import Library

from minecraft_manager.models import Player
from django.urls import reverse
from django.utils.html import mark_safe

register = Library()


@register.simple_tag(name="player_reverse_name")
def reverse_name(username):
    player = Player.objects.get(username=username)
    url = "{}{}".format(reverse('player'), player.id)
    return mark_safe('<a href="{}">{}</a>'.format(url, player.username))


@register.simple_tag(name="player_reverse_id")
def reverse_id(player_id):
    player = Player.objects.get(id=player_id)
    url = "{}{}".format(reverse('player'), player.id)
    return mark_safe('<a href="{}">{}</a>'.format(url, player.username))
