@extends('layouts.admin')

@section('title', 'Categorias')

@section('content')
<div class="relative z-10 w-full max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 pb-12">

    <header class="mb-10 flex flex-col md:flex-row md:items-end justify-between gap-6 pt-6">
        <div>
            <div class="flex items-center gap-3 mb-2">
                <span class="w-8 h-[2px] bg-brand"></span>
                <span class="font-bold text-[10px] uppercase tracking-[0.4em] text-brand">Gestão de Conteúdo</span>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold italic tracking-tighter uppercase text-brand">CATEGORIAS</h1>
            <p class="text-slate-500 font-medium mt-1">{{ $categories->count() }} categorias registadas</p>
        </div>
        <a href="{{ route('admin.categories.create') }}"
           class="inline-flex items-center gap-2 bg-brand hover:bg-brand-700 text-white font-bold uppercase tracking-widest text-xs rounded-xl px-6 py-4 transition-all shadow-md shadow-brand/20 active:scale-[0.98]">
            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
            </svg>
            Nova Categoria
        </a>
    </header>

    <div class="bg-white border border-slate-100 rounded-2xl shadow-sm overflow-hidden">
        @if($categories->count())
        <div class="overflow-x-auto">
            <table class="w-full text-sm">
                <thead>
                    <tr class="bg-slate-50 border-b border-slate-100">
                        <th class="text-left text-[10px] font-bold uppercase tracking-widest text-slate-400 px-5 py-4">Imagem</th>
                        <th class="text-left text-[10px] font-bold uppercase tracking-widest text-slate-400 px-5 py-4">Nome</th>
                        <th class="text-left text-[10px] font-bold uppercase tracking-widest text-slate-400 px-5 py-4">Slug</th>
                        <th class="text-center text-[10px] font-bold uppercase tracking-widest text-slate-400 px-5 py-4">Hero</th>
                        <th class="text-center text-[10px] font-bold uppercase tracking-widest text-slate-400 px-5 py-4">Ativo</th>
                        <th class="text-center text-[10px] font-bold uppercase tracking-widest text-slate-400 px-5 py-4">Ordem</th>
                        <th class="text-right text-[10px] font-bold uppercase tracking-widest text-slate-400 px-5 py-4">Ações</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-50">
                    @foreach($categories as $category)
                    <tr class="hover:bg-slate-50/50 transition">
                        <td class="px-5 py-4">
                            @if($category->image)
                            <img src="{{ asset('storage/' . $category->image) }}"
                                 class="w-12 h-12 rounded-xl object-cover border border-slate-100">
                            @else
                            <div class="w-12 h-12 rounded-xl bg-slate-100 flex items-center justify-center text-slate-300">
                                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.41a2.25 2.25 0 013.182 0l2.909 2.91m-18 3.75h16.5a1.5 1.5 0 001.5-1.5V6a1.5 1.5 0 00-1.5-1.5H3.75A1.5 1.5 0 002.25 6v12a1.5 1.5 0 001.5 1.5z"/>
                                </svg>
                            </div>
                            @endif
                        </td>
                        <td class="px-5 py-4 font-bold text-slate-800">{{ $category->name }}</td>
                        <td class="px-5 py-4 text-slate-400 text-xs">{{ $category->slug }}</td>
                        <td class="px-5 py-4 text-center">
                            @if($category->show_in_hero)
                            <span class="inline-flex items-center gap-1 text-[10px] font-bold text-green-600 bg-green-50 border border-green-100 rounded-lg px-2.5 py-1">Sim</span>
                            @else
                            <span class="inline-flex items-center gap-1 text-[10px] font-bold text-slate-400 bg-slate-50 border border-slate-100 rounded-lg px-2.5 py-1">Não</span>
                            @endif
                        </td>
                        <td class="px-5 py-4 text-center">
                            @if($category->is_active)
                            <span class="inline-flex items-center gap-1 text-[10px] font-bold text-green-600 bg-green-50 border border-green-100 rounded-lg px-2.5 py-1">Sim</span>
                            @else
                            <span class="inline-flex items-center gap-1 text-[10px] font-bold text-red-400 bg-red-50 border border-red-100 rounded-lg px-2.5 py-1">Não</span>
                            @endif
                        </td>
                        <td class="px-5 py-4 text-center font-bold text-slate-500">{{ $category->sort_order ?? '-' }}</td>
                        <td class="px-5 py-4 text-right">
                            <div class="flex items-center justify-end gap-2">
                                <a href="{{ route('admin.categories.edit', $category->id) }}"
                                   class="inline-flex items-center gap-1.5 text-[10px] font-bold uppercase tracking-widest text-brand bg-brand/5 hover:bg-brand/10 border border-brand/10 rounded-xl px-3.5 py-2.5 transition">
                                    <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/>
                                    </svg>
                                    Editar
                                </a>
                                <form action="{{ route('admin.categories.destroy', $category->id) }}" method="POST"
                                      onsubmit="return confirm('Tem a certeza que pretende eliminar esta categoria?')">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit"
                                            class="inline-flex items-center gap-1.5 text-[10px] font-bold uppercase tracking-widest text-red-500 bg-red-50 hover:bg-red-100 border border-red-100 rounded-xl px-3.5 py-2.5 transition">
                                        <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
                                        </svg>
                                        Eliminar
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        @else
        <div class="flex flex-col items-center justify-center py-20 px-6">
            <div class="w-16 h-16 bg-slate-50 rounded-2xl flex items-center justify-center mb-4">
                <svg class="w-7 h-7 text-slate-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9.568 3H5.25A2.25 2.25 0 003 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 005.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 009.568 3z"/>
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M6 6h.008v.008H6V6z"/>
                </svg>
            </div>
            <p class="text-slate-300 text-xs font-bold uppercase tracking-widest text-center">Nenhuma categoria encontrada</p>
            <p class="text-slate-200 text-[10px] font-bold mt-1">Crie a primeira categoria para começar</p>
        </div>
        @endif
    </div>
</div>
@endsection
