<?php
if (Auth('admin')->User()->dashboard_style == 'light') {
    $text = 'dark';
    $bg = 'light';
} else {
    $bg = 'dark';
    $text = 'light';
}
?>


<?php $__env->startSection('title', $title ?? 'Leave Applications Management'); ?>

<?php $__env->startSection('content'); ?>
    <?php echo $__env->make('admin.topmenu', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <?php echo $__env->make('admin.sidebar', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <div class="main-panel">
        <div class="content">
            <div class="page-inner">
                <div class="mt-2 mb-4">
                    <h1 class="title1 text-<?php echo e($text); ?>"><?php echo e($title ?? 'Leave Applications Management'); ?></h1>
                    <p class="text-muted mt-1">Manage and review military leave applications</p>
                </div>

                <?php if (isset($component)) { $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4 = $component; } ?>
<?php $component = $__env->getContainer()->make(Illuminate\View\AnonymousComponent::class, ['view' => 'components.danger-alert','data' => []]); ?>
<?php $component->withName('danger-alert'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php $component->withAttributes([]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4)): ?>
<?php $component = $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4; ?>
<?php unset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4); ?>
<?php endif; ?>
                <?php if (isset($component)) { $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4 = $component; } ?>
<?php $component = $__env->getContainer()->make(Illuminate\View\AnonymousComponent::class, ['view' => 'components.success-alert','data' => []]); ?>
<?php $component->withName('success-alert'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php $component->withAttributes([]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4)): ?>
<?php $component = $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4; ?>
<?php unset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4); ?>
<?php endif; ?>

                <!-- Statistics Cards -->
                <div class="row mb-4">
                    <div class="col-xl-3 col-md-6 mb-4">
                        <div class="card border-left-primary shadow h-100 py-2">
                            <div class="card-body">
                                <div class="row no-gutters align-items-center">
                                    <div class="col mr-2">
                                        <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Total Applications</div>
                                        <div class="h5 mb-0 font-weight-bold text-<?php echo e($text); ?>"><?php echo e($stats['total']); ?></div>
                                    </div>
                                    <div class="col-auto">
                                        <i class="fas fa-file-alt fa-2x text-gray-300"></i>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-xl-3 col-md-6 mb-4">
                        <div class="card border-left-warning shadow h-100 py-2">
                            <div class="card-body">
                                <div class="row no-gutters align-items-center">
                                    <div class="col mr-2">
                                        <div class="text-xs font-weight-bold text-warning text-uppercase mb-1">Pending Review</div>
                                        <div class="h5 mb-0 font-weight-bold text-<?php echo e($text); ?>"><?php echo e($stats['pending']); ?></div>
                                    </div>
                                    <div class="col-auto">
                                        <i class="fas fa-clock fa-2x text-gray-300"></i>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-xl-3 col-md-6 mb-4">
                        <div class="card border-left-success shadow h-100 py-2">
                            <div class="card-body">
                                <div class="row no-gutters align-items-center">
                                    <div class="col mr-2">
                                        <div class="text-xs font-weight-bold text-success text-uppercase mb-1">Approved</div>
                                        <div class="h5 mb-0 font-weight-bold text-<?php echo e($text); ?>"><?php echo e($stats['approved']); ?></div>
                                    </div>
                                    <div class="col-auto">
                                        <i class="fas fa-check-circle fa-2x text-gray-300"></i>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-xl-3 col-md-6 mb-4">
                        <div class="card border-left-info shadow h-100 py-2">
                            <div class="card-body">
                                <div class="row no-gutters align-items-center">
                                    <div class="col mr-2">
                                        <div class="text-xs font-weight-bold text-info text-uppercase mb-1">This Week</div>
                                        <div class="h5 mb-0 font-weight-bold text-<?php echo e($text); ?>"><?php echo e($stats['recent']); ?></div>
                                    </div>
                                    <div class="col-auto">
                                        <i class="fas fa-calendar-week fa-2x text-gray-300"></i>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Search and Filter Section -->
                <div class="mb-5 row">
                    <div class="col-md-12">
                        <div class="card p-md-4 p-2">
                            <div class="card-header py-3">
                                <h6 class="m-0 font-weight-bold text-primary">
                                    <i class="fas fa-search mr-2"></i>Search & Filter Applications
                                </h6>
                            </div>
                            <div class="card-body">
                                <form method="GET" action="<?php echo e(route('admin.leave-applications.index')); ?>" class="row">
                                    <div class="col-md-4 mb-3">
                                        <label for="search" class="form-label text-<?php echo e($text); ?> font-weight-bold">Search Applications</label>
                                        <input type="text" class="form-control text-<?php echo e($text); ?>" id="search" name="search"
                                               value="<?php echo e(request('search')); ?>"
                                               placeholder="Search by name, service number, or email...">
                                    </div>
                                    <div class="col-md-3 mb-3">
                                        <label for="status" class="form-label text-<?php echo e($text); ?> font-weight-bold">Status Filter</label>
                                        <select class="form-control text-<?php echo e($text); ?>" id="status" name="status">
                                            <option value="">All Status</option>
                                            <option value="pending" <?php echo e(request('status') === 'pending' ? 'selected' : ''); ?>>Pending</option>
                                            <option value="approved" <?php echo e(request('status') === 'approved' ? 'selected' : ''); ?>>Approved</option>
                                            <option value="rejected" <?php echo e(request('status') === 'rejected' ? 'selected' : ''); ?>>Rejected</option>
                                        </select>
                                    </div>
                                    <div class="col-md-3 d-flex align-items-end mb-3">
                                        <button type="submit" class="btn btn-primary mr-2">
                                            <i class="fas fa-search mr-1"></i>Search
                                        </button>
                                        <a href="<?php echo e(route('admin.leave-applications.index')); ?>" class="btn btn-secondary">
                                            <i class="fas fa-undo mr-1"></i>Reset
                                        </a>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Applications Table -->
                <div class="mb-5 row">
                    <div class="col-md-12">
                        <div class="card p-md-4 p-2">
                            <div class="card-header py-3">
                                <h6 class="m-0 font-weight-bold text-primary">
                                    <i class="fas fa-list mr-2"></i>Leave Applications (<?php echo e($applications->total()); ?> total)
                                </h6>
                            </div>
                            <div class="card-body">
                                <?php if($applications->count() > 0): ?>
                                    <div class="table-responsive">
                                        <table class="table table-bordered" width="100%" cellspacing="0">
                                            <thead class="thead-light">
                                                <tr>
                                                    <th class="text-<?php echo e($text); ?>">ID</th>
                                                    <th class="text-<?php echo e($text); ?>">Service Member</th>
                                                    <th class="text-<?php echo e($text); ?>">Rank</th>
                                                    <th class="text-<?php echo e($text); ?>">Leave Type</th>
                                                    <th class="text-<?php echo e($text); ?>">Duration</th>
                                                    <th class="text-<?php echo e($text); ?>">Submitted</th>
                                                    <th class="text-<?php echo e($text); ?>">Status</th>
                                                    <th class="text-<?php echo e($text); ?>">Actions</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php $__currentLoopData = $applications; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $application): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <tr>
                                                        <td class="font-weight-bold text-<?php echo e($text); ?>">
                                                            LA-<?php echo e(str_pad($application->id, 6, '0', STR_PAD_LEFT)); ?>

                                                        </td>
                                                        <td class="text-<?php echo e($text); ?>">
                                                            <div class="font-weight-bold"><?php echo e($application->full_name); ?></div>
                                                            <small class="text-muted"><?php echo e($application->service_number); ?></small>
                                                        </td>
                                                        <td class="text-<?php echo e($text); ?>">
                                                            <span class="badge badge-secondary"><?php echo e($application->rank); ?></span>
                                                        </td>
                                                        <td class="text-<?php echo e($text); ?>"><?php echo e(ucfirst(str_replace('_', ' ', $application->leave_type))); ?></td>
                                                        <td class="text-<?php echo e($text); ?>">
                                                            <div><?php echo e($application->formatted_start_date); ?> - <?php echo e($application->formatted_end_date); ?></div>
                                                            <small class="text-muted"><?php echo e($application->days_requested); ?> days</small>
                                                        </td>
                                                        <td class="text-<?php echo e($text); ?>"><?php echo e($application->formatted_submitted_at); ?></td>
                                                        <td>
                                                            <?php if($application->status === 'pending'): ?>
                                                                <span class="badge badge-warning">
                                                                    <i class="fas fa-clock mr-1"></i>Pending
                                                                </span>
                                                            <?php elseif($application->status === 'approved'): ?>
                                                                <span class="badge badge-success">
                                                                    <i class="fas fa-check mr-1"></i>Approved
                                                                </span>
                                                            <?php elseif($application->status === 'rejected'): ?>
                                                                <span class="badge badge-danger">
                                                                    <i class="fas fa-times mr-1"></i>Rejected
                                                                </span>
                                                            <?php endif; ?>
                                                        </td>
                                                        <td>
                                                            <div class="btn-group" role="group">
                                                                <a href="<?php echo e(route('admin.leave-applications.show', $application)); ?>"
                                                                   class="btn btn-sm btn-info" title="View Details">
                                                                    <i class="fas fa-eye"></i>
                                                                </a>

                                                                <?php if($application->status === 'pending'): ?>
                                                                    <form method="POST" action="<?php echo e(route('admin.leave-applications.update-status', $application)); ?>" class="d-inline">
                                                                        <?php echo csrf_field(); ?>
                                                                        <?php echo method_field('PATCH'); ?>
                                                                        <input type="hidden" name="status" value="approved">
                                                                        <button type="submit" class="btn btn-sm btn-success" title="Approve"
                                                                                onclick="return confirm('Are you sure you want to approve this application?')">
                                                                            <i class="fas fa-check"></i>
                                                                        </button>
                                                                    </form>

                                                                    <form method="POST" action="<?php echo e(route('admin.leave-applications.update-status', $application)); ?>" class="d-inline">
                                                                        <?php echo csrf_field(); ?>
                                                                        <?php echo method_field('PATCH'); ?>
                                                                        <input type="hidden" name="status" value="rejected">
                                                                        <button type="submit" class="btn btn-sm btn-warning" title="Reject"
                                                                                onclick="return confirm('Are you sure you want to reject this application?')">
                                                                            <i class="fas fa-times"></i>
                                                                        </button>
                                                                    </form>
                                                                <?php endif; ?>

                                                                <form method="POST" action="<?php echo e(route('admin.leave-applications.destroy', $application)); ?>" class="d-inline">
                                                                    <?php echo csrf_field(); ?>
                                                                    <?php echo method_field('DELETE'); ?>
                                                                    <button type="submit" class="btn btn-sm btn-danger" title="Delete"
                                                                            onclick="return confirm('Are you sure you want to delete this application? This action cannot be undone.')">
                                                                        <i class="fas fa-trash"></i>
                                                                    </button>
                                                                </form>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </tbody>
                                        </table>
                                    </div>

                                    <!-- Pagination -->
                                    <div class="d-flex justify-content-center">
                                        <?php echo e($applications->appends(request()->query())->links()); ?>

                                    </div>
                                <?php else: ?>
                                    <div class="text-center py-5">
                                        <i class="fas fa-inbox fa-3x text-gray-300 mb-3"></i>
                                        <h5 class="text-<?php echo e($text); ?>">No applications found</h5>
                                        <p class="text-muted">
                                            <?php if(request('search') || request('status')): ?>
                                                Try adjusting your search criteria or filters.
                                            <?php else: ?>
                                                No leave applications have been submitted yet.
                                            <?php endif; ?>
                                        </p>
                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

<?php if(session('success')): ?>
    <script>
        Swal.fire({
            icon: 'success',
            title: 'Success!',
            text: '<?php echo e(session('success')); ?>',
            confirmButtonColor: '#28a745'
        });
    </script>
<?php endif; ?>

<?php if(session('error')): ?>
    <script>
        Swal.fire({
            icon: 'error',
            title: 'Error!',
            text: '<?php echo e(session('error')); ?>',
            confirmButtonColor: '#dc3545'
        });
    </script>
<?php endif; ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/lpzmfgmrni/usgodefense.com/resources/views/admin/leave-applications/index.blade.php ENDPATH**/ ?>