<%- include('partials/header') %>

<div class="checkout">
    <h2>Checkout</h2>

    <% if (!user) { %>
        <p>You need to <a href="/login">log in</a> to proceed with checkout.</p>
    <% } else { %>
        <div class="order-summary">
            <h3>Order Summary</h3>
            <% cartItems.forEach(item => { %>
                <div class="order-item">
                    <span><%= item.name %> x <%= item.quantity %></span>
                    <span>฿<%= (item.price * item.quantity).toLocaleString() %></span>
                </div>
            <% }); %>
            <div class="total">
                <strong>Total:</strong>
                <strong>฿<%= total.toLocaleString() %></strong>
            </div>
        </div>
        
        <form action="/order/create" method="POST" class="checkout-form">
            <div class="form-group">
                <label for="address">Shipping Address:</label>
                <textarea name="address" required></textarea>
            </div>
            <button type="submit" style="margin: 0; padding: 0.5rem 1rem;" > Place Order</button>
        </form>
    <% } %>
</div>

<%- include('partials/footer') %>