<div>
    <div class="mb-8">
        <h1 class="text-2xl font-bold text-gray-900">Estimates</h1>
        <p class="text-gray-600">View and manage your service estimates.</p>
    </div>

    <!-- Filters -->
    <div class="bg-white rounded-lg shadow p-6 mb-6">
        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-2">Status</label>
                <select wire:model.live="filterStatus" class="w-full border-gray-300 rounded-md shadow-sm focus:border-blue-500 focus:ring-blue-500">
                    <option value="">All Statuses</option>
                    <option value="draft">Draft</option>
                    <option value="sent">Sent</option>
                    <option value="viewed">Viewed</option>
                    <option value="approved">Approved</option>
                    <option value="rejected">Rejected</option>
                </select>
            </div>
            <div class="flex items-end">
                <button wire:click="$set('filterStatus', '')" 
                        class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50">
                    Clear Filters
                </button>
            </div>
        </div>
    </div>

    <!-- Estimates List -->
    <div class="bg-white rounded-lg shadow overflow-hidden">
        @if($estimates->count() > 0)
            <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 tracking-wider">Estimate #</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Vehicle</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Date</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Amount</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
                        </tr>
                    </thead>
                    <tbody class="bg-white divide-y divide-gray-200">
                        @foreach($estimates as $estimate)
                            <tr class="hover:bg-gray-50">
                                <td class="px-6 py-4 whitespace-nowrap">
                                    <div class="text-sm font-medium text-gray-900">#{{ $estimate->id }}</div>
                                    <div class="text-sm text-gray-500">Job Card #{{ $estimate->job_card_id }}</div>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap">
                                    <div class="text-sm text-gray-900">
                                        {{ $estimate->jobCard->vehicle->year ?? '' }} 
                                        {{ $estimate->jobCard->vehicle->make ?? '' }} 
                                        {{ $estimate->jobCard->vehicle->model ?? '' }}
                                    </div>
                                    <div class="text-sm text-gray-500">{{ $estimate->jobCard->vehicle->license_plate ?? '' }}</div>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap">
                                    <div class="text-sm text-gray-900">{{ $estimate->created_at->format('M j, Y') }}</div>
                                    <div class="text-sm text-gray-500">{{ $estimate->created_at->format('g:i A') }}</div>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap">
                                    <div class="text-sm font-medium text-gray-900">${{ number_format($estimate->total_amount, 2) }}</div>
                                    @if($estimate->subtotal_amount != $estimate->total_amount)
                                        <div class="text-sm text-gray-500">
                                            Subtotal: ${{ number_format($estimate->subtotal_amount, 2) }}
                                            @if($estimate->tax_amount > 0)
                                                + Tax: ${{ number_format($estimate->tax_amount, 2) }}
                                            @endif
                                        </div>
                                    @endif
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap">
                                    <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium
                                        @switch($estimate->status)
                                            @case('approved')
                                                bg-green-100 text-green-800
                                                @break
                                            @case('rejected')
                                                bg-red-100 text-red-800
                                                @break
                                            @case('sent')
                                            @case('viewed')
                                                bg-yellow-100 text-yellow-800
                                                @break
                                            @case('draft')
                                                bg-gray-100 text-gray-800
                                                @break
                                            @default
                                                bg-gray-100 text-gray-800
                                        @endswitch
                                    ">
                                        {{ ucfirst($estimate->status) }}
                                    </span>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                                    <span class="text-blue-600">View Details</span>
                                    @if(in_array($estimate->status, ['sent', 'viewed']))
                                        <span class="text-gray-300 mx-2">|</span>
                                        <span class="text-orange-600 font-medium">Action Required</span>
                                    @endif
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>

            @if($estimates->hasPages())
                <div class="px-6 py-3 border-t border-gray-200">
                    {{ $estimates->links() }}
                </div>
            @endif
        @else
            <div class="text-center py-12">
                <svg class="mx-auto h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
                </svg>
                <h3 class="mt-2 text-sm font-medium text-gray-900">No estimates found</h3>
                <p class="mt-1 text-sm text-gray-500">
                    @if($filterStatus)
                        Try adjusting your filters or contact us about your vehicle service.
                    @else
                        You don't have any estimates yet. Contact us to schedule a service.
                    @endif
                </p>
            </div>
        @endif
    </div>
</div>
