<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>EazyEatz</title>
  <link rel="icon" href="/imgs/ezblack.png" type="image/png">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css">
  <script src="/scripts/read.js"></script>
</head>

<body class="d-flex flex-column min-vh-100">
  <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container-fluid">
      <a class="navbar-brand" href="/"><img class="navbar-brand-image img-fluid" src="/imgs/ezwhite.png" style="height: 40px;;">
        EazyEatz</a>
      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
        aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav ms-auto">
          <li class="nav-item">
            <button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-target="#editRecipeModal">
              Edit Recipe
            </button>
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
              Menu
            </a>
            <ul class="dropdown-menu dropdown-menu-dark" aria-labelledby="navbarDropdown">
              <li><a class="dropdown-item" href="/">Home</a></li>
              <li><a class="dropdown-item" href="https://crimsonhog.github.io/Sprint-Biggie/" target="_blank">About</a></li>
            </ul>
          </li>
        </ul>
      </div>
    </div>
  </nav>

  <div class="container mt-4 mb-5">
    <div class="row">
      <div class="col-md-6 offset-md-3">
        <h1 class="text-center mb-4"><%= recipe.recipeName %></h1>
        <p class="lead text-center"><%= recipe.author %></p>
        <p class="text-center"><i class="bi bi-clock"></i> <%= recipe.time %></p>
        <div class="mt-4">
          <h5>Ingredients:</h5>
          <ul class="list-group">
            <!-- Print each ingredient in the array -->
            <% recipe.ingredients.forEach(function(ingredient) { %>
              <li class="list-group-item d-flex align-items-center">
                <%= ingredient %>
                <input type="checkbox" class="form-check-input ms-auto">
              </li>
            <% }) %>
          </ul>
        </div>
        <div class="mt-4">
          <h5>Steps:</h5>
          <ul class="list-group">
            <!-- Print each step in the array -->
            <% recipe.steps.forEach(function(step) { %>
              <li class="list-group-item d-flex align-items-center">
                <%= step %>
                <input type="checkbox" class="form-check-input ms-auto">
              </li>
            <% }) %>
          </ul>
        </div>
      </div>
    </div>
  </div>

  <!-- Edit Recipe Modal -->
  <div class="modal fade" id="editRecipeModal" tabindex="-1" aria-labelledby="editRecipeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="editRecipeModalLabel">New Recipe</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          <form action="/update" method="POST">
            <input type="hidden" name="recipe" value="<%= recipe._id %>">
            <div class="mb-3">
              <label for="recipeName" class="form-label">Recipe Name</label>
              <input type="text" class="form-control" id="recipeName" name="recipeName" value="<%= recipe.recipeName %>" required>
            </div>
            <div class="mb-3">
              <label for="authorName" class="form-label">Author Name</label>
              <input type="text" class="form-control" id="authorName" name="authorName" value="<%= recipe.author %>" required>
            </div>
            <div class="mb-3">
              <label for="time" class="form-label">Time</label>
              <input type="text" class="form-control" id="time" name="time" value="<%= recipe.time %>" required>
            </div>
            <div class="mb-3">
              <label for="ingredients" class="form-label">Ingredients</label>
              <div id="ingredientsContainer">
                <% recipe.ingredients.forEach(function(ingredient) { %>
                  <input type="text" class="form-control mb-2" name="ingredients[]" value="<%= ingredient %>">
                <% }) %>
              </div>
              <button type="button" class="btn btn-secondary mt-2" id="addIngredientBtn">Add Ingredient</button>
            </div>
            <div class="mb-3">
              <label for="steps" class="form-label">Steps</label>
              <div id="stepsContainer">
                <% recipe.steps.forEach(function(step) { %>
                  <textarea class="form-control form-control-sm mb-2" name="steps[]" rows="3" ><%= step %></textarea>
                <% }) %>
              </div>
              <button type="button" class="btn btn-secondary mt-2" id="addStepBtn">Add Step</button>
            </div>
            <button type="submit" class="btn btn-primary">Save Changes</button>
            <button class="btn btn-danger" id="deleteBtn" data-recipe-id="<%= recipe._id %>">Delete</button>
          </form>
        </div>
      </div>
    </div>
  </div>

  <footer class="bg-light text-center py-3 mt-auto">
    <div class="container">
      <p class="m-0">EazyEatz &copy; 2024</p>
    </div>
  </footer>

  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js"></script>
</body>

</html>