﻿@model IEnumerable<TradeUnionCommittee.BLL.DTO.DirectoryDTO>
@{

}

<section class="add-user container-fluid">
    <div class="row justify-content-center">
        <div class="col-md-12 add-user_block">
            <div class="row">
                <a asp-controller="Home" asp-action="Directory" class="back-link">Повернутися</a>
                <hr />
                <div class="form-group">
                    <a asp-action="Create" class="btn btn-success">Додати хобі</a>
                </div>
            </div>
            <div class="row main-block">
                <table class="table">
                    <thead>
                        <tr>
                            <th>
                                Хобі
                            </th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        @if (TempData["ErrorsList"] == null)
                        {
                            foreach (var item in Model)
                            {
                                <tr>
                                    <td>
                                        @item.Name
                                    </td>

                                    <td class="text-right">
                                        <div class="btn-group">
                                            <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown"></button>
                                            <div class="dropdown-menu">
                                                <a class="dropdown-item" asp-action="Update" asp-route-id="@item.HashId">Редагувати назву</a>

                                                @if (User.IsInRole("Admin"))
                                                {
                                                    <a class="dropdown-item delete"
                                                       href=""
                                                       data-controller="Hobby"
                                                       data-action="Delete"
                                                       data-id="@item.HashId"
                                                       data-body-message="Ви впевнені, що хочете видалити хобі?">Видалити</a>
                                                }
                                            </div>
                                        </div>
                                    </td>

                                </tr>
                            }
                        }
                        else
                        {
                            await Html.RenderPartialAsync("_Errors", TempData["ErrorsList"]);
                        }
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</section>


@if (User.IsInRole("Admin"))
{
    @section Scripts
    {
        <environment include="Development">
            <script src="~/js/delete.js"></script>
        </environment>

        <environment exclude="Development">
            <script src="~/js/delete.min.js" asp-append-version="true"></script>
        </environment>
    }
}