@page "{id:int}"
@using AfRApay.Web.Backend
@model EditUserModel
@{
	ViewData["Title"] = "Edit User";
	if (Request.Method == "POST" && Request.Form["action"] == "delete") {
		return;
	}
	var db = new Database.DbConn();
	var user = db.Users.First(p => p.Id == int.Parse(RouteData.Values["id"]!.ToString()!));
	var cards = db.Cards.Where(p => p.UserId == user.Id);
}

<div class="text-center">
	<h1 class="display-5">
		Edit User
	</h1>
</div>

<form method="POST">
	<h3>Account</h3>
	<div class="mb-3">
		<label for="nickname" class="form-label">Nickname</label>
		<input type="text" maxlength="10" class="form-control" id="nickname" name="nickname" value="@user.Nickname" required>
	</div>
	<button type="submit" class="btn btn-primary" name="action" value="save">Save</button>
	<button type="submit" class="btn btn-danger" name="action" value="delete">Delete</button>
</form>
<br/>
<h3>Cards</h3>
@if (!cards.Any()) {
	<div>
		No linked cards found.
	</div>
}
else {
	<div class="row">
		@foreach (var card in cards) {
			<div class="fake-card-wrapper">
				<div class="fake-card">
					<div class="face-card front">
						<div class="chip">
							<div>
								<div>
									<div>
									</div>
								</div>
							</div>
						</div>
						<h2 class="card-number">@card.CardId</h2>
						<h3 class="card-holder">@user.Nickname</h3>
						<span class="validity">
							<span class="small">VALID<br>THRU</span>
							<span>01/2038</span>
						</span>

						<div class="fake-card-logo-top">
							<img src="/img/afra.png" class="fake-card-logo-inner" alt="">
						</div>
						<div class="fake-card-logo-bottom">
							<img src="/img/matecard.png" class="fake-card-logo-inner" alt="">
						</div>

					</div>
				</div>
			</div>
		}
	</div>
}
