from django import template
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe
from django.urls import reverse

register = template.Library()

@register.inclusion_tag("templatetags/card_badge.html")
def card_badge(card, quantity=None, expanded=False):
    url = reverse('cards:card_detail', args=[card.pk])
    return {
        'quantity': quantity,
        'style': card.style,
        'name': card.name,
        'rarity': card.rarity_icon,
        'cardset': card.cardset,
        'expanded': expanded,
        'url': url,
    }

@register.filter
def card_badge_inline(card, quantity=None):
    """
    Renders an inline card badge.
    """
    url = reverse('cards:card_detail', args=[card.pk])
    html = render_to_string("templatetags/card_badge.html", {
        'quantity': quantity,
        'style': card.style,
        'name': card.name,
        'rarity': card.rarity_icon,
        'cardset': card.cardset,
        'expanded': True,
        'url': url,
    })
    return mark_safe(html)

@register.filter
def addstr(arg1, arg2):
    """concatenate arg1 & arg2"""
    return str(arg1) + str(arg2)