<?php $__env->startSection('title', __('messages.warehouses')); ?>

<?php $__env->startSection('content'); ?>
<div class="d-flex align-items-center justify-content-between mb-3">
    <div>
        <h5 class="fw-bold mb-0">Warehouse & Van Stock Master</h5>
        <span class="text-muted fs-xs">Setup Physical Warehouses, Branch Stock & Mobile Van Stock Locations</span>
    </div>
    <button class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#createWhModal">
        <i class="bi bi-plus-lg me-1"></i> Add New Warehouse / Van
    </button>
</div>

<div class="card-erp">
    <div class="table-responsive">
        <table class="table table-dense table-hover mb-0">
            <thead>
                <tr>
                    <th>Code</th>
                    <th>Name (EN)</th>
                    <th>Name (AR)</th>
                    <th>Branch</th>
                    <th>Type</th>
                    <th>Contact Person</th>
                    <th>Phone</th>
                    <th>Status</th>
                    <th class="text-end">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $warehouses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $wh): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td><code class="fw-bold text-primary"><?php echo e($wh->code); ?></code></td>
                        <td class="fw-bold text-dark"><?php echo e($wh->name_en); ?></td>
                        <td><?php echo e($wh->name_ar ?? '-'); ?></td>
                        <td><?php echo e($wh->branch->name_en ?? 'All Branches'); ?></td>
                        <td>
                            <?php if($wh->type === 'main'): ?>
                                <span class="badge bg-primary">Main Warehouse</span>
                            <?php elseif($wh->type === 'van'): ?>
                                <span class="badge bg-warning text-dark"><i class="bi bi-truck me-1"></i> Van Warehouse</span>
                            <?php elseif($wh->type === 'transit'): ?>
                                <span class="badge bg-info text-dark">Transit</span>
                            <?php elseif($wh->type === 'damaged'): ?>
                                <span class="badge bg-danger">Damaged Stock</span>
                            <?php else: ?>
                                <span class="badge bg-secondary">Branch Warehouse</span>
                            <?php endif; ?>
                        </td>
                        <td><?php echo e($wh->contact_person ?? '-'); ?></td>
                        <td><?php echo e($wh->phone ?? '-'); ?></td>
                        <td>
                            <?php if($wh->status === 'active'): ?>
                                <span class="badge bg-success">Active</span>
                            <?php else: ?>
                                <span class="badge bg-danger">Inactive</span>
                            <?php endif; ?>
                        </td>
                        <td class="text-end">
                            <form action="<?php echo e(route('warehouses.destroy', $wh->id)); ?>" method="POST" class="d-inline" onsubmit="return confirm('Delete warehouse?')">
                                <?php echo csrf_field(); ?>
                                <?php echo method_field('DELETE'); ?>
                                <button type="submit" class="btn btn-dense btn-outline-danger"><i class="bi bi-trash"></i> Delete</button>
                            </form>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr><td colspan="9" class="text-center py-3 text-muted">No warehouses found.</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

<!-- Create Warehouse Modal -->
<div class="modal fade" id="createWhModal" tabindex="-1">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <form method="POST" action="<?php echo e(route('warehouses.store')); ?>">
                <?php echo csrf_field(); ?>
                <div class="modal-header py-2">
                    <h6 class="modal-title fw-bold">Add Warehouse / Van Location</h6>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <div class="row g-3">
                        <div class="col-md-4">
                            <label class="form-label small fw-semibold">Warehouse Code <span class="text-danger">*</span></label>
                            <input type="text" name="code" class="form-control form-control-sm" placeholder="e.g. WH-001 or VAN-001" required>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label small fw-semibold">Name (EN) <span class="text-danger">*</span></label>
                            <input type="text" name="name_en" class="form-control form-control-sm" placeholder="e.g. Main Warehouse" required>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label small fw-semibold">Name (AR)</label>
                            <input type="text" name="name_ar" class="form-control form-control-sm" placeholder="المستودع الرئيسي">
                        </div>
                        <div class="col-md-4">
                            <label class="form-label small fw-semibold">Branch</label>
                            <select name="branch_id" class="form-select form-select-sm">
                                <option value="">Select Branch...</option>
                                <?php $__currentLoopData = $branches; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $b): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($b->id); ?>"><?php echo e($b->name_en); ?> (<?php echo e($b->code); ?>)</option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label small fw-semibold">Warehouse Type <span class="text-danger">*</span></label>
                            <select name="type" class="form-select form-select-sm" required>
                                <option value="main">Main Warehouse</option>
                                <option value="branch">Branch Warehouse</option>
                                <option value="van">Van Warehouse (Mobile Sales)</option>
                                <option value="transit">Transit Warehouse</option>
                                <option value="damaged">Damaged Stock Warehouse</option>
                            </select>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label small fw-semibold">Status</label>
                            <select name="status" class="form-select form-select-sm">
                                <option value="active">Active</option>
                                <option value="inactive">Inactive</option>
                            </select>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label small fw-semibold">Contact Person</label>
                            <input type="text" name="contact_person" class="form-control form-control-sm">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label small fw-semibold">Phone Number</label>
                            <input type="text" name="phone" class="form-control form-control-sm">
                        </div>
                    </div>
                </div>
                <div class="modal-footer py-2">
                    <button type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-sm btn-primary">Save Warehouse</button>
                </div>
            </form>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\saudi\resources\views\settings\warehouses\index.blade.php ENDPATH**/ ?>