@using MrCMS.Web.Apps.Ecommerce.Settings
@using MrCMS.Helpers
@{
    ViewBag.Title = "Tax Rates";
    var taxSettings = (ViewData["settings"] as TaxSettings);
}
@{ Html.IncludeScript("~/Apps/Ecommerce/Areas/Admin/Content/Scripts/custom/tax-rates.js");}
@using (Html.BeginForm("Settings", "TaxRate", FormMethod.Post, new {id = "Settings"}))
{
    <fieldset>
        <legend>Tax  
            
            @if (taxSettings.TaxesEnabled)
            {
                <span class="btn-group display-inline pull-right" id="add-tax-rate"><a href="@Url.Action("Add", "TaxRate")" class="btn btn-primary" data-toggle="fb-modal">Add Tax Rate</a> </span>
            }
        </legend>
    </fieldset>
    <div class="checkbox">
        <label class="checkbox">@Html.CheckBox("TaxesEnabled", taxSettings.TaxesEnabled) Enable Taxes?</label>
    </div>
    
    if (!String.IsNullOrWhiteSpace(ViewBag.Status))
    {
        <div class="alert alert-info">
            To enable taxes, please first <a href="@Url.Action("Add", "TaxRate", new {source = "settings"})" data-toggle="fb-modal">set up</a> a default tax rate <a class="btn btn-default" href="@Url.Action("Add", "TaxRate", new {source = "settings"})" data-toggle="fb-modal">here</a>
        </div>
    }

    if (taxSettings.TaxesEnabled)
    {
        <h4>Tax Categories</h4>

        if (Model.Count > 0)
        {
            <table class="table table-condensed table-striped">
                <thead>
                    <tr>
                        <th>Name
                        </th>
                        <th>Code
                        </th>
                        <th>Rate Percentage
                        </th>
                        <th>Is Default Rate?
                        </th>
                        <th>Actions
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var rate in Model)
                    {
                        <tr>
                            <td>
                                @rate.Name
                            </td>
                            <td>
                                @rate.Code
                            </td>
                            <td>
                                @rate.Percentage
                            </td>
                            <td>
                                @rate.IsDefault
                            </td>
                            <td>
                                <div class="btn-group">
                                    @Html.FormLink("Make Default", "MakeDefault", "TaxRate", new {id = rate.Id}, new {@class = "btn btn-xs btn-default"})
                                    @Html.ActionLink("Edit", "Edit", new {id = rate.Id}, new {@class = "btn btn-xs btn-default"})
                                    @Html.ActionLink("Delete", "Delete", new {id = rate.Id}, new {@class = "btn btn-danger btn-xs", data_toggle = "fb-modal"})
                                </div>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        }
        else
        {
            <span>Please add a tax rate.</span>
        }

        <h4>Tax Settings</h4>
        {
            Html.RenderPartial("Settings", taxSettings);
        }
    }
    else
    {
        <span>Tax rates are disabled. Enable tax rates by checking Enable Taxes checkbox above.</span>
        <div id="taxes-settings" style="display: none">
            @{ Html.RenderPartial("Settings", taxSettings); }
        </div>
    }

}