@page "{id}"
@using MediaManager.database
@using MediaManager.database.Tables
@model MediaManager.Pages.EditShow
@{
	ViewData["Title"] = "Edit Show";
	if (Request.Method == "POST" && Request.Form["action"] == "delete") {
		return;
	}
	var show = new Database.DbConn().Shows.First(p => p.ShowId == int.Parse(RouteData.Values["id"]!.ToString()!));
	if (show.UserId != Model.AuthorizedUser.UserId) {
		Response.Redirect("/");
		return;
	}
}

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

<form method="POST">
	<div class="mb-3">
		<label for="title" class="form-label">Title</label>
		<input type="text" maxlength="100" class="form-control" id="title" name="title" value="@show.Title" autofocus required>
	</div>
	<div class="mb-3">
		<label for="year" class="form-label">Year</label>
		<input type="number" min="1800" max="2100" class="form-control" id="year" name="year" value="@show.Year" required>
	</div>
	<div class="mb-3">
		<label for="rating" class="form-label">Rating</label>
		<input type="number" min="0" max="10" class="form-control" id="rating" name="rating" value="@show.Rating" required>
	</div>
	<div class="mb-3">
		<label for="rewatchability" class="form-label">Rewatchability</label>
		<input type="number" min="0" max="10" class="form-control" id="rewatchability" name="rewatchability" value="@show.Rewatchability" required>
	</div>
	<div class="mb-3">
		<label for="watchcount" class="form-label">Watch count</label>
		<input type="number" min="0" class="form-control" id="watchcount" name="watchcount" value="@show.WatchCount" required>
	</div>
	<div class="mb-3">
		<label for="lastwatch" class="form-label">Last watch</label>
		<input type="date" class="form-control" id="lastwatch" name="lastwatch" value="@show.LastSeen.ToString("yyyy-MM-dd")">
	</div>
	<div class="mb-3">
		<label for="status" class="form-label">Status</label>
		<select class="form-select" id="status" name="status">
			@if (show.WatchStatus == WatchStatus.Unwatched) {
				<option value="1" selected>Unwatched</option>
			}
			else {
				<option value="1">Unwatched</option>
			}
			@if (show.WatchStatus == WatchStatus.FirstWatch) {
				<option value="2" selected>First Watch</option>
			}
			else {
				<option value="2">First Watch</option>
			}
			@if (show.WatchStatus == WatchStatus.Waiting) {
				<option value="3" selected>Waiting</option>
			}
			else {
				<option value="3">Waiting</option>
			}
			@if (show.WatchStatus == WatchStatus.Finished) {
				<option value="4" selected>Finished</option>
			}
			else {
				<option value="4">Finished</option>
			}
			@if (show.WatchStatus == WatchStatus.Rewatch) {
				<option value="5" selected>Rewatch</option>
			}
			else {
				<option value="5">Rewatch</option>
			}
		</select>
	</div>
	<div class="mb-3">
		<label for="seeneps" class="form-label">Episodes seen</label>
		<input type="number" min="0" class="form-control" id="seeneps" name="seeneps" value="@show.SeenEpisodes" required>
	</div>
	<div class="mb-3">
		<label for="totaleps" class="form-label">Episodes total</label>
		<input type="number" min="1" class="form-control" id="totaleps" name="totaleps" value="@show.TotalEpisodes" required>
	</div>
	<div class="mb-3">
		<label for="comment" class="form-label">Comment</label>
		<input type="text" maxlength="100" class="form-control" id="comment" name="comment" value="@show.Comment">
	</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>
