{% load i18n lfs_tags %}

<div class="navigation-pages-inline">
    {% if page.has_previous %}
        <a class="ajax-link"
           href="{% url lfs_pg_products_inline property_group.id %}?page=1"><img src="{{ STATIC_URL }}icons/resultset_first.png" alt='{% trans "First" %}' /></a>
        <a class="ajax-link"
           href="{% url lfs_pg_products_inline property_group.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" %}' />
    {% 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_pg_products_inline property_group.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_pg_products_inline property_group.id %}?page={{ paginator.num_pages }}"><img src="{{ STATIC_URL }}icons/resultset_last.png"  alt='{% trans "Last" %}' /></a>
    {% else %}
        <img src="{{ STATIC_URL }}icons/resultset_next.png" alt='{% trans "Next" %}' />
        <img src="{{ STATIC_URL }}icons/resultset_last.png"  alt='{% trans "Last" %}' />
    {% endif %}
</div>

<table class="lfs-manage-table" style="margin-top:20px">
    <tr>
        <td width="50%">
            <h2>{% trans 'Products' %}</h2>
            <form id="add-products-form"
                  action="{% url lfs_assign_products_to_property_group property_group.id %}"
                  method="post">
                <div id="property-products-left">
                    <table class="lfs-manage-table">
                        <tr>
                            <th class="checkbox">
                                <input type="checkbox"
                                       class="select-all"
                                       value="products" />
                            </th>
                            <th>
                                {% 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-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" />

                <div class="buttons">
                    <input type="submit"
                           class="ajax-save-button button"
                           value="{% trans 'Add to product group' %}" />
                </div>
            </form>
        </td>
        <td width="50%">
            <h2>{% trans 'Assigned products' %}</h2>
            <form id="products-update-form"
                  action="{% url lfs_pg_remove_products property_group.id %}"
                  method="post">
                <div id="property-products-right">
                    <table class="lfs-manage-table">
                        <tr>
                            <th class="checkbox">
                                <input type="checkbox"
                                       class="select-all"
                                       value="assigned-products" />
                            </th>
                            <th>
                                {% trans 'Name' %}
                            </th>
                            <th>
                                {% trans 'SKU' %}
                            </th>
                            <th class="tiny right-padding">
                                {% trans 'Active' %}
                            </th>
                        </tr>

                        {% for product in group_products %}
                            <tr>
                                <td>
                                    <input type="checkbox"
                                           name="product-{{ product.id }}"
                                           class="select-assigned-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" />

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