

<?php $__env->startSection('content'); ?>
    <!--begin::App Content Header-->
    <div class="app-content-header"> <!--begin::Container-->
        <div class="container-fluid">
            <!--begin::Row-->
            <div class="row">
                <div class="col-sm-6">
                    <h3 class="mb-0">Submitted Forms</h3>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-end">
                        <li class="breadcrumb-item"><a href="#">Home</a></li>
                        <li class="breadcrumb-item active" aria-current="page">
                            Submitted Forms
                        </li>
                    </ol>
                </div>
            </div>
            <!--end::Row-->
        </div> <!--end::Container-->
    </div>
    <!--end::App Content Header-->

    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">List of Submitted Forms</h3>
                    <div class="text-end">
                        <?php if(Auth::user()->id_role != 4): ?>
                            <a href="<?php echo e(route('form.show.1', ['id' => 1])); ?>" class="btn btn-success">Create New Form</a>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                                <tr class="text-center" style="vertical-align: middle";>
                                    <th>No</th>
                                    <th>Form ID</th>
                                    <th>Form Name</th>
                                    <th>Submitted By</th>
                                    <th>Submission Date</th>
                                    <th>Status</th>
                                    <?php if(Auth::user()->id_role == 1): ?>
                                        <th>Assigned To</th>
                                    <?php endif; ?>
                                    <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 = 'lightgreen';
                                                        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 class="form-selected" 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>
                                            <div class="text-center" class="btn-group">
                                                <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-warning btn-sm"
                                                        onclick="return confirm('Are you sure you want to reject this form?')">Reject</a>
                                                <?php endif; ?>
                                                <?php if(Auth::user()->id_role != 4): ?>
                                                    <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>
                                                <?php endif; ?>
                                                <a href="<?php echo e(route('form.timeline', $submittedForm->id)); ?>"
                                                    class="btn btn-warning btn-sm">Status</a>
                                            </div>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

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