@model List<bitforum.Models.Views.UserViewModel>
@{
    ViewData["Title"] = "권한 관리";
}

<div id="directorUser" class="container">
    <h3>@ViewData["Title"]</h3>
    <hr />

    <partial name="_StatusMessage" />
    <small>관리자 가입 회원들입니다. 메뉴 접근 권한을 관리할 수 있습니다.</small>

    <div class="row g-2">
        <div class="col align-self-end">
            Total : @Model.Count.ToString("N0")
        </div>
        <div class="col text-end">
            <a class="btn btn-sm btn-primary" asp-controller="Role" asp-action="Index">역할 관리</a>
        </div>
    </div>

    <div class="table-responsive">
        <table class="table table-striped table-bordered table-hover mt-3">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Mail</th>
                    <th>Name</th>
                    <th>Role</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                @if (Model == null || !Model.Any())
                {
                    <tr>
                        <td colspan="6">No Data.</td>
                    </tr>
                }
                else
                {
                    @foreach (var user in Model)
                    {
                        <tr>
                            <td>@user.ID</td>
                            <td>@user.Email</td>
                            <td>@user.Name</td>
                            <td>
                                @if (user.Roles.Any())
                                {
                                    @string.Join(", ", user.Roles)
                                }
                                else
                                {
                                    <span>역할 없음</span>
                                }
                            </td>
                            <td>
                                <a class="btn btn-sm btn-info text-white" asp-controller="User" asp-action="Edit" asp-route-userId="@user.ID">수정</a>
                                <a class="btn btn-sm btn-danger" asp-controller="Attach" asp-action="Index" asp-route-userId="@user.ID">권한</a>
                            </td>
                        </tr>
                    }
                }
            </tbody>
        </table>
    </div>
</div>
