<?php if (isset($component)) { $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54 = $attributes; } ?>
<?php $component = App\View\Components\AppLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('app-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AppLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
    <?php
        $statusBadge = fn($s) => match($s) {
            'pending'     => 'bg-warning text-dark',
            'in_progress' => 'bg-primary',
            'completed'   => 'bg-success',
            'approved'    => 'bg-success',
            'rejected'    => 'bg-danger',
            default       => 'bg-secondary',
        };
    ?>

    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h3 fw-bold mb-0">Approval Requests</h1>
        <a href="<?php echo e(route('tokens.create')); ?>" class="btn btn-primary">
            <i class="bi bi-plus-lg me-1"></i>New Request
        </a>
    </div>

    <!-- Filter Tabs -->
    <ul class="nav nav-pills mb-4 gap-1">
        <li class="nav-item">
            <a href="<?php echo e(route('tokens.index', ['filter' => 'all'])); ?>"
               class="nav-link <?php echo e($filter === 'all' ? 'active' : 'text-secondary'); ?>">All Requests</a>
        </li>
        <li class="nav-item">
            <a href="<?php echo e(route('tokens.index', ['filter' => 'my-requests'])); ?>"
               class="nav-link <?php echo e($filter === 'my-requests' ? 'active' : 'text-secondary'); ?>">My Requests</a>
        </li>
        <li class="nav-item">
            <a href="<?php echo e(route('tokens.index', ['filter' => 'pending-approval'])); ?>"
               class="nav-link <?php echo e($filter === 'pending-approval' ? 'active' : 'text-secondary'); ?>">Pending My Approval</a>
        </li>
    </ul>

    <div class="card shadow-sm border-0">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table id="tokensTable" class="table table-hover align-middle mb-0">
                    <thead class="table-dark">
                        <tr>
                            <th>Title</th>
                            <th>Category</th>
                            <th>Status</th>
                            <th>Current Stage</th>
                            <th>Created</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $tokens; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $token): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td class="fw-medium"><?php echo e($token->title); ?></td>
                                <td class="text-muted"><?php echo e($token->category->name); ?></td>
                                <td>
                                    <span class="badge <?php echo e($statusBadge($token->status)); ?>">
                                        <?php echo e(ucfirst(str_replace('_', ' ', $token->status))); ?>

                                    </span>
                                </td>
                                <td class="text-muted small">
                                    <?php if($token->status === 'in_progress'): ?>
                                        <?php
                                            $stage = $token->category->categoryStages->where('stage_order', $token->current_stage)->first();
                                        ?>
                                        <?php echo e($stage ? $stage->department->name . ' — ' . ($stage->role ?? $stage->designation) : 'N/A'); ?>

                                    <?php else: ?>
                                        <span class="text-muted">—</span>
                                    <?php endif; ?>
                                </td>
                                <td class="text-muted small"><?php echo e($token->created_at->format('M d, Y')); ?></td>
                                <td>
                                    <div class="d-flex gap-1 flex-wrap">
                                        <a href="<?php echo e(route('tokens.show', $token)); ?>"
                                           class="btn btn-outline-primary btn-sm">
                                            <i class="bi bi-eye me-1"></i>View
                                        </a>
                                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('approve', $token)): ?>
                                            <form action="<?php echo e(route('tokens.approve', $token)); ?>" method="POST" class="d-inline"
                                                  onsubmit="return confirm('Approve this request?')">
                                                <?php echo csrf_field(); ?>
                                                <button type="submit" class="btn btn-success btn-sm">
                                                    <i class="bi bi-check-lg me-1"></i>Approve
                                                </button>
                                            </form>
                                            <a href="<?php echo e(route('tokens.show', $token)); ?>#decline"
                                               class="btn btn-danger btn-sm">
                                                <i class="bi bi-x-lg me-1"></i>Decline
                                            </a>
                                        <?php endif; ?>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <?php $__env->startPush('styles'); ?>
        <link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css">
    <?php $__env->stopPush(); ?>

    <?php $__env->startPush('scripts'); ?>
        <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
        <script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>
        <script>
            $(document).ready(() => $('#tokensTable').DataTable({ order: [[4, 'desc']] }));
        </script>
    <?php $__env->stopPush(); ?>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $attributes = $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $component = $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?><?php /**PATH D:\My Works\approval\resources\views/tokens/index.blade.php ENDPATH**/ ?>