from django import template
from components.views import get_vote_data

register = template.Library()


@register.inclusion_tag('components/vote_button.html', takes_context=True)
def vote_button(context, content_type, content_id):
    """
    Render a vote button with automatic vote count fetching.
    
    Usage:
        {% load vote_tags %}
        {% vote_button 'tool' 'species-alert-report' %}
    """
    request = context['request']
    vote_data = get_vote_data(request, content_type, content_id)
    
    return {
        'content_type': content_type,
        'content_id': content_id,
        'vote_count': vote_data['vote_count'],
        'has_voted': vote_data['has_voted'],
    }

