@{
	ViewData["Title"] = "Создание заказа";
	Layout = "~/Views/Shared/_LayoutStorekeeper.cshtml";
}

<div class="text-center">
	<h2 class="display-4">Создание заказа</h2>
</div>

<form method="post" class="d-flex flex-column align-items-center">
	<div class="col-sm-3">
		<label class="form-label">Товар</label>
		<select id="good" name="good" class="form-control" asp-items="@(new SelectList(@ViewBag.Goods, "Id", "GoodName"))"></select>
	</div>	
	<div class="col-sm-3">
		<label class="form-label">Количество</label>
		<input type="number" class="form-control" name="count" id="count" min="1" value="1" required>
	</div>
	<div class="col-sm-3">
		<label class="form-label">Сумма</label>
		<input type="number" step="0.01" class="form-control" name="sum" id="sum" value="0" readonly required>
	</div>
	<div class="col-sm-2 d-flex justify-content-evenly align-items-baseline">
		<button type="submit" class="btn btn-primary mt-3 px-4">Сохранить</button>
	</div>
</form>

@section Scripts
	{
	<script>
		$('#good').on('change', function () {
			check();
		});
		$('#count').on('input', function () {
			check();
		});

		function check() {
			var count = $('#count').val();
			var good = $('#good').val();
			if (count && good) {
				$.ajax({
					method: "POST",
					url: "/Storekeeper/Calc",
					data: { count: count, good: good  },
					success: function (result) {
						$("#sum").val(result);
					}
				});
			};
		}
		check()
	</script>
}
