




<?php $__env->startSection('admin'); ?>
<div class="flex flex-col h-full overflow-auto">
    <!-- Header -->
    <div class="flex justify-between items-center mb-6">
        <div>
            <h1 class="text-2xl font-bold text-gray-900 dark:text-white">Service Requests</h1>
            <p class="text-sm text-gray-500 dark:text-gray-400 mt-1">Manage all service requests from users</p>
        </div>
        <div class="flex items-center space-x-4">
            <div class="relative">
                <input type="text" placeholder="Search requests..." 
                       class="pl-10 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-[#10B981] focus:border-[#10B981] transition-colors w-64 bg-white dark:bg-gray-800 text-gray-900 dark:text-white"
                       id="searchInput">
                <i class="fas fa-search absolute left-3 top-3 text-gray-400"></i>
            </div>
        </div>
    </div>

    <!-- Success/Error Messages -->
    <?php if(session('success')): ?>
        <div class="bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 text-green-700 dark:text-green-300 px-4 py-3 rounded-lg mb-6 flex items-center justify-between">
            <div class="flex items-center">
                <i class="fas fa-check-circle mr-2"></i>
                <?php echo e(session('success')); ?>

            </div>
            <button type="button" class="text-green-700 dark:text-green-300 hover:text-green-900 dark:hover:text-green-100" onclick="this.parentElement.remove()">
                <i class="fas fa-times"></i>
            </button>
        </div>
    <?php endif; ?>

    <?php if(session('error')): ?>
        <div class="bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 text-red-700 dark:text-red-300 px-4 py-3 rounded-lg mb-6 flex items-center justify-between">
            <div class="flex items-center">
                <i class="fas fa-exclamation-circle mr-2"></i>
                <?php echo e(session('error')); ?>

            </div>
            <button type="button" class="text-red-700 dark:text-red-300 hover:text-red-900 dark:hover:text-red-100" onclick="this.parentElement.remove()">
                <i class="fas fa-times"></i>
            </button>
        </div>
    <?php endif; ?>

    <!-- Service Requests Table -->
    <div class="bg-white dark:bg-dark-secondary rounded-2xl shadow-sm border border-gray-100 dark:border-gray-700 overflow-hidden flex-1 flex flex-col">
        <div class="px-6 py-4 border-b border-gray-100 dark:border-gray-700 flex justify-between items-center">
            <h2 class="text-lg font-semibold text-gray-800 dark:text-white">All Service Requests</h2>
            <div class="flex items-center space-x-4">
                <div class="flex space-x-2">
                    <button class="text-gray-500 dark:text-gray-400 hover:text-[#10B981] p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700" id="filterBtn">
                        <i class="fas fa-filter"></i>
                    </button>
                </div>
            </div>
        </div>
        
        <div class="flex-1 overflow-auto">
            <table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
                <thead class="bg-gray-50 dark:bg-gray-800">
                    <tr>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Request Info</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Business Details</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Package</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Price</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Status</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Created</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider w-40">Actions</th>
                    </tr>
                </thead>
                <tbody class="bg-white dark:bg-dark-secondary divide-y divide-gray-200 dark:divide-gray-700" id="requestsTable">
                    <?php $__empty_1 = true; $__currentLoopData = $serviceRequests; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $request): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <?php
                            $contactInfo = $request->contact_info;
                            $servicesData = $request->services_data;
                        ?>
                        <tr class="hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors" data-request-id="<?php echo e($request->id); ?>">
                            <td class="px-6 py-4 whitespace-nowrap">
                                <div class="flex items-center">
                                    <div class="w-10 h-10 bg-gradient-to-br from-blue-100 to-blue-200 dark:from-blue-900/20 dark:to-blue-800/20 rounded-lg flex items-center justify-center mr-3">
                                        <i class="fas fa-file-alt text-blue-500 dark:text-blue-400"></i>
                                    </div>
                                    <div>
                                        <div class="text-sm font-medium text-gray-900 dark:text-white">
                                            <?php echo e($contactInfo['name'] ?? 'N/A'); ?>

                                        </div>
                                        <div class="text-xs text-gray-500 dark:text-gray-400">
                                            <?php echo e($contactInfo['email'] ?? 'N/A'); ?>

                                        </div>
                                        <div class="text-xs text-gray-400 dark:text-gray-500">
                                            ID: <?php echo e($request->id); ?>

                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="px-6 py-4">
                                <div class="text-sm text-gray-900 dark:text-white">
                                    <div class="font-medium"><?php echo e($request->businessType->name ?? 'N/A'); ?></div>
                                    <div class="text-xs text-gray-500 dark:text-gray-400">
                                        <?php echo e($request->businessModel->name ?? 'N/A'); ?> • <?php echo e($request->branch->name ?? 'N/A'); ?>

                                    </div>
                                </div>
                            </td>
                            <td class="px-6 py-4">
                                <div class="text-sm text-gray-900 dark:text-white">
                                    <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-purple-100 dark:bg-purple-900/30 text-purple-800 dark:text-purple-300 border border-purple-200 dark:border-purple-800 capitalize">
                                        <?php echo e($request->package_type); ?>

                                    </span>
                                    <div class="text-xs text-gray-500 dark:text-gray-400 mt-1">
                                        <?php echo e(count($servicesData ?? [])); ?> services
                                    </div>
                                </div>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <div class="text-sm font-semibold text-gray-900 dark:text-white">
                                    <?php echo e(number_format($request->total_price, 2)); ?> SR
                                </div>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <?php
                                    $statusColors = [
                                        'pending' => 'bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-300 border-yellow-200 dark:border-yellow-800',
                                        'in_progress' => 'bg-blue-100 dark:bg-blue-900/30 text-blue-800 dark:text-blue-300 border-blue-200 dark:border-blue-800',
                                        'approved' => 'bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-300 border-green-200 dark:border-green-800',
                                        'cancelled' => 'bg-red-100 dark:bg-red-900/30 text-red-800 dark:text-red-300 border-red-200 dark:border-red-800'
                                    ];
                                    $statusIcons = [
                                        'pending' => 'fa-clock',
                                        'in_progress' => 'fa-spinner',
                                        'approved' => 'fa-check-circle',
                                        'cancelled' => 'fa-times-circle'
                                    ];
                                    $statusLabels = [
                                        'pending' => 'Pending',
                                        'in_progress' => 'In Progress',
                                        'approved' => 'Approved',
                                        'cancelled' => 'Cancelled'
                                    ];
                                ?>
                                <span class="px-3 py-1 inline-flex text-xs leading-5 font-semibold rounded-full <?php echo e($statusColors[$request->status]); ?> border">
                                    <i class="fas <?php echo e($statusIcons[$request->status]); ?> mr-1"></i>
                                    <?php echo e($statusLabels[$request->status]); ?>

                                </span>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
                                <div class="flex items-center">
                                    <i class="fas fa-calendar-alt mr-2 text-gray-400"></i>
                                    <?php echo e($request->created_at->format('M j, Y')); ?>

                                </div>
                                <div class="text-xs text-gray-400 dark:text-gray-500">
                                    <?php echo e($request->created_at->format('g:i A')); ?>

                                </div>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <div class="flex items-center justify-start space-x-2">
                                    <!-- View Button -->
                                    <a href="<?php echo e(route('admin.service-requests.show', $request)); ?>" 
                                       class="inline-flex items-center justify-center w-9 h-9 bg-blue-50 dark:bg-blue-900/20 text-blue-500 dark:text-blue-400 rounded-lg hover:bg-blue-100 dark:hover:bg-blue-900/30 transition-colors border border-blue-200 dark:border-blue-800"
                                       title="View Details">
                                        <i class="fas fa-eye text-xs"></i>
                                    </a>
                                    
                                    <!-- Edit Button -->
                                    <a href="<?php echo e(route('admin.service-requests.edit', $request)); ?>" 
                                       class="inline-flex items-center justify-center w-9 h-9 bg-green-50 dark:bg-green-900/20 text-[#10B981] rounded-lg hover:bg-green-100 dark:hover:bg-green-900/30 transition-colors border border-green-200 dark:border-green-800"
                                       title="Edit Request">
                                        <i class="fas fa-edit text-xs"></i>
                                    </a>

                                    <!-- Status Dropdown -->
                                    <div class="relative">
                                        <button class="inline-flex items-center justify-center w-9 h-9 bg-purple-50 dark:bg-purple-900/20 text-purple-500 dark:text-purple-400 rounded-lg hover:bg-purple-100 dark:hover:bg-purple-900/30 transition-colors border border-purple-200 dark:border-purple-800 status-dropdown-btn"
                                                title="Change Status"
                                                data-request-id="<?php echo e($request->id); ?>">
                                            <i class="fas fa-sync-alt text-xs"></i>
                                        </button>
                                        
                                        <!-- Status Dropdown Menu -->
                                        <div class="absolute right-0 mt-1 w-40 bg-white dark:bg-gray-800 rounded-lg shadow-lg border border-gray-200 dark:border-gray-700 z-10 hidden status-dropdown-menu">
                                            <form method="POST" action="<?php echo e(route('admin.service-requests.update-status', $request)); ?>" class="p-2 space-y-1">
                                                <?php echo csrf_field(); ?>
                                                <?php $__currentLoopData = ['pending', 'in_progress', 'approved', 'cancelled']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <button type="submit" 
                                                            name="status" 
                                                            value="<?php echo e($status); ?>"
                                                            class="w-full text-left px-3 py-2 text-sm rounded-md hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors flex items-center justify-between <?php echo e($request->status === $status ? 'bg-gray-100 dark:bg-gray-700' : ''); ?>">
                                                        <span><?php echo e(ucfirst(str_replace('_', ' ', $status))); ?></span>
                                                        <?php if($request->status === $status): ?>
                                                            <i class="fas fa-check text-green-500"></i>
                                                        <?php endif; ?>
                                                    </button>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </form>
                                        </div>
                                    </div>

                                    <!-- Delete Button -->
                                    <button type="button" 
                                            class="inline-flex items-center justify-center w-9 h-9 bg-red-50 dark:bg-red-900/20 text-red-500 dark:text-red-400 rounded-lg hover:bg-red-100 dark:hover:bg-red-900/30 transition-colors border border-red-200 dark:border-red-800 delete-request-btn"
                                            data-request-id="<?php echo e($request->id); ?>"
                                            data-request-name="<?php echo e($contactInfo['name'] ?? 'Request'); ?>"
                                            title="Delete Request">
                                        <i class="fas fa-trash text-xs"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="7" class="px-6 py-8 text-center">
                                <div class="flex flex-col items-center justify-center text-gray-400 dark:text-gray-500">
                                    <i class="fas fa-file-alt text-4xl mb-3"></i>
                                    <p class="text-lg font-medium text-gray-500 dark:text-gray-400">No service requests found</p>
                                    <p class="text-sm text-gray-400 dark:text-gray-500 mt-1">All service requests will appear here</p>
                                </div>
                            </td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>

        <!-- Pagination -->
        <?php if($serviceRequests->hasPages()): ?>
            <div class="px-6 py-4 border-t border-gray-100 dark:border-gray-700">
                <?php echo e($serviceRequests->links()); ?>

            </div>
        <?php endif; ?>
    </div>
</div>

<!-- Delete Confirmation Modal -->
<div id="deleteModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
    <div class="bg-white dark:bg-dark-secondary rounded-2xl shadow-xl max-w-md w-full mx-4 transform transition-all">
        <div class="p-6">
            <!-- Modal Header -->
            <div class="flex items-center justify-between mb-4">
                <div class="flex items-center">
                    <div class="w-10 h-10 bg-red-100 dark:bg-red-900/20 rounded-lg flex items-center justify-center mr-3">
                        <i class="fas fa-exclamation-triangle text-red-500 dark:text-red-400"></i>
                    </div>
                    <h3 class="text-lg font-semibold text-gray-900 dark:text-white">Confirm Deletion</h3>
                </div>
                <button type="button" class="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors" onclick="closeModal()">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            
            <!-- Modal Body -->
            <div class="mb-6">
                <p class="text-gray-600 dark:text-gray-300">
                    Are you sure you want to delete service request from 
                    <span id="requestName" class="font-semibold text-gray-900 dark:text-white"></span>?
                </p>
                <p class="text-sm text-red-500 dark:text-red-400 mt-2 flex items-center">
                    <i class="fas fa-info-circle mr-1"></i>
                    This action cannot be undone.
                </p>
            </div>
            
            <!-- Modal Footer -->
            <div class="flex justify-end space-x-3">
                <button type="button" 
                        class="px-4 py-2 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors"
                        onclick="closeModal()">
                    Cancel
                </button>
                <form id="deleteForm" method="POST" class="inline">
                    <?php echo csrf_field(); ?>
                    <?php echo method_field('DELETE'); ?>
                    <button type="submit" 
                            class="px-4 py-2 bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center">
                        <i class="fas fa-trash mr-2"></i>
                        Delete Request
                    </button>
                </form>
            </div>
        </div>
    </div>
</div>

<style>
    .pagination {
        display: flex;
        justify-content: center;
        list-style: none;
        padding: 0;
    }
    
    .pagination li {
        margin: 0 2px;
    }
    
    .pagination li a,
    .pagination li span {
        display: block;
        padding: 8px 12px;
        border: 1px solid #e5e7eb;
        border-radius: 6px;
        color: #6b7280;
        text-decoration: none;
        transition: all 0.2s;
    }
    
    .pagination li a:hover {
        background-color: #f9fafb;
        border-color: #d1d5db;
    }
    
    .pagination li.active span {
        background-color: #10B981;
        border-color: #10B981;
        color: white;
    }
    
    .pagination li.disabled span {
        color: #9ca3af;
        background-color: #f9fafb;
    }

    /* Dark mode pagination styles */
    .dark .pagination li a,
    .dark .pagination li span {
        border: 1px solid #374151;
        color: #9ca3af;
        background-color: #1f2937;
    }

    .dark .pagination li a:hover {
        background-color: #374151;
        border-color: #4b5563;
    }

    .dark .pagination li.active span {
        background-color: #10B981;
        border-color: #10B981;
        color: white;
    }

    .dark .pagination li.disabled span {
        color: #6b7280;
        background-color: #374151;
    }

    /* Modal Animation */
    #deleteModal {
        transition: opacity 0.3s ease;
    }

    #deleteModal > div {
        transition: transform 0.3s ease;
    }

    #deleteModal.hidden {
        opacity: 0;
        pointer-events: none;
    }

    #deleteModal:not(.hidden) > div {
        transform: scale(1);
    }

    /* Status dropdown styles */
    .status-dropdown-menu {
        min-width: 160px;
    }
</style>

<script>
    // Delete Request Modal Functions
    function openModal(requestId, requestName) {
        const modal = document.getElementById('deleteModal');
        const requestNameElement = document.getElementById('requestName');
        const deleteForm = document.getElementById('deleteForm');
        
        // Set request name in modal
        requestNameElement.textContent = requestName;
        
        // Set form action
        deleteForm.action = `/admin/panel/service-requests/${requestId}`;
        
        // Show modal
        modal.classList.remove('hidden');
        document.body.style.overflow = 'hidden';
    }

    function closeModal() {
        const modal = document.getElementById('deleteModal');
        modal.classList.add('hidden');
        document.body.style.overflow = 'auto';
    }

    // Event Listeners
    document.addEventListener('DOMContentLoaded', function() {
        // Delete button click handlers
        document.querySelectorAll('.delete-request-btn').forEach(button => {
            button.addEventListener('click', function() {
                const requestId = this.getAttribute('data-request-id');
                const requestName = this.getAttribute('data-request-name');
                openModal(requestId, requestName);
            });
        });

        // Status dropdown functionality
        document.querySelectorAll('.status-dropdown-btn').forEach(button => {
            button.addEventListener('click', function(e) {
                e.stopPropagation();
                const dropdownMenu = this.nextElementSibling;
                const isHidden = dropdownMenu.classList.contains('hidden');
                
                // Close all other dropdowns
                document.querySelectorAll('.status-dropdown-menu').forEach(menu => {
                    menu.classList.add('hidden');
                });
                
                // Toggle current dropdown
                if (isHidden) {
                    dropdownMenu.classList.remove('hidden');
                } else {
                    dropdownMenu.classList.add('hidden');
                }
            });
        });

        // Close dropdowns when clicking outside
        document.addEventListener('click', function() {
            document.querySelectorAll('.status-dropdown-menu').forEach(menu => {
                menu.classList.add('hidden');
            });
        });

        // Close modal when clicking outside
        document.getElementById('deleteModal').addEventListener('click', function(e) {
            if (e.target === this) {
                closeModal();
            }
        });

        // Close modal with Escape key
        document.addEventListener('keydown', function(e) {
            if (e.key === 'Escape') {
                closeModal();
            }
        });

        // Search functionality
        const searchInput = document.getElementById('searchInput');
        if (searchInput) {
            searchInput.addEventListener('input', function(e) {
                const searchTerm = e.target.value.toLowerCase();
                const rows = document.querySelectorAll('#requestsTable tr');
                
                rows.forEach(row => {
                    const rowText = row.textContent.toLowerCase();
                    if (rowText.includes(searchTerm)) {
                        row.style.display = '';
                    } else {
                        row.style.display = 'none';
                    }
                });
            });
        }
    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layout.main', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\crm_new\resources\views/admin/service-requests/index.blade.php ENDPATH**/ ?>