<article class="post-card quiz-card card-link-host">
    {% set _href = item.url %}
    {% set _label = item.title or 'View quiz' %}
    {% include "_card_link.html" %}

    <div class="quiz-card-head">
        {% set _size = 32 %}{% set _size_class = "sm" %}{% set _user = item.author %}{% include "_avatar_link.html" %}
        <div class="quiz-card-byline">
            {% set _user = item.author %}{% set _class = none %}{% include "_user_link.html" %}
            <span class="meta-muted">&middot; {{ dt_ago(item.created_at) if item.created_at else item.time_ago }}</span>
        </div>
        {% if item.viewer_state == 'done' %}
        <span class="quiz-state-badge quiz-state-done">Completed - {{ format_number(item.viewer_best_percent) }}%</span>
        {% elif item.viewer_state == 'in_progress' %}
        <span class="quiz-state-badge quiz-state-progress">In progress</span>
        {% else %}
        <span class="quiz-state-badge quiz-state-todo">Not started</span>
        {% endif %}
    </div>

    <a href="{{ item.url }}" class="post-title-link">
        <h3 class="post-title rendered-title">{{ render_title(item.title, author_is_admin=is_admin(item.author)) }}</h3>
    </a>

    {% if item.description %}
    <div class="post-content rendered-content">{{ render_content(item.description[:300] ~ ('...' if item.description|length > 300 else ''), author_is_admin=is_admin(item.author)) }}</div>
    {% endif %}

    <div class="quiz-card-meta">
        <span class="quiz-meta-chip"><span aria-hidden="true">❓</span> {{ item.question_count }} questions</span>
        <span class="quiz-meta-chip"><span aria-hidden="true">🎯</span> {{ item.total_points }} points</span>
        {% if item.time_limit_seconds %}
        <span class="quiz-meta-chip"><span aria-hidden="true">⏱️</span> {{ format_duration(item.time_limit_seconds) }}</span>
        {% endif %}
        {% if item.pass_percent %}
        <span class="quiz-meta-chip"><span aria-hidden="true">✅</span> Pass at {{ item.pass_percent }}%</span>
        {% endif %}
        <span class="quiz-meta-chip"><span aria-hidden="true">👥</span> {{ item.attempt_count }} attempts</span>
    </div>

    <div class="post-actions">
        {% set _type = "quiz" %}{% set _uid = item.uid %}{% set _my_vote = item.my_vote %}{% set _count = item.stars %}{% set _btn_class = "post-action-btn" %}{% set _stop = true %}{% include "_star_vote.html" %}
        <a href="{{ item.url }}" class="post-action-btn" aria-label="{% if user %}{{ item.comment_count }} comments{% else %}Comments{% endif %}">
            <span aria-hidden="true">&#x1F4AC;</span>{% if user %} {{ item.comment_count }}{% endif %}
        </a>
        {% set _type = "quiz" %}{% set _uid = item.uid %}{% set _reactions = item.reactions %}{% include "_reaction_bar.html" %}
        {% set _type = "quiz" %}{% set _uid = item.uid %}{% set _bookmarked = item.bookmarked %}{% include "_bookmark_button.html" %}
        {% if item.viewer_state == 'in_progress' and item.viewer_attempt_uid %}
        <a href="{{ item.url }}/attempts/{{ item.viewer_attempt_uid }}" class="post-action-btn quiz-card-cta">Resume</a>
        {% elif item.viewer_state == 'done' %}
        <a href="{{ item.url }}/attempts/{{ item.viewer_attempt_uid }}/results" class="post-action-btn">Results</a>
        <form method="POST" action="{{ item.url }}/attempts" class="inline-form" data-stop-propagation>
            <button type="submit" class="post-action-btn quiz-card-cta" {{ guest_disabled(user) }}>Play again</button>
        </form>
        {% else %}
        <form method="POST" action="{{ item.url }}/attempts" class="inline-form" data-stop-propagation>
            <button type="submit" class="post-action-btn quiz-card-cta" {{ guest_disabled(user) }}>Start</button>
        </form>
        {% endif %}
    </div>

    {% if item.recent_comments %}
    {% from "_comment.html" import render_comment with context %}
    <div class="post-card-comments">
        {% for c in item.recent_comments %}
        {{ render_comment(c, 0) }}
        {% endfor %}
    </div>
    {% endif %}
</article>
