<%@ page import="java.util.List" %>
<%@ page import="com.nisum.model.CartItem" %>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false"%>

<%
    List<CartItem> cartItems = (List<CartItem>) request.getAttribute("cartItems");
    double cartTotal = (double) request.getAttribute("cartTotal");
%>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>FashionHub</title>
  <link rel="icon" href="./images/NISUM.jpeg" type="image/x-icon">
   <link rel="stylesheet" href="./CSS/order.css">
</head>
<body>

  <div class="order-container">
    <h2>Thank You for Placing Your Order!</h2>
    <p class="subtitle">Your order has been successfully placed. You will receive a confirmation email shortly.</p>

    <div class="section">
      <h4>Order Details</h4>
      <% for (CartItem item : cartItems) { %>
        <div class="item">
          <p><strong><%= item.getProductName() %></strong></p>
          <p>Quantity: <%= item.getQuantity() %></p>
          <p>Price per unit: Rs. <%= item.getFinalPrice() / item.getQuantity() %></p>
          <p>Subtotal: Rs. <%= item.getFinalPrice() %></p>
        </div>
      <% } %>
    </div>

    <div class="section">
      <h4>Total Amount</h4>
      <div class="item">
        <p><strong>Total: Rs. <%= cartTotal %></strong></p>
      </div>
    </div>

    <div class="section">
      <h4>Delivery Instructions</h4>
      <div class="note">
        Please ensure someone is available at the address to receive the delivery. You can track your shipment from your account.
      </div>
    </div>

    <div class="section">
      <h4>Rewards Earned</h4>
      <div class="rewards">
        <span class="emoji">🎁</span>You’ve earned <strong><%= (int)(cartTotal / 10) %></strong> reward points on this order! Redeem them on your next purchase.
      </div>
    </div>

    <div class="section">
      <h4>Email Confirmation</h4>
      <div class="note">
        A confirmation email has been sent to <strong>ravi.kumar@example.com</strong> with all the order details.
      </div>
    </div>

    <div class="buttons">
        <button onclick="alert('Orders page is yet to be added.')">View My Orders</button>
      <button onclick="window.location.href='product'">Continue Shopping</button>
    </div>
  </div>
<button onclick="viewOrders()">View My Orders</button>

<script>
  function viewOrders() {
    alert('Orders page is yet to be added.');
    // setTimeout(() => {
    //   window.location.href = 'orders.html';
    // }, 2000);
  }
</script>

</body>
</html>
