<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Averías') }}
        </h2>
    </x-slot>
    
    <h1>{{ $test }}</h1>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="overflow-x-auto py-4">
                <table class="min-w-full table-auto border-collapse">
                    <thead>
                        <tr>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Direcció</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">Ciutat</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Telefon</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Google Maps</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 ($faults as $fault)
        <tr>
            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{{ $fault->id }}</td>
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ $fault->contact_name }}</td>
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->address }}</td>
            <td class="px-6 py-4 whitespace-nowrap text-sm  font-bold " style="background: {{ $colors[$fault->status] ?? 'white' }};">
  {{ $fault->status  }}
</td>            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->city }}</td>
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->contact_phone }}</td>
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->google_maps_link }}</td>

            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                <a href="{{ route('dashboard.openModal', $fault->id) }}" class="text-indigo-600 hover:text-indigo-900">Edit</a>
                <button class="text-red-600 hover:text-red-900 ml-4">Delete</button>
            </td>
        </tr>
    @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    </div>

<!-- Modal -->
<!-- Modal -->
@if($isModalOpen)
    <div class="fixed inset-0 flex justify-center items-center bg-slate-200 bg-opacity-90 ">
    <form action="{{ route('dashboard.updateStatus', $modalData->id) }}" method="POST">
                    @csrf
                    @method('PATCH')
        <div class="bg-white p-6 rounded-lg flex flex-col justify-center gap-3">
            <h3 class="text-xl">Fault Details</h3>
            <div class="border-t border-gray-300 my-4"></div>
         
            <p>ID: {{ $modalData->id }}</p>
            <p>Name: {{ $modalData->contact_name }}</p>
            <p>Address: {{ $modalData->address }}</p>
            <div class="flex justify-around items-center gap-2">
            <p>Status:</p>
                <select name="status" class="border-gray-300 rounded-md p-0"  >
                    <option class="mx-6" value="open"  {{ $modalData->status == 'open' ? 'selected' : '' }}>Open</option>
                    <option class="mx-6"  value="in_progress" {{ $modalData->status == 'in_progress' ? 'selected' : '' }}>In Progress</option>
                    <option class="mx-6"  value="resolved" {{ $modalData->status == 'resolved' ? 'selected' : '' }}>Resolved</option>
                </select>
            
            </div>
         
            <p>City: {{ $modalData->city }}</p>
            <p>Phone: {{ $modalData->contact_phone }}</p>
            <p>Google Maps: <a href="{{ $modalData->google_maps_link }}" target="_blank">{{ $modalData->google_maps_link }}</a></p>


            <div class="border-t border-gray-300 my-4"></div>
            <div 
            class="flex justify-between items-center mt-4"
            >
          <a href="{{ route('dashboard.closeModal') }}" class="text-red-600 hover:text-red-900">Close</a>
          <button type="submit" class="text-blue-500 hover:text-blue-700">Update Status</button>

            </div>
  
        </div>
        </form>
    </div>
@endif


</x-app-layout>
