{% load bookwyrm_tags %}
{% load i18n %}
<form class="is-flex-grow-1" name="{{ type }}" action="/post/{% if type == 'direct' %}status{% else %}{{ type }}{% endif %}" method="post" id="tab-{{ type }}-{{ book.id }}{{ reply_parent.id }}">
    {% csrf_token %}
    <input type="hidden" name="book" value="{{ book.id }}">
    <input type="hidden" name="user" value="{{ request.user.id }}">
    <input type="hidden" name="reply_parent" value="{{ reply_parent.id }}">
    {% if type == 'review' %}
    <div class="control">
        <label class="label" for="id_name_{{ book.id }}_{{ type }}">{% trans "Title" %}:</label>
        <input type="text" name="name" maxlength="255" class="input" required="" id="id_name_{{ book.id }}_{{ type }}" placeholder="My {{ type }} of '{{ book.title }}'">
    </div>
    {% endif %}
    <div class="control">
        {% if type != 'reply' and type != 'direct'  %}
        <label class="label" for="id_{% if type == 'quotation' %}quote{% else %}content{% endif %}_{{ book.id }}_{{ type }}">
            {% if type == 'comment' %}
            {% trans "Comment:" %}
            {% elif type == 'quotation' %}
            {% trans "Quote:" %}
            {% elif type == 'review' %}
            {% trans "Review:" %}
            {% endif %}
        </label>
        {% endif %}

        {% if type == 'review' %}
        <fieldset>
            <legend class="is-sr-only">{% trans "Rating" %}</legend>
            <div class="field is-grouped stars form-rate-stars">
                <label class="is-sr-only" for="no-rating-{{ book.id }}">{% trans "No rating" %}</label>
                <input class="is-sr-only" type="radio" name="rating" value="" id="no-rating-{{ book.id }}" checked>
                {% for i in '12345'|make_list %}
                <input class="is-sr-only" id="book{{book.id}}-star-{{ forloop.counter }}" type="radio" name="rating" value="{{ forloop.counter }}">
                <label class="icon icon-star-empty" for="book{{book.id}}-star-{{ forloop.counter }}">
                    <span class="is-sr-only">{{ forloop.counter }} star{{ forloop.counter | pluralize }}</span>
                </label>
                {% endfor %}
            </div>
        </fieldset>
        {% endif %}

        {% if type == 'quotation' %}
        <textarea name="quote" class="textarea" id="id_quote_{{ book.id }}_{{ type }}" placeholder="{{ placeholder }}" required></textarea>
        {% else %}
        {% include 'snippets/content_warning_field.html' with parent_status=status %}
        <textarea name="content" class="textarea" id="id_content_{{ type }}-{{ book.id }}{{reply_parent.id}}" placeholder="{{ placeholder }}" {% if type == 'reply' %} aria-label="Reply"{% endif %} required>{% if reply_parent %}{{ reply_parent|mentions:request.user }}{% endif %}{% if mentions %}@{{ mentions|username }} {% endif %}</textarea>
        {% endif %}
    </div>
    {% if type == 'quotation' %}
    <div class="control">
        <label class="label" for="id_content_quote-{{ book.id }}">{% trans "Comment" %}:</label>
        {% include 'snippets/content_warning_field.html' with parent_status=status %}
        <textarea name="content" class="textarea is-small" id="id_content_quote-{{ book.id }}"></textarea>
    </div>
    {% elif type == 'comment' %}
    <div class="control">
        {% active_shelf book as active_shelf %}
        {% if active_shelf.shelf.identifier == 'reading' and book.latest_readthrough %}

        {% with readthrough=book.latest_readthrough %}
        <div class="field">
            <input type="hidden" name="id" value="{{ readthrough.id }}"/>
            <label class="label" for="progress-{{ uuid }}">{% trans "Progress:" %}</label>
            <div class="field has-addons mb-0">
                <div class="control">
                    <input aria-label="{% if readthrough.progress_mode == 'PG' %}Current page{% else %}Percent read{% endif %}" class="input" type="number" min="0" name="progress" size="3" value="{{ readthrough.progress|default:'' }}" id="progress-{{ uuid }}">
                </div>
                <div class="control select">
                    <select name="progress_mode" aria-label="Progress mode">
                        <option value="PG" {% if readthrough.progress_mode == 'PG' %}selected{% endif %}>{% trans "pages" %}</option>
                        <option value="PCT" {% if readthrough.progress_mode == 'PCT' %}selected{% endif %}>{% trans "percent" %}</option>
                    </select>
                </div>
            </div>
            {% if readthrough.progress_mode == 'PG' and book.pages %}
            <p class="help">{% blocktrans with pages=book.pages %}of {{ pages }} pages{% endblocktrans %}</p>
            {% endif %}
        </div>
        {% endwith %}
        {% endif %}
    </div>
    {% endif %}
    <input type="checkbox" class="hidden" name="sensitive" id="id_show_spoilers-{{ uuid }}" {% if status.content_warning %}checked{% endif %} aria-hidden="true">
    {# bottom bar #}
    <div class="columns pt-1">
        <div class="field has-addons column">
            <div class="control">
                {% trans "Include spoiler alert" as button_text %}
                {% include 'snippets/toggle/toggle_button.html' with text=button_text icon="warning is-size-4" controls_text="spoilers" controls_uid=uuid focus="id_content_warning" checkbox="id_show_spoilers" class="toggle-button" pressed=status.content_warning %}
            </div>
            <div class="control">
            {% if type == 'direct' %}
                <input type="hidden" name="privacy" value="direct">
                <button type="button" class="button" aria-label="Privacy" disabled>{% trans "Private" %}</button>
            {% else %}
                {% include 'snippets/privacy_select.html' with current=reply_parent.privacy %}
            {% endif %}
            </div>
        </div>
        <div class="column is-narrow">
            <button class="button is-link" type="submit">{% trans "Post" %}</button>
        </div>
    </div>
</form>