<?php $__env->startSection('content'); ?>
<div class="row">
    <div class="col-12">
        <div class="card mb-4">
            <h5 class="card-header"><?php echo e($item->exists ? 'Edit Barang' : 'Tambah Barang'); ?></h5>
            <div class="card-body">
                <form method="POST" action="<?php echo e($action); ?>" class="row g-3">
                    <?php echo csrf_field(); ?>
                    <?php if($method !== 'POST'): ?>
                        <?php echo method_field($method); ?>
                    <?php endif; ?>

                    <div class="col-md-6">
                        <label class="form-label">Lokasi</label>
                        <select name="location_id" class="form-select" required>
                            <option value="">Pilih lokasi</option>
                            <?php $__currentLoopData = $locations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $location): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($location->id); ?>" <?php if(old('location_id', $item->location_id) == $location->id): echo 'selected'; endif; ?>><?php echo e($location->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>

                    <div class="col-md-6">
                        <label class="form-label">Nama barang</label>
                        <input type="text" name="name" class="form-control" value="<?php echo e(old('name', $item->name)); ?>" required>
                    </div>

                    <div class="col-md-6">
                        <label class="form-label">Kategori</label>
                        <input list="category-list" name="category_name" class="form-control" value="<?php echo e(old('category_name', $item->category?->name)); ?>" placeholder="Contoh: Elektronik">
                        <datalist id="category-list">
                            <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($category->name); ?>"></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </datalist>
                    </div>

                    <div class="col-md-6">
                        <label class="form-label">Tracking mode</label>
                        <select name="tracking_mode" class="form-select" required>
                            <option value="stock" <?php if(old('tracking_mode', $item->tracking_mode) === 'stock'): echo 'selected'; endif; ?>>Stock</option>
                            <option value="unit" <?php if(old('tracking_mode', $item->tracking_mode) === 'unit'): echo 'selected'; endif; ?>>Unit</option>
                        </select>
                    </div>

                    <div class="col-md-6">
                        <label class="form-label">Satuan</label>
                        <input type="text" name="unit_of_measure" class="form-control" value="<?php echo e(old('unit_of_measure', $item->unit_of_measure ?: 'unit')); ?>" required>
                    </div>

                    <div class="col-md-6">
                        <label class="form-label">Total jumlah</label>
                        <input type="number" name="total_quantity" class="form-control" min="0" value="<?php echo e(old('total_quantity', $item->total_quantity)); ?>" required>
                    </div>

                    <div class="col-md-3">
                        <label class="form-label text-success">Kondisi Baik</label>
                        <input type="number" name="good_count" class="form-control" min="0" value="<?php echo e(old('good_count', $item->good_count)); ?>" required>
                    </div>

                    <div class="col-md-3">
                        <label class="form-label text-warning">Rusak Ringan</label>
                        <input type="number" name="minor_damage_count" class="form-control" min="0" value="<?php echo e(old('minor_damage_count', $item->minor_damage_count)); ?>" required>
                    </div>

                    <div class="col-md-3">
                        <label class="form-label text-danger">Rusak Berat</label>
                        <input type="number" name="major_damage_count" class="form-control" min="0" value="<?php echo e(old('major_damage_count', $item->major_damage_count)); ?>" required>
                    </div>

                    <div class="col-md-3">
                        <label class="form-label text-secondary">Hilang</label>
                        <input type="number" name="lost_count" class="form-control" min="0" value="<?php echo e(old('lost_count', $item->lost_count)); ?>" required>
                    </div>

                    <div class="col-md-6">
                        <label class="form-label">Tanggal pengecekan</label>
                        <input type="datetime-local" name="last_checked_at" class="form-control" value="<?php echo e(old('last_checked_at', $item->last_checked_at && $item->last_checked_at->format('H:i') !== '00:00' ? $item->last_checked_at->format('Y-m-d\TH:i') : now()->format('Y-m-d\TH:i'))); ?>">
                    </div>

                    <div class="col-12">
                        <label class="form-label">Catatan</label>
                        <textarea name="notes" class="form-control" rows="4"><?php echo e(old('notes', $item->notes)); ?></textarea>
                    </div>

                    <div class="col-12">
                        <div class="form-check">
                            <input type="checkbox" class="form-check-input" name="is_active" id="is_active" value="1" <?php if(old('is_active', $item->is_active ?? true)): echo 'checked'; endif; ?>>
                            <label class="form-check-label" for="is_active">Barang aktif</label>
                        </div>
                    </div>

                    <div class="col-12 text-end mt-4">
                        <a href="<?php echo e(route('items.index')); ?>" class="btn btn-label-secondary me-2">Kembali</a>
                        <button type="submit" class="btn btn-primary">Simpan Barang</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', ['title' => 'Form Inventaris', 'heading' => $item->exists ? 'Edit Barang' : 'Tambah Barang'], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH G:\Project\inventaris-pondok\resources\views/items/form.blade.php ENDPATH**/ ?>