@extends('layouts.super-admin')

@section('title', 'Client Management')
@section('page_title', 'Client Management')

@section('content')
<div class="mb-4 flex justify-between items-center">
    <h3 class="text-[11px] font-bold uppercase tracking-widest text-zinc-600 dark:text-zinc-300">Registered Clients</h3>
    <a href="{{ route('clients.create') }}" class="px-3 py-1 bg-amber-600 hover:bg-amber-500 text-white text-[10px] font-bold uppercase tracking-widest rounded-sm transition-all active:scale-[0.97]">
        Add New Client
    </a>
</div>

<div class="bg-white dark:bg-zinc-900 border border-zinc-200 dark:border-zinc-800 rounded-sm shadow-sm overflow-hidden">
    <div class="overflow-x-auto">
        <table class="w-full text-left text-[11px]">
            <thead class="bg-zinc-100 dark:bg-zinc-800/80 text-zinc-500 dark:text-zinc-400 uppercase tracking-tighter font-bold border-b border-zinc-200 dark:border-zinc-800">
                <tr>
                    <th class="px-4 py-2">Client Name</th>
                    <th class="px-4 py-2">Email</th>
                    <th class="px-4 py-2 text-center">Branches</th>
                    <th class="px-4 py-2 text-center">Status</th>
                    <th class="px-4 py-2 text-right">Actions</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-zinc-100 dark:divide-zinc-800 text-zinc-600 dark:text-zinc-400">
                @forelse($clients as $client)
                    <tr class="hover:bg-zinc-50 dark:hover:bg-zinc-800/50 transition-colors">
                        <td class="px-4 py-2 font-bold text-zinc-900 dark:text-zinc-100">{{ $client->name }}</td>
                        <td class="px-4 py-2">{{ $client->email }}</td>
                        <td class="px-4 py-2 text-center">
                            <span class="px-2 py-0.5 rounded-full bg-zinc-100 dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700">
                                {{ $client->branches_count }}
                            </span>
                        </td>
                        <td class="px-4 py-2 text-center">
                            @if($client->active)
                                <span class="text-[9px] font-bold text-green-500 uppercase">Active</span>
                            @else
                                <span class="text-[9px] font-bold text-red-500 uppercase">Inactive</span>
                            @endif
                        </td>
                        <td class="px-4 py-2 text-right">
                            <div class="flex justify-end space-x-2">
                                <a href="{{ route('clients.edit', $client) }}" class="text-amber-600 hover:text-amber-500 font-bold uppercase text-[9px]">Edit</a>
                                <form action="{{ route('clients.destroy', $client) }}" method="POST" onsubmit="return confirm('Delete this client and all associated data?')">
                                    @csrf @method('DELETE')
                                    <button type="submit" class="text-red-600 hover:text-red-500 font-bold uppercase text-[9px]">Delete</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="5" class="px-4 py-12 text-center italic opacity-50">No clients found.</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>

<div class="mt-4">
    {{ $clients->links() }}
</div>
@endsection
