{% load i18n lfs_tags %}

<div id="related-products-inline">
    <div class="navigation-pages-inline">
        {% if page.has_previous %}
            <a class="ajax-link"
               href="{% url lfs.manage.views.manage_related_products_inline product.id%}?page=1"><img src="{{ STATIC_URL }}icons/resultset_first.png" alt='{% trans "First" %}' /></a>
            <a class="ajax-link"
               href="{% url lfs.manage.views.manage_related_products_inline product.id%}?page={{ page.previous_page_number }}"><img src="{{ STATIC_URL }}icons/resultset_previous.png" alt='{% trans "Previous" %}' /></a>
        {% else %}
            <img src="{{ STATIC_URL }}icons/resultset_first.png" alt='{% trans "First" %}' />
            <img src="{{ STATIC_URL }}icons/resultset_previous.png" alt='{% trans "Previous" %}' /></span>
        {% endif %}

        <span style="position: relative; top:-4px ">
            {{ page.number }} {% trans "of" %} {{ paginator.num_pages }}
        </span>

        {% if page.has_next %}
            <a class="ajax-link"
               href="{% url lfs.manage.views.manage_related_products_inline product.id%}?page={{ page.next_page_number }}"><img src="{{ STATIC_URL }}icons/resultset_next.png" alt='{% trans "Next" %}' /></a>
            <a class="ajax-link"
               href="{% url lfs.manage.views.manage_related_products_inline product.id%}?page={{ paginator.num_pages }}"><img src="{{ STATIC_URL }}icons/resultset_last.png"  alt='{% trans "Last" %}' /></a>

        {% else %}
            <span><img src="{{ STATIC_URL }}icons/resultset_next.png" alt='{% trans "Next" %}' /></span>
            <span><img src="{{ STATIC_URL }}icons/resultset_last.png" alt='{% trans "Last" %}' /></span>
        {% endif %}
    </div>
    <table class="lfs-manage-table" style="margin-top:20px">
        <tr>
            <td width="50%">
                <h2>{% trans "Selectable products" %}</h2>
                <form id="add-related-products-form"
                      action="{% url lfs.manage.views.add_related_products product.id %}"
                      method="post">

                    <div id="related-products-left" style="padding-bottom:10px">
                        <table class="lfs-manage-table">
                            <tr>
                                <th class="checkbox">
                                    <input type="checkbox"
                                           class="select-all"
                                           value="related-products" />
                                </th>
                                <th class="middle">
                                    {% trans 'Name' %}
                                </th>
                                <th>
                                    {% trans 'SKU' %}
                                </th>
                                <th class="tiny right-padding">
                                    {% trans 'Active' %}
                                </th>
                            </tr>
                            {% for product in page.object_list %}
                                <tr class="{% cycle 'even' 'odd' %}">
                                    <td>
                                        <input type="checkbox"
                                               name="product-{{ product.id }}"
                                               class="select-related-products" />
                                    </td>
                                    <td>
                                        <a href="{% url lfs_manage_product product.id %}">
                                            {{ product.get_name }}
                                        </a>
                                    </td>
                                    <td>
                                        {{ product.get_sku }}
                                    </td>
                                    <td class="right-padding">
                                        {% if product.is_active %}
                                            <img src="{{ STATIC_URL }}icons/tick.png" />
                                        {% else %}
                                            <img src="{{ STATIC_URL }}icons/cross.png" />
                                        {% endif %}
                                    </td>
                                </tr>
                            {% endfor %}
                        </table>
                    </div>

                    <input type="hidden"
                           name="keep-filters"
                           value="1" />

                    <input type="submit"
                           class="ajax-save-button button"
                           value="{% trans 'Add to related products' %}" />

                </form>
            </td>
            <td width="50%">
                <h2>{% trans "Selected products" %}</h2>
                <form id="remove-related-products-form"
                      action="{% url lfs.manage.views.remove_related_products product.id %}"
                      method="post">
                    <div id="related-products-right" style="padding-bottom:10px">
                        <table class="lfs-manage-table">
                            <tr>
                                <th class="checkbox">
                                    <input type="checkbox"
                                           class="select-all"
                                           value="selected-related-products" />
                                </th>
                                <th class="middle">
                                    {% trans 'Name' %}
                                </th>
                                <th>
                                    {% trans 'SKU' %}
                                </th>
                                <th class="tiny right-padding">
                                    {% trans 'Active' %}
                                </th>
                            </tr>

                            {% for related_product in related_products %}
                                <tr class="{% cycle 'even' 'odd' %}">
                                    <td>
                                        <input type="checkbox"
                                               name="product-{{ related_product.id }}"
                                               class="select-selected-related-products" />
                                    </td>
                                    <td>
                                        <a href="{% url lfs_manage_product related_product.id %}">
                                            {{ related_product.get_name }}
                                        </a>
                                    </td>
                                    <td>
                                        {{ related_product.get_sku }}
                                    </td>
                                    <td class="right-padding">
                                        {% if related_product.is_active %}
                                            <img src="{{ STATIC_URL }}icons/tick.png" />
                                        {% else %}
                                            <img src="{{ STATIC_URL }}icons/cross.png" />
                                        {% endif %}
                                    </td>
                                </tr>
                            {% endfor %}
                        </table>
                    </div>

                    <input type="hidden"
                           name="keep-filters"
                           value="1" />

                    <input type="submit"
                           class="ajax-save-button button"
                           value="{% trans 'Remove from related products' %}" />
                </form>
            </td>
        </tr>
    </table>
</div>
<script>
    align_buttons("#related-products");
</script>