@page
@model QuantEngine.Web.Pages.Admin.Users.IndexModel
@{
    ViewData["Title"] = "사용자 관리";
}

<div class="page-header d-print-none">
    <div class="row align-items-center">
        <div class="col">
            <h2 class="page-title">사용자 관리</h2>
        </div>
        <div class="col-auto">
            <a href="/Admin/Users/Create" class="btn btn-primary">새 사용자 추가</a>
        </div>
    </div>
</div>

<div class="page-body">
    <div class="row row-deck row-cards">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">사용자 목록</h3>
                </div>
                <div class="table-responsive">
                    <table class="table card-table table-vcenter">
                        <thead>
                            <tr>
                                <th>사용자명</th>
                                <th>역할</th>
                                <th>상태</th>
                                <th>생성일</th>
                                <th>작업</th>
                            </tr>
                        </thead>
                        <tbody>
                            @if (Model.Users?.Any() == true)
                            {
                                @foreach (var user in Model.Users)
                                {
                                    <tr>
                                        <td>@user.Username</td>
                                        <td>@(user.Role ?? "Admin")</td>
                                        <td>
                                            @if (string.Equals(user.IsActive, "true", StringComparison.OrdinalIgnoreCase))
                                            {
                                                <span class="badge bg-success">활성</span>
                                            }
                                            else
                                            {
                                                <span class="badge bg-secondary">비활성</span>
                                            }
                                        </td>
                                        <td>@(user.CreatedAt ?? "-")</td>
                                        <td>
                                            <a href="/Admin/Users/@user.Username/Edit" class="btn btn-sm btn-link">수정</a>
                                            <form method="post" style="display:inline;" onsubmit="return confirm('이 사용자를 비활성화하시겠습니까?');">
                                                @Html.AntiForgeryToken()
                                                <input type="hidden" name="handler" value="delete" />
                                                <input type="hidden" name="username" value="@user.Username" />
                                                <button type="submit" class="btn btn-sm btn-link text-danger">비활성화</button>
                                            </form>
                                        </td>
                                    </tr>
                                }
                            }
                            else
                            {
                                <tr>
                                    <td colspan="5" class="text-center text-muted">사용자가 없습니다</td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
