@model IEnumerable<SuperShop.Web.Data.Entities.Country>
@{
    ViewData["Title"] = "Index";
}

<h2>Countries</h2>

<p>
    <a asp-action="Create" class="btn btn-primary">Create New</a>
</p>
<table class="table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Name)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.NumberCities)
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.Name)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.NumberCities)
                </td>
                <td id="@item.Id">
                    <a asp-action="Edit" asp-route-id="@item.Id" class="btn btn-warning">Edit</a>
                    <a asp-action="Details" asp-route-id="@item.Id" class="btn btn-info">Details</a>
                    <a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger" id="btnDelete">Delete</a>
                </td>
            </tr>
        }
    </tbody>
</table>

<div id="deleteDialog" class="modal fade">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><i class="fa fa-window-close"></i></button>
                <h4 class="modal-title">Delete</h4>
            </div>
            <div class="modal-body">
                <p>Do you want to delete the country?</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" id="btnYesDelete">Delete</button>
                <button type="button" class="btn btn-success" id="btnNoDelete">No</button>
            </div>
        </div>
    </div>
</div>

@section Scripts {
    @{
        await Html.RenderPartialAsync("_ValidationScriptsPartial");
    }

    <script type="text/javascript">
        $(document).ready(function () {
            var id = 0;
            $('a[id*=btnDelete]').click(function () {
                debugger;
                id = $(this).parent()[0].id;
                $("#deleteDialog").modal('show');
                return false;
            });
            $("#btnNoDelete").click(function () {
                $("#deleteDialog").modal('hide');
                return false;
            });
            $("#btnYesDelete").click(function () {
                window.location.href = '/Countries/Delete/' + id;
            });
        });
    </script>
}

