@page "{username}/edit"
@model QuantEngine.Web.Pages.Admin.Users.EditModel
@{
    ViewData["Title"] = "사용자 수정 - " + Model.CurrentUser?.Username;
}

<div class="page-header d-print-none">
    <div class="row align-items-center">
        <div class="col">
            <h2 class="page-title">사용자 수정: @Model.CurrentUser?.Username</h2>
        </div>
        <div class="col-auto">
            <a href="/Admin/Users" class="btn btn-secondary">목록으로</a>
        </div>
    </div>
</div>

<div class="page-body">
    @if (Model.CurrentUser == null)
    {
        <div class="alert alert-danger">사용자를 찾을 수 없습니다.</div>
        return;
    }

    <div class="row">
        <div class="col-md-8">
            <div class="card">
                <div class="card-body">
                    @if (!ViewData.ModelState.IsValid)
                    {
                        <div class="alert alert-danger alert-dismissible fade show">
                            <h4 class="alert-title">검증 오류</h4>
                            @foreach (var error in ViewData.ModelState.Values.SelectMany(v => v.Errors))
                            {
                                <div>@error.ErrorMessage</div>
                            }
                            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                        </div>
                    }

                    <form method="post">
                        @Html.AntiForgeryToken()

                        <div class="mb-3">
                            <label class="form-label">사용자명</label>
                            <input type="text" class="form-control" value="@Model.CurrentUser.Username" disabled />
                            <small class="text-muted">변경할 수 없습니다</small>
                        </div>

                        <div class="mb-3">
                            <label for="role" class="form-label">역할</label>
                            <select class="form-select" id="role" asp-for="Input.Role">
                                <option value="Admin" selected="@(Model.CurrentUser.Role == "Admin")">관리자</option>
                                <option value="User" selected="@(Model.CurrentUser.Role == "User")">사용자</option>
                                <option value="Viewer" selected="@(Model.CurrentUser.Role == "Viewer")">조회전용</option>
                            </select>
                        </div>

                        <div class="mb-3">
                            <div class="form-check">
                                <input type="checkbox" class="form-check-input" id="isActive" asp-for="Input.IsActive" />
                                <label class="form-check-label" for="isActive">활성화</label>
                            </div>
                        </div>

                        <div class="alert alert-info">
                            <strong>주의:</strong> 비밀번호는 사용자 본인이 직접 변경해야 합니다.
                        </div>

                        <div class="form-footer">
                            <button type="submit" class="btn btn-primary">저장</button>
                            <a href="/Admin/Users" class="btn btn-secondary">취소</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
