<!DOCTYPE html>
<html lang="th">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>แก้ไขสินค้า - ระบบจัดการคลังสินค้า</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <%- include('partials/navbar') %>

    <div class="container mt-4">
        <div class="row justify-content-center">
            <div class="col-md-6">
                <div class="card shadow">
                    <div class="card-header bg-warning">
                        <h5 class="mb-0">แก้ไขสินค้า</h5>
                    </div>
                    <div class="card-body">
                        <form action="/products/update/<%= product.id %>?_method=PUT" method="POST">
                            <div class="mb-3">
                                <label for="name" class="form-label">ชื่อสินค้า</label>
                                <input type="text" class="form-control" id="name" name="name" 
                                       value="<%= product.name %>" required>
                            </div>
                            <div class="mb-3">
                                <label for="category_id" class="form-label">หมวดหมู่</label>
                                <select class="form-select" id="category_id" name="category_id" required>
                                    <option value="">เลือกหมวดหมู่</option>
                                    <% categories.forEach(category => { %>
                                        <option value="<%= category.id %>" 
                                                <%= product.category_id == category.id ? 'selected' : '' %>>
                                            <%= category.name %>
                                        </option>
                                    <% }); %>
                                </select>
                            </div>
                            <div class="mb-3">
                                <label for="quantity" class="form-label">จำนวน</label>
                                <input type="number" class="form-control" id="quantity" name="quantity" 
                                       value="<%= product.quantity %>" min="0" required>
                            </div>
                            <div class="mb-3">
                                <label for="price" class="form-label">ราคา</label>
                                <input type="number" class="form-control" id="price" name="price" 
                                       value="<%= product.price %>" min="0" step="0.01" required>
                            </div>
                            <div class="d-grid gap-2">
                                <button type="submit" class="btn btn-warning">บันทึกการแก้ไข</button>
                                <a href="/products" class="btn btn-secondary">ยกเลิก</a>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html> 