<?php $__env->startSection('title', 'Setup — Complete Staff Records'); ?>
<?php $__env->startSection('content'); ?>

<div class="row mb-4">
    <div class="col-lg-4 mb-3">
        <div class="card h-100">
            <div class="mi-brand-strip rounded-top"></div>
            <div class="card-body">
                <h6 class="mb-1">Setup Progress</h6>
                <p class="text-xs text-muted">Staff with passport no., expiry, permit expiry and a photo.</p>
                <div class="d-flex align-items-end gap-2">
                    <h3 class="mb-0 text-primary"><?php echo e($percent); ?>%</h3>
                    <span class="text-sm text-muted mb-1"><?php echo e(number_format($complete)); ?> / <?php echo e(number_format($total)); ?> complete</span>
                </div>
                <div class="progress mt-2" style="height:8px">
                    <div class="progress-bar bg-gradient-primary" style="width: <?php echo e($percent); ?>%"></div>
                </div>
                <?php if(auth()->user()->isAdmin()): ?>
                    <a href="<?php echo e(route('import.show')); ?>" class="btn btn-sm btn-outline-primary w-100 mt-3 mb-0">
                        <i class="bi bi-file-earmark-spreadsheet me-1"></i>Import more from Excel
                    </a>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <div class="col-lg-8 mb-3">
        <div class="card h-100">
            <div class="card-header pb-0"><h6 class="mb-0">What still needs attention</h6></div>
            <div class="card-body pt-2">
                <div class="row g-2">
                    <?php $__currentLoopData = \App\Http\Controllers\SetupController::CHECKS; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="col-md-4 col-6">
                            <a href="<?php echo e(route('setup.index', ['check'=>$key,'site_id'=>$siteId])); ?>"
                               class="d-block border rounded p-2 text-center <?php echo e($check===$key ? 'border-primary bg-gray-100' : ''); ?>">
                                <div class="h5 mb-0 <?php echo e($counts[$key] > 0 ? 'text-danger' : 'text-success'); ?>"><?php echo e(number_format($counts[$key])); ?></div>
                                <span class="text-xs text-muted"><?php echo e($label); ?></span>
                            </a>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="card">
    <div class="card-header pb-0 d-flex justify-content-between align-items-center flex-wrap gap-2">
        <h6 class="mb-0"><?php echo e(\App\Http\Controllers\SetupController::CHECKS[$check] ?? 'Incomplete'); ?>

            <span class="text-sm text-muted">(<?php echo e($staff->total()); ?>)</span></h6>
        <form method="GET" class="d-flex gap-2 align-items-center">
            <input type="hidden" name="check" value="<?php echo e($check); ?>">
            <select name="site_id" class="form-select form-select-sm searchable" onchange="this.form.submit()" style="min-width:220px">
                <option value="">All sites</option>
                <?php $__currentLoopData = $sites; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $site): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($site->id); ?>" <?php if($siteId==$site->id): echo 'selected'; endif; ?>><?php echo e($site->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </form>
    </div>

    <div class="card-body">
        <div class="table-responsive">
            <table class="table align-items-center mb-0">
                <thead><tr class="text-xxs text-uppercase text-secondary">
                    <th class="ps-3">Staff</th><th>Site</th><th>Passport No</th>
                    <th>Passport Exp.</th><th>Permit Exp.</th><th>Photo</th><th></th>
                </tr></thead>
                <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $staff; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td class="ps-3">
                            <a href="<?php echo e(route('staff.show', $s)); ?>" class="text-sm font-weight-bold"><?php echo e($s->name); ?></a>
                            <div class="text-xs text-muted">#<?php echo e($s->running_no); ?> · <?php echo e($s->nationality?->name ?? '—'); ?></div>
                        </td>
                        <td class="text-sm"><?php echo e($s->site?->name ?? '—'); ?></td>
                        <td class="text-sm"><?php echo $s->passport_no ?: '<span class="text-danger">missing</span>'; ?></td>
                        <td class="text-sm"><?php echo optional($s->passport_expiry)->format('d/m/y') ?: '<span class="text-danger">—</span>'; ?></td>
                        <td class="text-sm"><?php echo optional($s->permit_expiry)->format('d/m/y') ?: '<span class="text-danger">—</span>'; ?></td>
                        <td>
                            <?php if($s->photoUrl()): ?>
                                <img src="<?php echo e($s->photoUrl()); ?>" class="rounded-circle border" style="width:28px;height:28px;object-fit:cover">
                            <?php else: ?>
                                <span class="text-danger text-xs">none</span>
                            <?php endif; ?>
                        </td>
                        <td class="text-end pe-3">
                            <button class="btn btn-sm btn-primary mb-0 py-1" data-bs-toggle="modal" data-bs-target="#fix-<?php echo e($s->id); ?>">
                                Complete
                            </button>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr><td colspan="7" class="text-center text-muted py-4">
                        <i class="bi bi-check-circle text-success me-1"></i>Nothing outstanding for this filter.
                    </td></tr>
                <?php endif; ?>
                </tbody>
            </table>
        </div>
        <div class="mt-3"><?php echo e($staff->links()); ?></div>
    </div>
</div>


<?php $__currentLoopData = $staff; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<div class="modal fade" id="fix-<?php echo e($s->id); ?>" tabindex="-1">
    <div class="modal-dialog modal-lg"><div class="modal-content">
        <form action="<?php echo e(route('setup.complete', $s)); ?>" method="POST" enctype="multipart/form-data">
            <?php echo csrf_field(); ?>
            <div class="modal-header">
                <h6 class="modal-title">Complete — <?php echo e($s->name); ?></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 text-xs">Passport No</label>
                        <input name="passport_no" value="<?php echo e($s->passport_no); ?>" class="form-control form-control-sm">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label text-xs">Passport Expiry</label>
                        <input type="date" name="passport_expiry" value="<?php echo e(optional($s->passport_expiry)->format('Y-m-d')); ?>" class="form-control form-control-sm">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label text-xs">Permit Expiry</label>
                        <input type="date" name="permit_expiry" value="<?php echo e(optional($s->permit_expiry)->format('Y-m-d')); ?>" class="form-control form-control-sm">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label text-xs">FOMEMA Expiry</label>
                        <input type="date" name="fomema_expiry" value="<?php echo e(optional($s->fomema_expiry)->format('Y-m-d')); ?>" class="form-control form-control-sm">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label text-xs">Staff Photo</label>
                        <input type="file" name="photo" accept="image/*" class="form-control form-control-sm">
                    </div>
                    <div class="col-md-4"></div>
                    <div class="col-md-6">
                        <label class="form-label text-xs">Passport Scan</label>
                        <input type="file" name="passport_file" class="form-control form-control-sm">
                    </div>
                    <div class="col-md-6">
                        <label class="form-label text-xs">Permit Scan</label>
                        <input type="file" name="permit_file" class="form-control form-control-sm">
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <a href="<?php echo e(route('staff.show', $s)); ?>" class="btn btn-sm btn-outline-secondary mb-0">Open full profile</a>
                <button class="btn btn-sm btn-primary mb-0">Save</button>
            </div>
        </form>
    </div></div>
</div>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /Users/kalaiarasen/projects/myindependent-worker-management/resources/views/setup/index.blade.php ENDPATH**/ ?>