@extends('layouts.admin')

@section('title', 'Manage Divisions')

@section('content')
<div class="container mx-auto max-w-6xl">
    <div class="flex justify-between items-center mb-6">
        <h1 class="text-2xl font-bold text-slate-900">Manage Divisions</h1>
        <a href="{{ route('admin.divisions.create') }}" class="bg-brand-primary hover:bg-brand-accent text-white font-bold py-2.5 px-5 rounded-lg shadow-md shadow-brand-primary/20 transition flex items-center gap-2 text-sm">
            <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"></path></svg>
            Add New Division
        </a>
    </div>

    <div class="bg-white shadow-sm rounded-xl border border-slate-100 overflow-hidden">
        <table class="min-w-full leading-normal">
            <thead>
                <tr>
                    <th class="px-5 py-4 border-b-2 border-slate-100/80 bg-slate-50 text-left text-xs font-bold text-slate-500 uppercase tracking-wider">Title</th>
                    <th class="px-5 py-4 border-b-2 border-slate-100/80 bg-slate-50 text-left text-xs font-bold text-slate-500 uppercase tracking-wider">Services</th>
                    <th class="px-5 py-4 border-b-2 border-slate-100/80 bg-slate-50 text-right text-xs font-bold text-slate-500 uppercase tracking-wider">Actions</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-slate-100">
                @forelse ($divisions as $division)
                <tr class="hover:bg-slate-50/50 transition duration-150">
                    <td class="px-5 py-5 bg-transparent text-sm">
                        <div class="flex items-center gap-4">
                            <div class="w-10 h-10 rounded-lg bg-brand-light flex items-center justify-center text-brand-primary border border-brand-primary/10 p-2">
                                {!! App\Helpers\SvgHelper::sanitize($division->icon) !!}
                            </div>
                            <p class="text-slate-900 font-bold">{{ $division->title }}</p>
                        </div>
                    </td>
                    <td class="px-5 py-5 bg-transparent text-sm">
                        <p class="text-slate-500 truncate max-w-xs">{{ $division->services }}</p>
                    </td>
                    <td class="px-5 py-5 bg-transparent text-sm text-right">
                        <div class="flex items-center justify-end gap-3">
                            <a href="{{ route('admin.divisions.edit', $division) }}" class="p-2 text-slate-400 hover:text-brand-primary bg-slate-50 hover:bg-brand-light rounded-lg transition" title="Edit">
                                <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="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"></path></svg>
                            </a>
                            <form method="POST" action="{{ route('admin.divisions.destroy', $division) }}" class="inline" onsubmit="return confirm('Are you sure you want to delete this division?');">
                                @csrf
                                @method('DELETE')
                                <button type="submit" class="p-2 text-slate-400 hover:text-red-500 bg-slate-50 hover:bg-red-50 rounded-lg transition" title="Delete">
                                    <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="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"></path></svg>
                                </button>
                            </form>
                        </div>
                    </td>
                </tr>
                @empty
                <tr>
                    <td colspan="3" class="px-5 py-10 text-center text-slate-500 bg-white">
                        <div class="flex flex-col items-center justify-center">
                            <svg class="w-12 h-12 text-slate-300 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"></path></svg>
                            <p class="text-lg font-medium text-slate-900 mb-1">No divisions yet</p>
                            <p class="text-sm">Get started by creating a new division.</p>
                        </div>
                    </td>
                </tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>
@endsection
