<?php $__env->startSection('title', 'Staff'); ?>
<?php $__env->startSection('page-title', 'Staff Management'); ?>
<?php $__env->startSection('page-subtitle', 'Tenant users, base roles, and customizable role profiles'); ?>

<?php $__env->startSection('content'); ?>
<?php ($showBranchField = $showBranchField ?? $branches->count() > 1); ?>
<div class="row g-4">
    <div class="col-lg-4">
        <div class="card border-0 shadow-sm">
            <div class="card-body">
                <h2 class="h5">Add staff</h2>
                <form method="POST" action="<?php echo e(route('tenant.staff.store')); ?>" class="vstack gap-2">
                    <?php echo csrf_field(); ?>
                    <input name="name" class="form-control" placeholder="Full name" required>
                    <input name="email" type="email" class="form-control" placeholder="Email" required>
                    <input name="phone" class="form-control" placeholder="Phone">
                    <select name="role" class="form-select" required>
                        <?php $__currentLoopData = $roles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($value); ?>"><?php echo e($label); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                    <select name="role_profile_id" class="form-select">
                        <option value="">Use base role permissions</option>
                        <?php $__currentLoopData = $roleProfiles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $profile): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($profile->id); ?>"><?php echo e($profile->name); ?> - <?php echo e($profile->permissionCount()); ?> permissions</option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                    <?php if($showBranchField): ?>
                        <select name="branch_id" class="form-select" required>
                            <?php $__currentLoopData = $branches; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $branch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($branch->id); ?>" <?php if((string) ($defaultBranchId ?? '') === (string) $branch->id): echo 'selected'; endif; ?>><?php echo e($branch->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    <?php else: ?>
                        <input type="hidden" name="branch_id" value="<?php echo e($defaultBranchId); ?>">
                    <?php endif; ?>
                    <input name="password" type="password" class="form-control" placeholder="Temporary password" required>
                    <select name="status" class="form-select"><option value="active">Active</option><option value="inactive">Inactive</option></select>
                    <button class="btn btn-primary">Add staff</button>
                </form>
                <div class="small text-muted mt-3">
                    Create detailed access profiles from Settings > Role Profiles, then assign them here.
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-8">
        <div class="card border-0 shadow-sm">
            <div class="table-responsive">
                <table class="table mb-0"><thead><tr><th>Name</th><th>Email</th><th>Role</th><th>Profile</th><?php if($showBranchField): ?><th>Branch</th><?php endif; ?><th>Status</th><th></th></tr></thead><tbody>
                <?php $__currentLoopData = $staff; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $member): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <form method="POST" action="<?php echo e(route('tenant.staff.update', $member)); ?>">
                            <?php echo csrf_field(); ?> <?php echo method_field('PATCH'); ?>
                            <td><input name="name" value="<?php echo e($member->name); ?>" class="form-control form-control-sm"></td>
                            <td><?php echo e($member->email); ?></td>
                            <td><select name="role" class="form-select form-select-sm"><?php $__currentLoopData = $roles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($value); ?>" <?php if($member->role===$value): echo 'selected'; endif; ?>><?php echo e($label); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></td>
                            <td>
                                <select name="role_profile_id" class="form-select form-select-sm">
                                    <option value="">Base role</option>
                                    <?php $__currentLoopData = $roleProfiles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $profile): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($profile->id); ?>" <?php if($member->role_profile_id === $profile->id): echo 'selected'; endif; ?>><?php echo e($profile->name); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </td>
                            <?php if($showBranchField): ?>
                                <td><select name="branch_id" class="form-select form-select-sm" required><?php $__currentLoopData = $branches; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $branch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($branch->id); ?>" <?php if((string) ($member->branch_id ?? $defaultBranchId) === (string) $branch->id): echo 'selected'; endif; ?>><?php echo e($branch->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></td>
                            <?php else: ?>
                                <input type="hidden" name="branch_id" value="<?php echo e($member->branch_id ?: $defaultBranchId); ?>">
                            <?php endif; ?>
                            <td><select name="status" class="form-select form-select-sm"><option <?php if($member->status==='active'): echo 'selected'; endif; ?> value="active">Active</option><option <?php if($member->status==='inactive'): echo 'selected'; endif; ?> value="inactive">Inactive</option></select><input type="hidden" name="phone" value="<?php echo e($member->phone); ?>"></td>
                            <td class="text-end"><button class="btn btn-sm btn-outline-primary">Save</button>
                        </form>
                            <?php if($member->id !== auth()->id()): ?>
                                <form method="POST" action="<?php echo e(route('tenant.staff.destroy', $member)); ?>" class="d-inline"><?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?><button class="btn btn-sm btn-outline-danger">Deactivate</button></form>
                            <?php endif; ?>
                            </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody></table>
            </div>
            <div class="card-body"><?php echo e($staff->links()); ?></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 C:\Users\Polite hp\Documents\Codex\2026-05-08\build-a-complete-production-ready-saas\microfinance-saas\resources\views\tenant\staff\index.blade.php ENDPATH**/ ?>