@model ShippingMethodRestrictionModel


@using (Html.BeginForm())
{
    <div class="section-header">
        <div class="title">
            <img src="@Url.Content("~/Administration/Content/images/ico-configuration.png")" alt="" />
            @T("Admin.Configuration.Shipping.Restrictions")
        </div>
        <div class="options">
            <button type="submit" name="save" value="save" class="t-button">@T("Admin.Common.Save")</button>
        </div>
    </div>
    
    <table class="adminContent">
        <tr>
            <td>
                @T("Admin.Configuration.Shipping.Restrictions.Description")
                <br />
                <br />
                @if (Model.AvailableCountries.Count == 0)
                {
                    <text>No countries defined</text>
                }
                else if (Model.AvailableShippingMethods.Count == 0)
                {
                    <text>No shipping methods available</text>
                }
                else
                {
                    
                    
                    <script type="text/javascript">
        $(document).ready(function () {            
            @foreach (var sm in Model.AvailableShippingMethods)
            {
            <text> 
                $('#selectall-@(sm.Id)').bind('click', function() {
                        var checked = $('#selectall-@(sm.Id)').attr("checked");
                        $('.restrict_@(sm.Id)').attr("checked",checked);
                });
            </text>
            }
        });
                    </script>
                    
                    <table class="tablestyle" cellspacing="0" rules="all" border="1" style="width: 100%;
                        border-collapse: collapse;">
                        <tbody>
                            <tr class="headerstyle">
                                <th scope="col">
                                    <b>@T("Admin.Configuration.Shipping.Restrictions.Country")</b>
                                </th>
                                @foreach (var sm in Model.AvailableShippingMethods)
                                {
                                    <th scope="col">
                                        <b>@sm.Name</b>
                                        <input type="checkbox" id="selectall-@(sm.Id)" />
                                    </th>
                                }
                            </tr>
                            @{
                                bool altRow = true;
                            }
                            @foreach (var c in Model.AvailableCountries)
                            {
                                altRow = !altRow;
                                <tr class="@(altRow ? "altrowstyle" : "rowstyle")">
                                    <td>
                                        <span>@c.Name</span>
                                    </td>
                                    @foreach (var sm in Model.AvailableShippingMethods)
                                    {
                                        var restricted = Model.Restricted.ContainsKey(c.Id) && Model.Restricted[c.Id][sm.Id];
                                        <td>
                                            <input id="restrict_@(sm.Id)" class="restrict_@(sm.Id)" type="checkbox" value="@(c.Id)" name="restrict_@(sm.Id)" @(restricted ? " checked=checked" : null) />
                                        </td>
                                    }
                                </tr>
                            }
                        </tbody>
                    </table>
                }
            </td>
        </tr>
    </table>

}
