<!doctype html>
<html lang="en">

<head>
  <title>EatQ</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <%- include('../../template/header') %>
</head>

<body class="font-kanit-sm">
  <%- include('../../template/navbar') %>
    <div class="container px-3">
      <div class="d-flex justify-content-between">
        <a href="/table" class="text-dark text-decoration-none">
          <div class="d-flex align-items-center">
            <i class="fa-solid fa-arrow-left me-2"></i>
            <p class="mb-0">ย้อนกลับ</p>
          </div>
        </a>
        <form id="deleteForm" method="POST" action="/table/delete">
          <input type="hidden" name="id" value="<%= tableData.id %>">
          <button type="button" class="btn btn-danger btn-sm" onclick="confirmDelete(event)">ลบโต๊ะ</button>
        </form>
      </div>
      <div class="container mx-2 my-3">
        <div class="d-flex">
          <h5>จัดการโต๊ะ</h5>
        </div>

        <form method="POST" action="/table/update">
          <input type="hidden" name="id" value="<%= tableData.id %>">
          <div class="form-group">
            <label for="table_number">หมายเลขโต๊ะ</label>
            <input type="number" class="form-control" name="table_number" id="table_number" placeholder="หมายเลขของโต๊ะ"
              value="<%= tableData.table_number %>">
          </div>
          <div class="form-group">
            <label for="table_type">ประเภทโต๊ะ</label>
            <select id="table_type" name="table_type" class="form-control">
              <% tableTypeData.forEach(element=> { %>
                <option value="<%= element.id %>" <%=tableData.table_type==element.id ? 'selected' : '' %>><%= element.description %> | <%= element.capacity_min %> - <%= element.capacity_max %> คน</option>
                <% }) %>
            </select>
          </div>
          <div class="form-group">
            <label for="table_status">สถานะโต๊ะ</label>
            <select id="table_status" name="table_status" class="form-control">
              <% tableStatusData.forEach(element=> { %>
                <option value="<%= element.id %>" <%=tableData.table_status==element.id ? 'selected' : '' %>><%= element.name %></option>
                <% }) %>
            </select>
          </div>
          <button type="submit" class="my-2 btn btn-success">บันทึก</button>
        </form>
      </div>
    </div>
    <script>
      function confirmDelete(event) {
        event.preventDefault();
        if (confirm("คุณแน่ใจหรือไม่ว่าต้องการลบโต๊ะนี้?")) {
          document.getElementById('deleteForm').submit();
        }
      }
    </script>
    <%- include('../../template/bottom_nav') %>
      <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js"
        integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r"
        crossorigin="anonymous"></script>
      <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js"
        integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqruptLy"
        crossorigin="anonymous"></script>
</body>

</html>