@using MrCMS.Web.Apps.Ecommerce.Entities.Shipping
@using MrCMS.Web.Apps.Ecommerce.Helpers
@using MrCMS.Web.Apps.Ecommerce.Helpers.Shipping
@model MrCMS.Web.Apps.Ecommerce.Settings.Shipping.CountryBasedShippingSettings
@{
    ViewBag.Title = "Country Based Shipping Settings";
    var taxRateOptions = ViewData["tax-rate-options"] as List<SelectListItem> ?? new List<SelectListItem>();
    var calculations = ViewData["calculations"] as List<CountryBasedShippingCalculation> ?? new List<CountryBasedShippingCalculation>();
}
@using (Html.BeginForm("Configure", "CountryBasedShipping", FormMethod.Post))
{
    <fieldset>
        <legend>
            Country Based Shipping Settings
            <span class="btn-group display-inline pull-right">
                <a href="@Url.Action("Index", "ShippingMethod")" class="btn btn-default">Back</a>
                <input type="submit" class="btn btn-primary" value="Save" />
            </span>
        </legend>
        <div class="row">
            <div class="col-sm-4">
                <div class="form-group">
                    @Html.LabelFor(settings => settings.DisplayName)
                    @Html.TextBoxFor(settings => settings.DisplayName, new { @class = "form-control" })
                    @Html.ValidationMessageFor(settings => settings.DisplayName)
                </div>
                <div class="form-group">

                    @Html.LabelFor(settings => settings.Description)
                    @Html.TextBoxFor(settings => settings.Description, new { @class = "form-control" })
                    @Html.ValidationMessageFor(settings => settings.Description)
                </div>
                <div class="form-group">
                    @Html.LabelFor(settings => settings.TaxRateId)
                    @Html.DropDownListFor(settings => settings.TaxRateId, taxRateOptions, new { @class = "form-control" })
                    @Html.ValidationMessageFor(settings => settings.TaxRateId)
                </div>
            </div>
            <div class="col-sm-8">
                <fieldset>
                    <legend>
                        Rates
                        <span class="btn-group display-inline pull-right">
                            @Html.ActionLink("Add rate", "Add", "CountryBasedShippingCalculation", new { }, new { @class = "btn-sm btn-primary btn" })
                        </span>
                    </legend>

                </fieldset>
                @if (calculations.Any())
                {
                    <table class="table table-striped table-condensed" style="table-layout: fixed; word-wrap: break-word;">
                        <thead>
                            <tr>
                                <th>
                                    Description
                                </th>
                                <th>
                                    Rate
                                </th>
                                <th>
                                    Countries
                                </th>
                                <th>
                                    Actions
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var calculation in calculations)
                            {
                                <tr>
                                    <td>
                                        @calculation.GetDescription()
                                    </td>
                                    <td>
                                        @calculation.BaseAmount.ToCurrencyFormat()
                                    </td>
                                    <td>
                                        @calculation.DisplayCountries()
                                    </td>
                                    <td>
                                        <div class="btn-group">
                                            @Html.ActionLink("Edit", "Edit", "CountryBasedShippingCalculation", new { id = calculation.Id }, new { @class = "btn btn-default btn-xs"})
                                            @Html.ActionLink("Delete", "Delete", "CountryBasedShippingCalculation", new { id = calculation.Id }, new { @class = "btn btn-xs btn-danger", data_toggle = "fb-modal" })
                                        </div>
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                }
                else
                {
                    <p>There are currently no rates loaded.</p>
                }
            </div>
        </div>
    </fieldset>
}
