<x-app-layout>
    <x-slot name="title">Site Surveys & Inquiries</x-slot>
    <div class="mb-6 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
        <div>
            <h1 class="text-2xl font-bold text-gray-900">Site Surveys & Inquiries</h1>
            <p class="text-sm text-gray-500 mt-1">Manage client site visits and structure assessments.</p>
        </div>
        <a href="{{ route('site-surveys.create') }}" class="inline-flex items-center justify-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-lg text-white bg-primary-600 hover:bg-primary-700">
            + New Inquiry / Survey
        </a>
    </div>

    @if(session('success'))
        <div class="mb-4 bg-green-50 p-4 rounded-md border border-green-200">
            <p class="text-green-700 text-sm font-medium">{{ session('success') }}</p>
        </div>
    @endif

    <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
        <div class="overflow-x-auto">
            <table class="min-w-full divide-y divide-gray-200">
                <thead class="bg-gray-50">
                    <tr>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Inquiry No</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Client</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Structure Type</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Site Visit Date</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Status</th>
                        <th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase">Actions</th>
                    </tr>
                </thead>
                <tbody class="bg-white divide-y divide-gray-200">
                    @forelse($surveys as $survey)
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
                                {{ $survey->inquiry_no }}
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
                                {{ $survey->customer_name }}<br>
                                <span class="text-xs text-gray-500">{{ $survey->mobile }}</span>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                {{ $survey->structure_type }}
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                {{ $survey->proposed_visit_date ? $survey->proposed_visit_date->format('d M, Y') : 'Not Scheduled' }}
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm">
                                <span class="px-2 py-1 text-xs font-semibold rounded-full 
                                    {{ $survey->status === 'Completed' ? 'bg-green-100 text-green-800' : 
                                       ($survey->status === 'Scheduled' ? 'bg-blue-100 text-blue-800' : 
                                       ($survey->status === 'Cancelled' ? 'bg-red-100 text-red-800' : 'bg-yellow-100 text-yellow-800')) }}">
                                    {{ $survey->status }}
                                </span>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
                                <a href="{{ route('site-surveys.edit', $survey) }}" class="text-indigo-600 hover:text-indigo-900 mr-3">Manage</a>
                                <form action="{{ route('site-surveys.destroy', $survey) }}" method="POST" class="inline-block" onsubmit="return confirm('Delete this inquiry?');">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="text-red-600 hover:text-red-900">Delete</button>
                                </form>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="6" class="px-6 py-12 text-center text-gray-500">No site surveys found.</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        <div class="px-6 py-4 border-t border-gray-100">
            {{ $surveys->links() }}
        </div>
    </div>
</x-app-layout>
