<!DOCTYPE html>
<html lang="ja">

<head>
	<meta charset="UTF-8">
	<title<%=title %>
		</title>
		<link rel="stylesheet" href="/styles.css">
		<script src="/script.js"></script>
</head>

<body>
	<h1>
		<%=title %>
	</h1>
	<div class="container">
		<div class="card">
			<p class="title" id="message">
				<%=message %>
			</p>
			<label for="id">ID</label>
			<input type="number" id="id" name="id" onchange="doChange(this.value)">
			<pre id="row"></pre>
			<button onclick="doAction();">削除</button>
		</div>
		<script>
			const message = document.querySelector('#message');
			const id = document.querySelector('#id');
			const row = document.querySelector('#row');

			function doChange(id) {
				getPersonalDataById(id).then(res => {
					const data = `NAME: ${res.row.name}\nEMAIL: ${res.row.email}`;
					message.textContent = `id=${id} のレコードを削除します。`;
					row.textContent = data;
				})
			}

			function doAction() {
				const data = {
					id: id.value,
				};
				deletePersonalData(data).then(res => {
					console.log(res.result);
					message.textContent = `${res.result.changes}個のレコードを削除しました。`;
				})
			}
		</script>
</body>

</html>