@model IEnumerable<GreenTree.Strohrmann.ERP.Web.Models.Business.CustomerModel>

@{
    ViewData["Title"] = "Kundenliste";
}

<!-- Custom JavaScript -->
<script>

    $(document).ready(function () {
        $("#customersTable").DataTable({
            autoWidth: false,
            paging: true,
            pageLength: 50,
            "bInfo": false,
            columns: [
                {
                    data: "@Html.DisplayNameFor(model => model.Id)",
                    orderable: true
                },
                {
                    data: "@Html.DisplayNameFor(model => model.Firstname)",
                    orderable: true
                },
                {
                    data: "@Html.DisplayNameFor(model => model.Lastname)",
                    orderable: true
                },
                {
                    data: "@Html.DisplayNameFor(model => model.CompanyName)",
                    orderable: true
                },
                {
                    data: "@Html.DisplayNameFor(model => model.IsBusiness)",
                    orderable: true
                },
                {
                    data: "@Html.DisplayNameFor(model => model.Address)",
                    orderable: true
                },
                {
                    data: "@Html.DisplayNameFor(model => model.Town)",
                    orderable: true
                },
                {
                    data: "@Html.DisplayNameFor(model => model.ZipCode)",
                    orderable: true
                },
                {
                    data: "@Html.DisplayNameFor(model => model.Country)",
                    orderable: true
                },
                {
                    data: "Aktionen",
                    orderable: false
				}
            ],
            language: {
                zeroRecords: "Keine Einträge gefunden",
                search: "Suchen:",
                info: "Zeige _START_ bis _END_ von _TOTAL_ Einträgen",
                lengthMenu: "Zeige _MENU_ Einträge",
                paginate: {
                    first: "Erste",
                    last: "Letzte",
                    next: "Nächste",
                    previous: "Vorige"
				}
			}
        });
    });

    function showDeleteModal(id) {
        if (!id) return;
        $('#deleteModal').modal("show");
        $("[name='id'").val(id);
    }

</script>

<h1>Kundenliste</h1>

<p>
    <a asp-action="Create">Neuen Kunden erstellen</a>
</p>

<table id="customersTable" class="table responsive">
    <thead>
        <tr>
            <th data-priority="1">
                @Html.DisplayNameFor(model => model.Id)
            </th>
            <th data-priority="2">
                @Html.DisplayNameFor(model => model.Firstname)
            </th>
            <th data-priority="3">
                @Html.DisplayNameFor(model => model.Lastname)
            </th>
            <th data-priority="4">
                @Html.DisplayNameFor(model => model.CompanyName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.IsBusiness)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Address)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Town)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.ZipCode)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Country)
            </th>
            <th data-priority="1">
                Aktionen
            </th>
        </tr>
    </thead>
    <tbody>
@foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Id)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Firstname)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Lastname)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.CompanyName)
            </td>
            <td>
                @Html.YesNoBadgeFor(modelItem => item.IsBusiness)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Address)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Town)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.ZipCode)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Country)
            </td>
            <td>
                @Html.ActionLink("Bearbeiten", "Edit", new { id = item.Id }) |
                @Html.ActionLink("Anzeigen", "Details", new { id = item.Id }) |
                <a href="#" onclick="showDeleteModal(@item.Id)">Löschen</a>
            </td>
        </tr>
}
    </tbody>
</table>

<div id="deleteModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Kunde löschen</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form asp-action="Delete">
                <div class="modal-body">
                    <p>Sind Sie sicher, dass Sie diesen Kunden löschen möchten?</p>
                    <input name="id" type="hidden" />
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">Ja</button>
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Nein</button>
                </div>
            </form>
        </div>
    </div>
</div>