@extends('layouts.dashboard')



@section('content')

<h2>🚨 Alertas Recibidas</h2>



<table class="table table-bordered bg-white">

    <thead class="table-light">

        <tr>

            <th>Usuario</th>

            <th>Fecha</th>

            <th>Estado</th>

            <th>Ubicación</th>

        </tr>

    </thead>

    <tbody>

        @foreach($alertas as $alerta)

            <tr>

                <td>{{ $alerta->usuario->name }}</td>

                <td>{{ $alerta->created_at->timezone('America/Santiago')->format('d/m/Y H:i') }}</td>

                <td>

                    @if($alerta->estado === 'pendiente')

                        <span class="badge bg-warning text-dark">Pendiente</span>

                    @elseif($alerta->estado === 'atendida')

                        <span class="badge bg-info">Atendida</span>

                    @else

                        <span class="badge bg-success">Resuelta</span>

                    @endif

                </td>

                <td>

                    @if($alerta->latitud && $alerta->longitud)

                        <a href="https://maps.google.com/?q={{ $alerta->latitud }},{{ $alerta->longitud }}" target="_blank">Ver</a>

                    @else

                        —

                    @endif

                </td>

                <td>

                    <a href="{{ route('empresa.alertas.show', $alerta) }}" class="btn btn-sm btn-info">Ver</a>

                </td>

                <td>

                    <form action="{{ route('empresa.alertas.estado', $alerta) }}" method="POST" class="d-inline">

                        @csrf

                        <select name="estado" onchange="this.form.submit()" class="form-select form-select-sm">

                            <option value="pendiente" {{ $alerta->estado === 'pendiente' ? 'selected' : '' }}>Pendiente</option>

                            <option value="atendida" {{ $alerta->estado === 'atendida' ? 'selected' : '' }}>Atendida</option>

                            <option value="resuelta" {{ $alerta->estado === 'resuelta' ? 'selected' : '' }}>Resuelta</option>

                        </select>

                    </form>

                </td>

                <td>

                    <form action="{{ route('empresa.alertas.destroy', $alerta) }}" method="POST" onsubmit="return confirm('¿Eliminar esta alerta?')">

                        @csrf

                        @method('DELETE')

                        <button class="btn btn-sm btn-danger">Eliminar</button>

                    </form>

                </td>

                <td>

                @if($alerta->estado === 'falsa_alarma')

                <span class="badge bg-secondary">Falsa Alarma</span>

                @endif

                </td>

            </tr>

        @endforeach

    </tbody>

</table>



{{ $alertas->links() }}

@endsection

