@model IList<MrCMS.Web.Apps.Ecommerce.Entities.Geographic.Country>
@{
    ViewBag.Title = "Countries";
}

<form>
    <fieldset>
        <legend>Countries
            <span class="btn-group  display-inline  pull-right">
                @Html.ActionLink("Sort", "Sort", null, new { @class = "btn btn-default", data_toggle = "fb-modal" })
                @Html.ActionLink("Add", "Add", null, new { @class = "btn btn-primary", data_toggle = "fb-modal" })
            </span>
        </legend>
        @if (Model.Any())
        {
            <table class="table table-condensed table-striped">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>ISO Code</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var country in Model)
                    {
                        <tr>
                            <td>
                                @country.Name
                                @if (country.Regions.Any())
                                {
                                    <table class="table table-condensed table-striped padding-left-10">
                                        <thead>
                                            <tr>
                                                <th>Region</th>
                                                <th>Actions</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @foreach (var region in country.Regions)
                                            {

                                                <tr>
                                                    <td>@region.Name</td>
                                                    <td>
                                                        <div class="btn-group">
                                                            @Html.ActionLink("Edit", "Edit", "Region", new {id = region.Id}, new {@class = "btn btn-xs btn-default", data_toggle = "fb-modal"})
                                                            @Html.ActionLink("Delete", "Delete", "Region", new {id = region.Id}, new {@class = "btn btn-xs btn-danger", data_toggle = "fb-modal"})
                                                        </div>
                                                    </td>
                                                </tr>
                                            }
                                        </tbody>
                                    </table>
                                }
                            </td>
                            <td>@country.ISOTwoLetterCode</td>
                            <td>
                                <div class="btn-group">
                                    @Html.ActionLink("Edit", "Edit", "Country", new {id = country.Id}, new {@class = "btn btn-xs btn-default", data_toggle = "fb-modal"})
                                    @Html.ActionLink("Delete", "Delete", "Country", new {id = country.Id}, new {@class = "btn btn-xs btn-danger", data_toggle = "fb-modal"})
                                    @Html.ActionLink("Add Region", "Add", "Region", new { id = country.Id }, new { @class = "btn btn-xs btn-success", data_toggle = "fb-modal" })
                                </div>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        }
        else
        {
            <p>No countries.</p>
        }
    </fieldset>
</form>
