<!DOCTYPE html>
<html 
xmlns:th="http:/www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
lang="en">

<head  th:replace="fragments/header::headerLink">
</head>

<body>
<div>
	<div class="container" th:fragment="table">
	<!-- Begin Page Content -->
        <div class="container-fluid" >
		<div>
          <!-- Page Heading -->

          	</div>
          <!-- DataTales Example -->
          <div class="card shadow mb-4">

            <div class="card-body">
                <button type="button"  class="btn btn-success" data-toggle="modal" data-target="#myModal1" style="margin-bottom: 10px;">
                    <i class="far fa-edit mr-2"></i>
                    Add product
                </button>
                <!-- Modal -->
                <div class="modal fade" id="myModal1" role="dialog">
                    <div class="modal-dialog">

                        <!-- Modal content-->
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4 class="modal-title">Product</h4>
                                <button type="button" class="close" data-dismiss="modal">&times;</button>
                            </div>
                            <div class="modal-body">
                                <form class="user" id="frmFoodAdd" th:action="@{/food/add}" th:object="${food}" method="post">
                                    <div class="form-group">
                                        <input type="text" class="form-control form-control-user" id="product" name="name" placeholder="Product...">
                                    </div>
                                    <div class="form-group">
                                        <input type="text" class="form-control form-control-user" id="price" name="Price" placeholder="Price">
                                    </div>
                                    <button class="btn btn-primary" type="submit" onclick="check()">Save</button>
                                </form>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Modal -->
              <div class="table-responsive">
                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                  <thead>
                    <tr>
                      <th>ID</th>
                      <th>Name</th>
                      <th>Price</th>
                      <th>Action</th>
                    </tr>
                  </thead>
                  <tfoot>
                    <tr>
                      <th>ID</th>
                      <th>Name</th>
                      <th>Price</th>
                      <th>Action</th>
                    </tr>
                  </tfoot>
                  <tbody>
                      <tr th:each="food:${foods}">
                      	<td th:text="${food.id}"></td>
                      	<td th:text="${food.name}"></td>
                      	<td th:text="${food.price}"></td>
                            <!-- Modal -->
                              <div class="modal fade" th:id="${'my'+food.id}" role="dialog">
                                <div class="modal-dialog">

                                  <!-- Modal content-->
                                  <div class="modal-content">
                                    <div class="modal-header">
                                      <h4 class="modal-title">Product</h4>
                                      <button type="button" class="close" data-dismiss="modal">&times;</button>
                                    </div>
                                    <div class="modal-body">
                                        <form class="user" id="frmFoodEdit" th:action="@{/food/update}" th:object="${food}" th:method="put">
                                                <div class="form-group" th:id="${'food'+food.id}">
                                                  <input type="text" class="form-control form-control-user" th:value="${food.id}"  id="foodid" name="id"  placeholder="Price">
                                                </div>
                                                <div class="form-group">
                                                  <input type="text" class="form-control form-control-user" th:value="${food.name}"  id="name" name="name"  placeholder="Price">
                                                </div>
                                                <div class="form-group">
                                                  <input type="text" class="form-control form-control-user" th:value="${food.price}"  id="price" name="Price" placeholder="Price">
                                                </div>
                                                <button class="btn btn-primary" type="submit">Update</button>
                                         </form>
                                        <!-- Modal -->
                                        <div class="modal fade" id="myModal" role="dialog">
                                            <div class="modal-dialog">

                                                <!-- Modal content-->
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <h4 class="modal-title">Product</h4>
                                                        <button type="button" class="close" data-dismiss="modal">&times;</button>

                                                    </div>
                                                    <div class="modal-body">
                                                        <form class="user" id="formAddProduct" th:action="@{/burger/addproduct}" th:object="${food}" method="post">
                                                            <div class="form-group">
                                                                <input type="text" class="form-control form-control-user" id="username" name="name" placeholder="Product...">
                                                            </div>
                                                            <div class="form-group">
                                                                <input type="text" class="form-control form-control-user" id="password" name="Price" placeholder="Price">
                                                            </div>
                                                            <button class="btn btn-primary" type="submit" onclick="check()">Save</button>
                                                        </form>
                                                    </div>
                                                    <div class="modal-footer">

                                                        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="modal-footer">

                                      <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                                    </div>
                                  </div>

                                </div>
                              </div>
                              <!-- Modal -->
                      	<td>
                      		<button type="button"  class="btn btn-primary" data-toggle="modal"  th:id="${'btn'+ food.id}" th:onclick="'popup('+${food.id}+')'">
                      			<i class="far fa-edit mr-2"></i>
                      				Update
                      		</button>
                      		<button type="button" class="btn btn-danger" th:id="${'btndelete'+ food.id}" th:onclick="'deleteFood('+${food.id}+')'">
                      			<i class="fas fa-trash-alt mr-2"></i>
                      				Delete
                      		</button>
                      	</td>
                      </tr>
                  </tbody>
                </table>
              </div>
            </div>
          </div>

        </div>
        <!-- /.container-fluid -->
      </div>
      <!-- End of Main Content -->
<script>
	function popup(id){
		document.getElementById("food"+id).style.display="none";
		var btn=document.getElementById("btn"+id);
		btn.dataset.target="#my"+id;
		
	}
	function deleteFood(id){
        window.location.replace("/food/delete/"+id+"");
    }
</script>
  
  <!-- Footer -->
  <div th:replace="fragments/footer::footer"></div>

  <!-- Footer -->
</div>
</body>

</html>
