{% extends 'layouts/admin.twig' %}

{% block content %}

    <ul class="breadcrumbs el">
        <li><a href="/admin/">Home</a> /</li>
        <li class="end">Delivery Rates</li>
    </ul>

    <h1>
        Delivery Rates
    </h1>

    {% include 'shop/admin/delivery/tabnav.twig' %}
    {% include 'admin/messages.twig' %}

    <form action="{{ self }}"
          method="post">

        {% for key, zone in zones %}
            <h2 id="zone{{ loop.index1 }}">
                Region {{ zone[0].zone }}
            </h2>
            <p>Zone includes following countries - <b>{{ key }}</b></p>

            {% for method in zone %}
                <fieldset class="style">
                    <h3 class="deliveryMethodName">
                        {{ method.name }}
                    </h3>

                    <div class="row">
                        <label for="service{{ method.id }}">Delivery Service</label>
                        <select name="service[{{ method.id }}]" id="service{{ method.id }}">
                            <option value="0">Select Service</option>
                            {% for service in services %}
                                <option value="{{ service.id }}" {{ method.service_id == service.id ? 'selected' : '' }}>
                                    {{ service.name }}
                                </option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="row">
                        <label for="base_cost{{ method.id }}">Base cost (&pound;)</label>
                        <input type="text"
                               class="text"
                               id="base_cost{{ method.id }}"
                               name="base_cost[{{ method.id }}]"
                               value="{{ method.cost }}"/>
                        <div class="el hint">
                            <i class="fa fa-info-circle"></i>
                            <div class="text">
                                Base cost will be applied to methods that utilize Cost per KG
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <label for="max{{ method.id }}">Free Delivery From (&pound;)</label>
                        <input type="text"
                               class="text"
                               id="max{{ method.id }}"
                               name="max[{{ method.id }}]"
                               value="{{ method.max }}"/>
                    </div>
                    <div class="row">
                        <label for="disable{{ method.id }}">Disable</label>
                        <input type="checkbox"
                               id="disable{{ method.id }}"
                               name="disable[{{ method.id }}]"
                               value="{{ 1 }}"
                               {% if method.disable %}checked{% endif %}
                        />
                    </div>

                    <div class="row">&nbsp;</div>
                    <table class="manage-items">
                        <thead>
                        <tr>
                            <th>Min Weight</th>
                            <th>Max Weight</th>
                            <th>Cost per Basket (&pound;)</th>
                            <th>Cost per kg (&pound;)</th>
                            <th align="center">Remove</th>
                        </tr>
                        </thead>
                        {% for rate in method.rates %}
                            <tr>
                                <td>
                                    <input type="text"
                                           class="text"
                                           value="{{ rate.weight_min }}"
                                           name="rates[{{ method.id }}][{{ rate.id }}][weight_min]"/>
                                </td>
                                <td>
                                    <input type="text"
                                           class="text"
                                           value="{{ rate.weight_max }}"
                                           name="rates[{{ method.id }}][{{ rate.id }}][weight_max]"/>
                                </td>
                                <td>
                                    <input type="text"
                                           class="text"
                                           value="{{ rate.line_cost }}"
                                           name="rates[{{ method.id }}][{{ rate.id }}][line_cost]"/>
                                </td>
                                <td>
                                    <input type="text"
                                           class="text"
                                           value="{{ rate.kg_cost }}"
                                           name="rates[{{ method.id }}][{{ rate.id }}][kg_cost]"/>
                                </td>
                                <td align="center">
                                    <input type="checkbox"
                                           value="1"
                                           name="rates[{{ method.id }}][{{ rate.id }}][remove]"/>
                                </td>
                            </tr>
                        {% endfor %}
                        <tr>
                            <td>
                                <input type="text"
                                       class="text"
                                       value="{{ rate.weight_min }}"
                                       name="rates[{{ method.id }}][new][weight_min]"/>
                            </td>
                            <td>
                                <input type="text"
                                       class="text"
                                       value="{{ rate.weight_max }}"
                                       name="rates[{{ method.id }}][new][weight_max]"/>
                            </td>
                            <td>
                                <input type="text"
                                       class="text"
                                       value="{{ rate.line_cost }}"
                                       name="rates[{{ method.id }}][new][line_cost]"/>
                            </td>
                            <td>
                                <input type="text"
                                       class="text"
                                       value="{{ rate.kg_cost }}"
                                       name="rates[{{ method.id }}][new][kg_cost]"/>
                            </td>
                            <td align="center">
                                New
                            </td>
                        </tr>
                    </table>
                </fieldset>
                <div class="row">&nbsp;</div>
            {% endfor %}
        {% endfor %}

        <div class="row">
            <button type="submit"
                    name="action"
                    class="btn"
                    value="update">
                Save
            </button>
        </div>
    </form>

{% endblock %}