<div class="page-header">
    <div>
        <a href="<?= APP_URL ?>/batches" class="btn btn-ghost btn-sm mb-4" style="padding-left:0;">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>
            Back to Batches
        </a>
        <h1>Edit Batch</h1>
        <div class="page-subtitle">Update batch information</div>
    </div>
</div>

<div class="card">
    <div class="card-header">
        <h3 class="card-title">Edit Batch #<?= e($batch['batch_no']) ?></h3>
    </div>
    <form action="<?= APP_URL ?>/batches/update" method="POST">
        <?= Security::csrfField() ?>
        <input type="hidden" name="id" value="<?= $batch['id'] ?>">
        
        <div class="grid-2">
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title">Batch Details</h4>
                </div>
                <div class="card-body">
                    <div class="form-group">
                        <label class="form-label">Product <span class="required">*</span></label>
                        <select name="product_id" class="form-control" required>
                            <option value="">Select Product...</option>
                            <?php foreach ($products as $product): ?>
                                <option value="<?= $product['id'] ?>" <?= $product['id'] == $batch['product_id'] ? 'selected' : '' ?>>
                                    <?= e($product['name']) ?>
                                </option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    
                    <div class="form-group">
                        <label class="form-label">Location <span class="required">*</span></label>
                        <select name="location_id" class="form-control" required>
                            <option value="">Select Location...</option>
                            <?php foreach ($locations as $location): ?>
                                <option value="<?= $location['id'] ?>" <?= $location['id'] == $batch['location_id'] ? 'selected' : '' ?>>
                                    <?= e($location['name']) ?>
                                </option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    
                    <div class="form-group">
                        <label class="form-label">Batch Number <span class="required">*</span></label>
                        <input type="text" name="batch_no" class="form-control" value="<?= e($batch['batch_no']) ?>" required>
                    </div>
                    
                    <div class="form-group">
                        <label class="form-label">Manufacturing Date <span class="required">*</span></label>
                        <input type="date" name="mfg_date" class="form-control" value="<?= $batch['mfg_date'] ?>" required>
                    </div>
                    
                    <div class="form-group">
                        <label class="form-label">Expiry Date</label>
                        <input type="date" name="expiry_date" class="form-control" value="<?= $batch['expiry_date'] ?? '' ?>">
                        <small class="text-muted">Leave empty if no expiry date</small>
                    </div>
                    
                    <div class="form-group">
                        <label class="form-label">Quantity <span class="required">*</span></label>
                        <input type="number" name="quantity" class="form-control" value="<?= $batch['quantity'] ?>" min="0.01" step="0.01" required>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="flex justify-between">
            <a href="<?= APP_URL ?>/batches" class="btn btn-outline">Cancel</a>
            <button type="submit" class="btn btn-primary">Update Batch</button>
        </div>
    </form>
</div>

<style>
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 768px) {
    .grid-2 {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}
</style>
