

<?php $__env->startSection('content'); ?>
    <div class="bg-white shadow rounded p-6">
        <div class="flex justify-between items-center mb-4">
            <h2 class="text-2xl font-bold">Contact Submissions</h2>
        </div>
<button onclick="exportCleanExcel('contacts-table', 'contact_submissions')" 
    class="bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700 text-sm font-semibold shadow">
    <i class="fas fa-file-excel mr-2"></i> Export Excel
</button>

        <table id="contacts-table" class="min-w-full divide-y divide-gray-200">
            <thead class="bg-gray-100">
                <tr>
                    <th class="px-6 py-3 text-left text-sm font-medium">#</th>
                    <th class="px-6 py-3 text-left text-sm font-medium">Name</th>
                    <th class="px-6 py-3 text-left text-sm font-medium">Email</th>
                    <th class="px-6 py-3 text-left text-sm font-medium">Phone</th>
                    <th class="px-6 py-3 text-left text-sm font-medium">Property Name / Visit Page</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-100">
                <?php $__empty_1 = true; $__currentLoopData = $contacts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $contact): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td class="px-6 py-4"><?php echo e($loop->iteration + ($contacts->currentPage() - 1) * $contacts->perPage()); ?></td>
                        <td class="px-6 py-4"><?php echo e($contact->name); ?></td>
                        <td class="px-6 py-4"><?php echo e($contact->email); ?></td>
                        <td class="px-6 py-4"><?php echo e($contact->number); ?></td>
                        <td class="px-6 py-4">
                            <?php if(!$contact->matched_property): ?>
                                <span class="flex items-center text-yellow-600 font-medium">
                                    <i class="fas fa-phone text-yellow-500 mr-2"></i>
                                    <?php echo e($contact->property_name ?? 'General Inquiry'); ?>

                                </span>
                            <?php else: ?>
                                <span class="flex items-center text-green-600 font-medium hover:underline">
                                    <i class="fas fa-building text-green-500 mr-2"></i>
                                    <?php echo e($contact->matched_property->property_name); ?>

                                </span>
                            <?php endif; ?>
                        </td>

                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td colspan="6" class="px-6 py-4 text-center text-gray-500">No contact submissions found.</td>
                    </tr>
                <?php endif; ?>
            </tbody>
        </table>

        <!-- Tailwind Pagination -->
        <div class="mt-6">
            <?php echo e($contacts->links('vendor.pagination.tailwind')); ?>

        </div>
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
    <script>
function exportCleanExcel(tableID, filename = '') {
    const table = document.getElementById(tableID);
    const rows = Array.from(table.querySelectorAll('tr'));
    let csv = [];

    rows.forEach(row => {
        let rowData = [];
        row.querySelectorAll('th, td').forEach(cell => {
            // Get only text content, trim spaces
            const text = cell.innerText.trim().replace(/\n/g, ' ');
            rowData.push(`"${text}"`);
        });
        csv.push(rowData.join(','));
    });

    // Convert CSV array to string
    const csvString = csv.join('\n');
    const blob = new Blob([csvString], { type: 'text/csv;charset=utf-8;' });

    // Create download link
    const link = document.createElement("a");
    const url = URL.createObjectURL(blob);
    link.setAttribute("href", url);
    link.setAttribute("download", filename + ".csv");
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
}
</script>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH E:\Sw_arif\New folder\realState\resources\views/backend/admin/lead.blade.php ENDPATH**/ ?>