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

register = template.Library()

@register.inclusion_tag("templatetags/card_badge.html")
def card_badge(card, quantity=None, expanded=False):
    return {
        'quantity': quantity,
        'style': card.style,
        'name': card.name,
        'rarity': card.rarity_icon,
        'cardset': card.cardset,
        'expanded': expanded,
    }

@register.filter
def card_badge_inline(card, quantity=None):
    """
    Renders an inline card badge.
    """
    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,
    })
    return mark_safe(html)