{% load rating_tags %}

<div>
    {% get_rating object_info=object_info settings=settings as RATING %}
    {% get_user_rate request=request rating=RATING as USER_RATE %}

    {% if request.user.is_authenticated %}
        <form id="rating-{{ RATING.urlhash }}" method="post" action="{% url 'rating:create' %}" user_rate="{{ USER_RATE }}" class="rating space">

            <input type="hidden" name="app_name" value="{{ object_info.app_name }}" hidden>
            <input type="hidden" name="object_id" value="{{ object_info.object_id }}" hidden>
            <input type="hidden" name="model_name" value="{{ object_info.model_name }}" hidden>
            <input type="hidden" name="content_type" value="{{ object_info.content_type }}" hidden>
            <input type="hidden" name="settings_slug" value="{{ settings.slug }}" hidden>

            <input type="radio" name="rating-{{ RATING.urlhash }}" value="-1" class="sr-only" {% if USER_RATE is None %}checked{% endif %}/>
            {% if settings.from_zero %}
                <input type="radio" name="rating-{{ RATING.urlhash }}" value="0" class="rating-hidden" {% if USER_RATE == 0 %}checked{% endif %}/>
            {% endif %}

            {% for _ in ''|center:settings.rates %}
                <input type="radio" id="rate-{{ RATING.urlhash }}-{{ forloop.counter }}" name="rating-{{ RATING.urlhash }}" value="{{ forloop.counter }}" class="sr-only" {% if USER_RATE == forloop.counter %}checked{% endif %}/>
                <label for="rate-{{ RATING.urlhash }}-{{ forloop.counter }}">
                    <img src="{{ settings.icon.url }}" alt="{{ forloop.counter }}" style="height: {{ settings.height }}">
                </label>
            {% endfor %}

        </form>
    {% else %}
        <div class="rating space">
            {% for _ in ''|center:settings.rates %}
                <span class="rating-disable">
                <img src="{{ settings.icon.url }}" alt="{{ forloop.counter }}" style="height: {{ settings.height }}">
            </span>
            {% endfor %}
        </div>
    {% endif %}
</div>
