

<?php $__env->startSection('content'); ?>
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>Submitted Forms</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="#">Home</a></li>
                        <li class="breadcrumb-item active">Submitted Forms</li>
                    </ol>
                </div>
            </div>
        </div>
    </section>

    <section class="content">
        <div class="container-fluid">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">List of Submitted Forms</h3>
                </div>
                <div class="card-body">
                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th>No</th>
                                <th>Form ID</th>
                                <th>Form Name</th>
                                <th>Submitted By</th>
                                <th>Submission Date</th>
                                <th>Status</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__currentLoopData = $submittedForms; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $submittedForm): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td><?php echo e($loop->iteration); ?></td>
                                    <td><?php echo e($submittedForm->form->id); ?></td>
                                    <td><?php echo e($submittedForm->form->title); ?></td>
                                    <td><?php echo e($submittedForm->login->username ?? 'Unknown User'); ?></td>
                                    <td><?php echo e($submittedForm->created_at->format('d M Y, h:i A')); ?></td>
                                    <td>
                                        <?php
                                            $status = $submittedForm->form_status->title ?? 'Unknown';
                                            $color = 'gray'; // Default color
                                            switch ($status) {
                                                case 'Submitted':
                                                    $color = 'yellow';
                                                    break;
                                                case 'Verified':
                                                    $color = 'green';
                                                    break;
                                                case 'Rejected':
                                                    $color = 'red';
                                                    break;
                                            }
                                        ?>
                                        <span class="badge" style="background-color: <?php echo e($color); ?>; color: white;">
                                            <?php echo e($status); ?>

                                        </span>
                                    </td>
                                    <?php if(auth()->user()->id_role === 1): ?>
                                        <td>
                                            <form action="<?php echo e(route('form.assign', $submittedForm->id)); ?>" method="POST">
                                                <?php echo csrf_field(); ?>
                                                <select name="assigned_to" class="form-control form-control-sm" onchange="this.form.submit()">
                                                    <option value="">Unassigned</option>
                                                    <?php $__currentLoopData = $officers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $officer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <option value="<?php echo e($officer->id); ?>" <?php echo e($submittedForm->assigned_to === $officer->id ? 'selected' : ''); ?>>
                                                            <?php echo e($officer->username); ?>

                                                        </option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </select>
                                            </form>
                                        </td>
                                    <?php endif; ?>
                                    <td>
                                        <a href="<?php echo e(route('form.view', $submittedForm->id)); ?>"
                                            class="btn btn-primary btn-sm">View</a>

                                        <?php if($status === 'Submitted' && auth()->user()->id_role === 4): ?>
                                            <!-- Verify Button -->
                                            <a href="<?php echo e(route('form.verify', $submittedForm->id)); ?>"
                                                class="btn btn-success btn-sm"
                                                onclick="return confirm('Are you sure you want to verify this form?')">Verify</a>

                                            <!-- Reject Button -->
                                            <a href="<?php echo e(route('form.reject', $submittedForm->id)); ?>"
                                                class="btn btn-danger btn-sm"
                                                onclick="return confirm('Are you sure you want to reject this form?')">Reject</a>
                                        <?php endif; ?>

                                        <a href="<?php echo e(route('form.delete', $submittedForm->id)); ?>"
                                            class="btn btn-danger btn-sm"
                                            onclick="return confirm('Are you sure you want to delete this form?')">Delete</a>
                                        <a href="<?php echo e(route('form.timeline', $submittedForm->id)); ?>"
                                            class="btn btn-warning btn-sm">Status</a>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                </div>
                <div class="card-footer">
                    <a href="<?php echo e(route('form.show.1', ['id' => 1])); ?>" class="btn btn-success">Create New Form</a>
                </div>
            </div>
        </div>
    </section>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\laragon\www\VPS_changes\resources\views/form/form-index.blade.php ENDPATH**/ ?>