@extends('layouts.app')

@section('title', 'Proyectos')

@section('content')
<div class="max-w-7xl mx-auto py-10 sm:px-6 lg:px-8">

    <div class="flex justify-between items-center mb-6">
        <h2 class="text-2xl font-semibold text-gray-800">Proyectos</h2>
        <a href="{{ route('projects.create') }}" class="inline-flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white text-sm font-semibold rounded-lg shadow-md hover:bg-indigo-700 transition duration-150">
            <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
            </svg>
            Nuevo Proyecto
        </a>


    </div>

    @if (session('success'))
        <div class="mb-4 p-4 bg-green-100 text-green-800 rounded">
            {{ session('success') }}
        </div>
    @endif

    @if ($projects->count())
    <div class="overflow-x-auto bg-white rounded shadow">
        <table class="min-w-full divide-y divide-gray-200 text-sm">
            <thead class="bg-gray-50">
                <tr>
                    <th class="px-4 py-2 text-left font-medium text-gray-500 uppercase">Imagen</th>
                    <th class="px-4 py-2 text-left font-medium text-gray-500 uppercase">Nombre</th>
                    <th class="px-4 py-2 text-left font-medium text-gray-500 uppercase">Descripción</th>
                    <th class="px-4 py-2 text-left font-medium text-gray-500 uppercase">Ubicación</th>
                    <th class="px-4 py-2 text-left font-medium text-gray-500 uppercase">Acciones</th>
                </tr>

            </thead>
            <tbody class="divide-y divide-gray-200">
                @foreach ($projects as $project)
                <tr>
                    <td class="px-4 py-2">
                        @if($project->image)
                            <img src="{{ asset('storage/' . $project->image->path) }}"
                                alt="{{ $project->image->alt }}"
                                class="w-14 h-14 object-cover rounded border">
                        @else
                            <span class="text-xs text-gray-400">Sin imagen</span>
                        @endif
                    </td>

                    <td class="px-4 py-2">{{ $project->name }}</td>
                    <td class="px-4 py-2">{{ $project->description }}</td>
                    <td class="px-4 py-2">{{ $project->location }}</td>
                    <td class="px-4 py-2 flex gap-2">

                            {{-- Ver --}}
                            <a href="{{ route('projects.show', $project) }}"
                            class="inline-flex items-center gap-1 px-3 py-1 bg-gray-200 text-gray-700 rounded hover:bg-gray-300 text-sm font-medium transition">
                                <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4" fill="none" viewBox="0 0 24 24"
                                    stroke="currentColor" stroke-width="1.5">
                                    <path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
                                    <path stroke-linecap="round" stroke-linejoin="round"
                                        d="M2.458 12C3.732 7.943 7.523 5 12 5c4.477 0 8.268 2.943 9.542 7-1.274 4.057-5.065 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
                                </svg>
                                Ver
                            </a>

                            {{-- Editar --}}
                            <a href="{{ route('projects.edit', $project) }}"
                            class="inline-flex items-center gap-1 px-3 py-1 bg-blue-600 text-white rounded hover:bg-blue-700 text-sm font-medium transition">
                                <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4" fill="none" viewBox="0 0 24 24"
                                    stroke="currentColor" stroke-width="1.5">
                                    <path stroke-linecap="round" stroke-linejoin="round"
                                        d="M16.862 4.487a2.1 2.1 0 113.02 2.92L6.578 20.71l-3.712.793.793-3.713L16.862 4.487z" />
                                </svg>
                                Editar
                            </a>

                            {{-- Eliminar --}}
                            <form action="{{ route('projects.destroy', $project) }}" method="POST" onsubmit="return confirm('¿Eliminar este proyecto?')">
                                @csrf
                                @method('DELETE')
                                <button type="submit"
                                        class="inline-flex items-center gap-1 px-3 py-1 bg-red-600 text-white rounded hover:bg-red-700 text-sm font-medium transition">
                                    <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4" fill="none" viewBox="0 0 24 24"
                                        stroke="currentColor" stroke-width="1.5">
                                        <path stroke-linecap="round" stroke-linejoin="round"
                                            d="M6 18L18 6M6 6l12 12" />
                                    </svg>
                                    Eliminar
                                </button>
                            </form>
                        </td>


                </tr>
                @endforeach
            </tbody>
        </table>
    </div>

    <div class="mt-4">
        {{ $projects->links() }}
    </div>
    @else
        <div class="p-4 bg-yellow-100 text-yellow-800 rounded">No hay proyectos aún.</div>
    @endif

</div>
@endsection
