<?php $__env->startSection('title', 'Staff Profile'); ?>
<?php $canManage = auth()->user()->isAdmin() || auth()->user()->isSupervisor(); ?>
<?php $__env->startSection('content'); ?>
<div class="row">
    
    <div class="col-lg-4 mb-4">
        <div class="card">
            <div class="mi-brand-strip rounded-top"></div>
            <div class="card-body text-center">
                <?php if($staff->photoUrl()): ?>
                    <img src="<?php echo e($staff->photoUrl()); ?>" class="rounded-circle border mx-auto mb-3" style="width:96px;height:96px;object-fit:cover" alt="photo">
                <?php else: ?>
                    <div class="icon icon-lg icon-shape bg-gradient-primary rounded-circle mx-auto mb-3 d-flex align-items-center justify-content-center" style="width:96px;height:96px">
                        <span class="text-white h3 mb-0"><?php echo e(strtoupper(substr($staff->name,0,1))); ?></span>
                    </div>
                <?php endif; ?>
                <h5 class="mb-0"><?php echo e($staff->name); ?></h5>
                <p class="text-sm text-muted mb-2"><?php echo e($staff->designation ?? 'Worker'); ?> · <?php echo e($staff->passport_no); ?></p>
                <span class="badge bg-<?php echo e($staff->statusColor()); ?>"><?php echo e(ucfirst($staff->status)); ?></span>
                <?php if($canManage): ?>
                    <div class="mt-3"><a href="<?php echo e(route('staff.edit', $staff)); ?>" class="btn btn-sm btn-outline-primary"><i class="bi bi-pencil me-1"></i>Edit Profile</a></div>
                <?php endif; ?>
            </div>
            <hr class="horizontal dark my-0">
            <div class="card-body text-sm">
                <div class="d-flex justify-content-between py-1"><span class="text-muted">Running No</span><span>#<?php echo e($staff->running_no); ?></span></div>
                <div class="d-flex justify-content-between py-1"><span class="text-muted">Site / Project</span><span><?php echo e($staff->site?->name ?? '—'); ?></span></div>
                <div class="d-flex justify-content-between py-1"><span class="text-muted">Department</span><span><?php echo e($staff->department ?? '—'); ?></span></div>
                <div class="d-flex justify-content-between py-1"><span class="text-muted">Nationality</span><span><?php echo e($staff->nationality?->name ?? '—'); ?></span></div>
                <div class="d-flex justify-content-between py-1"><span class="text-muted">Gender</span><span><?php echo e(ucfirst($staff->gender ?? '—')); ?></span></div>
                <div class="d-flex justify-content-between py-1"><span class="text-muted">Date Joined</span><span><?php echo e(optional($staff->date_of_join)->format('d M Y') ?? '—'); ?></span></div>
                <?php if($staff->resign_date): ?><div class="d-flex justify-content-between py-1"><span class="text-muted">Resigned</span><span><?php echo e($staff->resign_date->format('d M Y')); ?></span></div><?php endif; ?>
            </div>
            <hr class="horizontal dark my-0">
            <div class="card-body text-sm">
                <h6 class="text-xs text-uppercase text-muted">Payroll & Bank</h6>
                <div class="d-flex justify-content-between py-1"><span class="text-muted">Basic Rate</span><span>RM <?php echo e(number_format((float)$staff->basic_rate, 2)); ?> / <?php echo e($staff->pay_basis); ?></span></div>
                <div class="d-flex justify-content-between py-1"><span class="text-muted">Bank</span><span><?php echo e($staff->bank?->name ?? '—'); ?></span></div>
                <div class="d-flex justify-content-between py-1"><span class="text-muted">Account</span><span><?php echo e($staff->account_number ?? '—'); ?></span></div>
            </div>
        </div>
    </div>

    
    <div class="col-lg-8 mb-4">
        <div class="card">
            <div class="card-header pb-0">
                <ul class="nav nav-pills nav-fill flex-column flex-sm-row text-xs" id="profileTabs" role="tablist">
                    <?php $__currentLoopData = ['passport'=>'Passport','permit'=>'Permit','fomema'=>'FOMEMA','sites'=>'Sites','documents'=>'Documents','payslips'=>'Payslips']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $k=>$label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li class="nav-item"><button class="nav-link <?php echo e($loop->first ? 'active' : ''); ?>" data-bs-toggle="tab" data-bs-target="#tab-<?php echo e($k); ?>" type="button"><?php echo e($label); ?></button></li>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </ul>
            </div>
            <div class="card-body">
                <div class="tab-content">
                    <div class="tab-pane fade show active" id="tab-passport">
                        <?php echo $__env->make('staff._renewal_tab', ['type'=>'passport','label'=>'Passport','col'=>'passport_expiry'], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    </div>
                    <div class="tab-pane fade" id="tab-permit">
                        <?php echo $__env->make('staff._renewal_tab', ['type'=>'permit','label'=>'Permit','col'=>'permit_expiry'], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    </div>
                    <div class="tab-pane fade" id="tab-fomema">
                        <?php echo $__env->make('staff._renewal_tab', ['type'=>'fomema','label'=>'FOMEMA','col'=>'fomema_expiry'], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    </div>

                    
                    <div class="tab-pane fade" id="tab-sites">
                        <div class="row">
                            <div class="col-md-5 mb-3">
                                <div class="border rounded p-3 h-100">
                                    <span class="text-xs text-uppercase text-muted">Current Site</span>
                                    <div class="h5 mb-0 mt-1"><?php echo e($staff->site?->name ?? 'Unassigned'); ?></div>
                                    <span class="text-xs text-muted"><?php echo e($staff->site?->client); ?></span>
                                </div>
                            </div>
                            <?php if($canManage): ?>
                            <div class="col-md-7 mb-3">
                                <div class="border rounded p-3">
                                    <h6 class="text-sm mb-2">Reassign Site</h6>
                                    <form action="<?php echo e(route('staff.reassign', $staff)); ?>" method="POST">
                                        <?php echo csrf_field(); ?>
                                        <div class="row g-2">
                                            <div class="col-7"><label class="form-label text-xs">New Site *</label>
                                                <select name="site_id" class="form-select form-select-sm searchable" required>
                                                    <option value="">—</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($staff->site_id==$site->id): echo 'selected'; endif; ?>><?php echo e($site->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </select></div>
                                            <div class="col-5"><label class="form-label text-xs">Assigned On</label><input type="date" name="assigned_on" value="<?php echo e(now()->format('Y-m-d')); ?>" class="form-control form-control-sm"></div>
                                            <div class="col-12"><label class="form-label text-xs">Remarks</label><input name="remarks" class="form-control form-control-sm"></div>
                                            <div class="col-12 text-end"><button class="btn btn-primary btn-sm mb-0">Reassign</button></div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                            <?php endif; ?>
                            <div class="col-12">
                                <h6 class="text-xs text-uppercase text-muted">Assignment History</h6>
                                <div class="table-responsive"><table class="table table-sm align-items-center mb-0">
                                    <thead><tr class="text-xxs text-uppercase text-secondary"><th>Site</th><th>From</th><th>To</th><th>Remarks</th><th>By</th></tr></thead>
                                    <tbody>
                                    <?php $__empty_1 = true; $__currentLoopData = $staff->siteAssignments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $a): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                        <tr>
                                            <td class="text-sm font-weight-bold"><?php echo e($a->site?->name ?? '—'); ?></td>
                                            <td class="text-sm"><?php echo e(optional($a->assigned_on)->format('d/m/Y') ?? '—'); ?></td>
                                            <td class="text-sm"><?php if($a->ended_on): ?><?php echo e($a->ended_on->format('d/m/Y')); ?><?php else: ?><span class="badge bg-success">Current</span><?php endif; ?></td>
                                            <td class="text-sm"><?php echo e($a->remarks ?? '—'); ?></td>
                                            <td class="text-sm"><?php echo e($a->creator?->name ?? '—'); ?></td>
                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                        <tr><td colspan="5" class="text-center text-muted py-3">No site assignment history yet.</td></tr>
                                    <?php endif; ?>
                                    </tbody>
                                </table></div>
                            </div>
                        </div>
                    </div>

                    
                    <div class="tab-pane fade" id="tab-documents">
                        <?php if($canManage): ?>
                        <div class="border rounded p-3 mb-3">
                            <h6 class="text-sm mb-2">Upload Document</h6>
                            <form action="<?php echo e(route('documents.store', $staff)); ?>" method="POST" enctype="multipart/form-data">
                                <?php echo csrf_field(); ?>
                                <div class="row g-2 align-items-end">
                                    <div class="col-md-4"><label class="form-label text-xs">Title *</label><input name="title" class="form-control form-control-sm" required></div>
                                    <div class="col-md-3"><label class="form-label text-xs">Type</label>
                                        <select name="type" class="form-select form-select-sm">
                                            <option value="contract">Contract</option><option value="passport">Passport</option>
                                            <option value="permit">Permit</option><option value="fomema">FOMEMA</option>
                                            <option value="insurance">Insurance</option><option value="other" selected>Other</option>
                                        </select></div>
                                    <div class="col-md-3"><label class="form-label text-xs">Expiry</label><input type="date" name="expiry_date" class="form-control form-control-sm"></div>
                                    <div class="col-md-2"><input type="file" name="file" class="form-control form-control-sm" required></div>
                                    <div class="col-12 text-end"><button class="btn btn-primary btn-sm mb-0"><i class="bi bi-upload me-1"></i>Upload</button></div>
                                </div>
                            </form>
                        </div>
                        <?php endif; ?>
                        <div class="table-responsive"><table class="table table-sm align-items-center mb-0">
                            <thead><tr class="text-xxs text-uppercase text-secondary"><th>Title</th><th>Type</th><th>Expiry</th><th>Uploaded</th><th></th></tr></thead>
                            <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $staff->documents; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $doc): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <td class="text-sm font-weight-bold"><?php echo e($doc->title); ?></td>
                                    <td class="text-sm"><?php echo e(ucfirst($doc->type)); ?></td>
                                    <td class="text-sm"><?php echo e(optional($doc->expiry_date)->format('d/m/y') ?? '—'); ?></td>
                                    <td class="text-sm text-muted"><?php echo e($doc->created_at->format('d/m/y')); ?></td>
                                    <td class="text-end">
                                        <a href="<?php echo e(route('documents.download', $doc)); ?>" class="text-secondary me-2"><i class="bi bi-download"></i></a>
                                        <?php if($canManage): ?>
                                        <form action="<?php echo e(route('documents.destroy', $doc)); ?>" method="POST" class="d-inline" onsubmit="return confirm('Delete this document?')">
                                            <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?><button class="btn btn-link p-0 text-danger"><i class="bi bi-trash"></i></button>
                                        </form><?php endif; ?>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr><td colspan="5" class="text-center text-muted py-3">No documents uploaded.</td></tr>
                            <?php endif; ?>
                            </tbody>
                        </table></div>
                    </div>

                    
                    <div class="tab-pane fade" id="tab-payslips">
                        <div class="table-responsive"><table class="table table-sm align-items-center mb-0">
                            <thead><tr class="text-xxs text-uppercase text-secondary"><th>Period</th><th>Nett Pay</th><th>Status</th><th></th></tr></thead>
                            <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $staff->payslips; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <td class="text-sm font-weight-bold"><?php echo e($p->periodLabel()); ?></td>
                                    <td class="text-sm">RM <?php echo e(number_format($p->nett_pay, 2)); ?></td>
                                    <td><span class="badge bg-<?php echo e($p->status==='finalized'?'success':'secondary'); ?>"><?php echo e(ucfirst($p->status)); ?></span></td>
                                    <td class="text-end">
                                        <?php if(auth()->user()->isAdmin() || auth()->user()->isFinance()): ?><a href="<?php echo e(route('payroll.show', $p)); ?>" class="text-secondary me-2"><i class="bi bi-eye"></i></a><?php endif; ?>
                                        <?php if($p->status==='finalized'): ?><a href="<?php echo e(route('payslips.pdf', $p)); ?>" class="text-secondary"><i class="bi bi-file-earmark-pdf"></i></a><?php endif; ?>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr><td colspan="4" class="text-center text-muted py-3">No payslips yet.</td></tr>
                            <?php endif; ?>
                            </tbody>
                        </table></div>
                    </div>
                </div>
            </div>
        </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 /Users/kalaiarasen/projects/myindependent-worker-management/resources/views/staff/show.blade.php ENDPATH**/ ?>