

<?php $__env->startSection('title', 'Staff Management'); ?>

<?php $__env->startSection('content'); ?>
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
    <h1 class="h2">Staff Management</h1>
    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('staff.create')): ?>
        <div class="btn-toolbar mb-2 mb-md-0">
            <a href="<?php echo e(route('admin.users.create')); ?>" class="btn btn-primary">
                <i class="bi bi-person-plus"></i> Add Staff Member
            </a>
        </div>
    <?php endif; ?>
</div>

<!-- Sales KPI Cards -->
<div class="row g-4 mb-4">
    <div class="col-md-6 col-lg-3">
        <div class="card text-center">
            <div class="card-body">
                <h5 class="card-title text-muted mb-2">
                    <i class="bi bi-calendar-day"></i> Today Sales
                </h5>
                <h2 class="mb-0 text-primary">₹<?php echo e(number_format($todaySales, 2)); ?></h2>
                <small class="text-muted">All Staff Combined</small>
            </div>
        </div>
    </div>
    <div class="col-md-6 col-lg-3">
        <div class="card text-center">
            <div class="card-body">
                <h5 class="card-title text-muted mb-2">
                    <i class="bi bi-calendar-week"></i> This Week Sales
                </h5>
                <h2 class="mb-0 text-info">₹<?php echo e(number_format($thisWeekSales, 2)); ?></h2>
                <small class="text-muted">All Staff Combined</small>
            </div>
        </div>
    </div>
    <div class="col-md-6 col-lg-3">
        <div class="card text-center">
            <div class="card-body">
                <h5 class="card-title text-muted mb-2">
                    <i class="bi bi-calendar-month"></i> This Month Sales
                </h5>
                <h2 class="mb-0 text-success">₹<?php echo e(number_format($thisMonthSales, 2)); ?></h2>
                <small class="text-muted">All Staff Combined</small>
            </div>
        </div>
    </div>
    <div class="col-md-6 col-lg-3">
        <div class="card text-center">
            <div class="card-body">
                <h5 class="card-title text-muted mb-2">
                    <i class="bi bi-cart-check"></i> Orders / Avg Value
                </h5>
                <h2 class="mb-0 text-warning"><?php echo e(number_format($thisMonthOrders)); ?></h2>
                <small class="text-muted">Avg: ₹<?php echo e(number_format($avgOrderValue, 2)); ?></small>
            </div>
        </div>
    </div>
</div>

<!-- Staff List with Sales Statistics -->
<div class="card">
    <div class="card-body pb-0">
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Staff Number</th>
                        <th>Name</th>
                        <th>Mobile</th>
                        <th>Email</th>
                        <th>Roles</th>
                        <th>Total Sales</th>
                        <th>Total Orders</th>
                        <th>Avg Order Value</th>
                        <th>Last Sale</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $staffWithStats; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $staffData): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <?php
                            $user = $staffData['user'];
                        ?>
                        <tr>
                            <td>#<?php echo e($user->id); ?></td>
                            <td>
                                <?php if($user->staff_number): ?>
                                    <span class="badge bg-info"><?php echo e($user->staff_number); ?></span>
                                <?php else: ?>
                                    <span class="text-muted">-</span>
                                <?php endif; ?>
                            </td>
                            <td><?php echo e($user->name); ?></td>
                            <td><?php echo e($user->mobile); ?></td>
                            <td><?php echo e($user->email ?? '-'); ?></td>
                            <td>
                                <?php $__currentLoopData = $user->roles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $role): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <span class="badge bg-<?php echo e($role->name === 'admin' ? 'danger' : ($role->name === 'staff' ? 'warning' : 'primary')); ?>">
                                        <?php echo e(ucfirst($role->name)); ?>

                                    </span>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </td>
                            <td>
                                <strong class="text-success">₹<?php echo e(number_format($staffData['total_sales'], 2)); ?></strong>
                            </td>
                            <td>
                                <span class="badge bg-primary"><?php echo e($staffData['total_orders']); ?></span>
                            </td>
                            <td>
                                ₹<?php echo e(number_format($staffData['avg_order_value'], 2)); ?>

                            </td>
                            <td>
                                <?php if($staffData['last_order_date']): ?>
                                    <?php echo e(\Carbon\Carbon::parse($staffData['last_order_date'])->format('M d, Y')); ?>

                                <?php else: ?>
                                    <span class="text-muted">No sales</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <?php if($user->banned_at): ?>
                                    <span class="badge bg-danger">
                                        <i class="bi bi-ban"></i> Banned
                                    </span>
                                <?php else: ?>
                                    <span class="badge bg-success">
                                        <i class="bi bi-check-circle"></i> Active
                                    </span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('staff.update')): ?>
                                <a href="<?php echo e(route('admin.users.edit', $user->id)); ?>" class="btn btn-sm btn-primary">
                                    <i class="bi bi-person-gear"></i> Manage
                                </a>
                                <?php endif; ?>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="12" class="text-center text-muted py-4">
                                <i class="bi bi-inbox" style="font-size: 2rem;"></i>
                                <p class="mt-2">No staff members found.</p>
                            </td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>

        <!-- Pagination - Right Aligned -->
        <div class="pagination-wrapper">
            <div class="d-flex justify-content-end align-items-center gap-3 flex-wrap">
                <div class="pagination-info-text">
                    Showing <strong><?php echo e($users->firstItem() ?? 0); ?></strong>–<strong><?php echo e($users->lastItem() ?? 0); ?></strong> 
                    of <strong><?php echo e($users->total()); ?></strong> customers
                </div>
                <?php if($users->hasPages()): ?>
                <div class="pagination-controls">
                    <?php echo e($users->links('vendor.pagination.admin-categories')); ?>

                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /var/www/html/shaa_jewels/live/resources/views/admin/users/staff.blade.php ENDPATH**/ ?>