<x-admin-layout title="Projects" active="projects">
    <div class="flex items-center justify-between mb-6">
        <p class="text-slate-500 text-sm">{{ $projects->total() }} project{{ $projects->total() === 1 ? '' : 's' }}</p>
        <a href="{{ route('admin.projects.create') }}" class="btn btn-primary text-sm !py-2.5">New project <x-icon name="arrow" class="w-4 h-4"/></a>
    </div>

    <div class="card overflow-hidden">
        @if ($projects->isEmpty())
            <p class="text-slate-500 text-center py-16">No projects yet. <a href="{{ route('admin.projects.create') }}" class="text-brand-600 font-semibold">Create the first one</a>.</p>
        @else
            <div class="overflow-x-auto">
                <table class="w-full text-sm">
                    <thead class="bg-paper-200 text-left text-xs uppercase tracking-wider text-slate-500">
                        <tr>
                            <th class="px-5 py-3 font-semibold">Title</th>
                            <th class="px-5 py-3 font-semibold">Year</th>
                            <th class="px-5 py-3 font-semibold">Industry</th>
                            <th class="px-5 py-3 font-semibold">Status</th>
                            <th class="px-5 py-3 font-semibold text-right">Actions</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-slate-100">
                        @foreach ($projects as $project)
                            <tr class="hover:bg-paper/60">
                                <td class="px-5 py-3.5">
                                    <p class="font-medium text-slate-ink">{{ $project->title }}</p>
                                    <p class="text-xs text-slate-400">{{ $project->client }}</p>
                                </td>
                                <td class="px-5 py-3.5 text-slate-600">{{ $project->year }}</td>
                                <td class="px-5 py-3.5 text-slate-600">{{ collect(config('brokam.industries'))->firstWhere('slug', $project->industry)['name'] ?? '—' }}</td>
                                <td class="px-5 py-3.5">
                                    @if ($project->published)
                                        <span class="inline-flex items-center text-xs font-semibold px-2.5 py-1 rounded-full bg-green-50 text-green-700">Published</span>
                                    @else
                                        <span class="inline-flex items-center text-xs font-semibold px-2.5 py-1 rounded-full bg-slate-100 text-slate-500">Draft</span>
                                    @endif
                                    @if ($project->featured)
                                        <span class="inline-flex items-center text-xs font-semibold px-2.5 py-1 rounded-full bg-brand-50 text-brand-700 ml-1">Featured</span>
                                    @endif
                                </td>
                                <td class="px-5 py-3.5">
                                    <div class="flex items-center justify-end gap-2">
                                        <a href="{{ route('projects.show', $project) }}" target="_blank" class="text-slate-400 hover:text-brand-600" title="View"><x-icon name="arrow-up-right" class="w-5 h-5"/></a>
                                        <a href="{{ route('admin.projects.edit', $project) }}" class="text-sm font-semibold text-brand-600 hover:text-brand-700">Edit</a>
                                        <form method="POST" action="{{ route('admin.projects.destroy', $project) }}" onsubmit="return confirm('Delete this project? This cannot be undone.')">
                                            @csrf @method('DELETE')
                                            <button class="text-sm font-semibold text-red-500 hover:text-red-600">Delete</button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        @endif
    </div>

    <div class="mt-6">{{ $projects->links() }}</div>
</x-admin-layout>
