@using X.PagedList;
@using X.PagedList.Mvc.Core;
@using X.PagedList.Web.Common;

@model IPagedList<Organization>

<table class="table table-striped table-hover"
       data-filter-control="true"
       data-show-search-clear-button="true">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(x => x.GetEnumerator().Current.ShortName)
            </th>
            <th>
                @Html.DisplayNameFor(x => x.GetEnumerator().Current.Name)
            </th>
            <th>
                @Html.DisplayNameFor(x => x.GetEnumerator().Current.Description)
            </th>
            <th>
                @Html.DisplayNameFor(x => x.GetEnumerator().Current.Type)
            </th>
            <th>
                @Html.DisplayNameFor(x => x.GetEnumerator().Current.ParentId)
            </th>
            <th>
                @Html.DisplayNameFor(x => x.GetEnumerator().Current.FullShortName)
            </th>
            <th>
                <a onclick="showInPopup('@Url.Action("AddOrEdit", "Organization", new {id = 0}, Context.Request.Scheme)','neue Organisation')" class="btn btn-success text-white">
                    <i class="bi bi-plus-square"></i>
                    neu
                </a>
            </th>
        </tr>
    </thead>

    <tbody>
        @{
            if (Model.Count() != 0)
            {
                foreach (var item in Model)
                {
                    <tr>
                        <td hidden>
                            @Html.DisplayFor(modelItem => item.Id)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.ShortName)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Name)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => @item.Description)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => @item.Type)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => @item.Parent.Name)  @(item.Parent == null ? "" : "(")@Html.DisplayFor(modelItem => @item.Parent.ShortName)@(item.Parent == null ? "" : ")")
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => @item.FullShortName)
                        </td>
                        <td>
                            <div class="btn-group" style="flex-direction:row">

                                <a onclick="showInPopup('@Url.Action("AddOrEdit", "Organization",new {id = item.Id}, Context.Request.Scheme)','Organisation bearbeiten')" class="btn btn-success text-white">
                                    <i class="bi bi-pencil-square"></i>
                                </a>

                                <form asp-action="Delete" asp-route-id="@item.Id" onsubmit="return jQueryAjaxDelete(this)" class="d-inline">
                                    <button type="submit" value="bi bi-trash" class="btn btn-danger text-white">
                                        <i class="bi bi-trash"></i>
                                    </button>
                                </form>

                            </div>
                        </td>
                    </tr>
                }
            }
            else
            {
                <tr>
                <td colspan="7" class="text-center">Keine Einträge gefunden</td>
                </tr>
            }
        }
    </tbody>

</table>

