@using HardwareShopContracts.ViewModels
@model List<BuildViewModel>
@{
    ViewData["Title"] = "Builds";
	Layout = "~/Views/Shared/_LayoutWorker.cshtml";
}

<div class="d-flex justify-content-evenly">
		@{
		if (Model == null)
		{
			<h3 class="display-4">Введите пароль</h3>
			return;
		}
	<div class=" col-sm-8">
		<div class="text-center">
			<h2 class="display-4">Сборки</h2>
		</div>
		<div class="text-center" name="id">
			<table class="table">
				<thead>
					<tr>
						<th>
							Номер
						</th>
						<th>
							Цена
						</th>
						<th>
							Название
						</th>
						<th>
							Действия
						</th>
					</tr>
				</thead>
				<tbody>
						@foreach (var item in Model)
						{
							<tr>
								<td>
									@Html.DisplayFor(modelItem => item.Id)
								</td>
								<td>
									@Html.DisplayFor(modelItem => item.Price)
								</td>
								<td>
									@Html.DisplayFor(modelItem => item.BuildName)
								</td>
								<td>
									<div>
										<button onclick="getBuild(@item.Id)" type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#updateModal">Изменить</button>
										<button onclick="getBuild(@item.Id)" type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#deleteModal">Удалить</button>
									</div>
								</td>
							</tr>
						}
					</tbody>
				</table>
				
		</div>
	</div>
	<div class="text-center d-flex flex-column mt-5">
		<button type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#createModal">Добавить</button>
		<button type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#exampleModal">Изменить</button>
		<button type="button" class="btn btn-primary btn-lg mb-5">Удалить</button>
		<button type="button" class="btn btn-primary btn-lg mb-5">Обновить</button>
		<button type="submit" class="btn btn-primary btn-lg mb-5">Привязать сборку</button>
	</div>
	<div class="modal fade" id="createModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
					<form method="post" asp-controller="home" asp-action="CreateBuild">
					<div class="modal-header">
						<h5 class="modal-title" id="exampleModalLabel">Создание сборку</h5>
						<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
					</div>
					<div class="modal-body">
						<div class="form-group">
							<label>Name</label>
							<input type="text" class="form-control" required="required" name="name" />
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
						<input type="submit" class="btn btn-primary" value="Сохранить">
					</div>
				</form>
			</div>
		</div>
	</div>
	<div class="modal fade" id="updateModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<form method="post" asp-controller="home" asp-action="UpdateBuild">
					<div class="modal-header">
						<h5 class="modal-title" id="exampleModalLabel">Обновление сборки</h5>
						<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
					</div>
					<div class="modal-body">
						<div class="form-group">
							<label>Name</label>
							<input type="text" class="form-control" required="required" id="name" name="name" />
						</div>
					</div>
					<input type="hidden" id="buildId" name="buildId" />
					<div class="modal-footer">
						<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
						<input type="submit" class="btn btn-primary" value="Сохранить">
					</div>
				</form>
			</div>
		</div>
	</div>
	<div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<form method="post" asp-controller="home" asp-action="DeleteBuild">
					<div class="modal-header">
						<h5 class="modal-title" id="exampleModalLabel">Удаление сборки</h5>
						<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
					</div>
					<div class="modal-body">
						<div class="form-group">
							<h1>Вы уверенны что хотите удалить сборку?</h1>
						</div>
					</div>
						<input type="hidden" id="deleteBuildId" name="deleteBuildId" />
					<div class="modal-footer">
						<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
						<input type="submit" class="btn btn-primary" value="Удалить">
					</div>
				</form>
			</div>
		</div>
	</div>
	}
</div>
@section Scripts
{
	<script>
		function getBuild(buildId) {
			$.ajax({
				method: "GET",
				url: "/Home/GetBuild",
				data: { buildId: buildId },
				success: function (result) {
					if (result != null)
					{
						$('#name').val(result.buildName);
						$('#buildId').val(result.id);
						$('#deleteBuildId').val(result.id);
					}
					console.log(result);
				}
			});
		}
	</script>
}