<x-layouts.portal title="Staff Management" page-title="Team Management">
    <div class="flex justify-between items-center mb-8">
        <div>
            <h2 class="text-xl font-bold text-zinc-900 tracking-tight">Staff Members</h2>
            <p class="text-xs text-zinc-500 mt-1">Manage waiters and billers for this branch.</p>
        </div>
        <a href="{{ route('portal.staff.create') }}" class="inline-flex items-center px-4 py-2 bg-amber-600 text-white text-[10px] font-bold uppercase tracking-widest rounded-sm hover:bg-amber-700 transition-colors shadow-lg shadow-amber-900/20">
            <svg class="w-3.5 h-3.5 mr-2" 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 Member
        </a>
    </div>

    <!-- Filters & Search -->
    <x-card class="mb-8">
        <form action="{{ route('portal.staff.index') }}" method="GET" class="flex flex-col md:flex-row md:items-end gap-4">
            <div class="flex-1">
                <label class="text-[10px] font-bold text-zinc-400 uppercase tracking-widest mb-2 block">Search Staff</label>
                <div class="relative">
                    <input type="text" name="search" value="{{ request('search') }}" placeholder="Name, email or phone..." 
                        class="w-full pl-9 pr-4 py-2 bg-zinc-50 border border-zinc-200 rounded-sm text-xs focus:outline-hidden focus:border-amber-500/50 focus:ring-1 focus:ring-amber-500/20 transition-all text-zinc-900">
                    <svg class="w-4 h-4 absolute left-3 top-2.5 text-zinc-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path></svg>
                </div>
            </div>
            <div class="w-full md:w-48">
                <label class="text-[10px] font-bold text-zinc-400 uppercase tracking-widest mb-2 block">Filter by Role</label>
                <select name="role" onchange="this.form.submit()" class="w-full px-3 py-2 bg-zinc-50 border border-zinc-200 rounded-sm text-xs focus:outline-hidden focus:border-amber-500/50 transition-all text-zinc-900">
                    <option value="">All Roles</option>
                    <option value="waiter" {{ request('role') == 'waiter' ? 'selected' : '' }}>Waiter</option>
                    <option value="biller" {{ request('role') == 'biller' ? 'selected' : '' }}>Biller</option>
                </select>
            </div>
            <button type="submit" class="hidden">Search</button>
        </form>
    </x-card>

    <div class="bg-white border border-zinc-200 rounded-sm shadow-sm overflow-hidden">
        <table class="w-full text-left">
            <thead>
                <tr class="bg-zinc-50 border-b border-zinc-200">
                    <th class="px-6 py-4 text-[10px] font-black text-zinc-500 uppercase tracking-widest">Member Info</th>
                    <th class="px-6 py-4 text-[10px] font-black text-zinc-500 uppercase tracking-widest text-center">Role</th>
                    <th class="px-6 py-4 text-[10px] font-black text-zinc-500 uppercase tracking-widest text-center">Status</th>
                    <th class="px-6 py-4 text-[10px] font-black text-zinc-500 uppercase tracking-widest text-right">Actions</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-zinc-100">
                @forelse($staff as $member)
                    <tr class="hover:bg-zinc-50/50 transition-colors group">
                        <td class="px-6 py-4">
                            <div class="flex items-center space-x-3">
                                <div class="w-8 h-8 rounded-full bg-zinc-100 flex items-center justify-center text-xs font-bold text-zinc-600 border border-zinc-200 uppercase">
                                    {{ substr($member->name, 0, 1) }}
                                </div>
                                <div>
                                    <p class="text-xs font-bold text-zinc-900 leading-none">{{ $member->name }}</p>
                                    <p class="text-[10px] text-zinc-400 font-medium mt-1 uppercase tracking-tighter">{{ $member->email }}</p>
                                    @if($member->phone_number)
                                        <p class="text-[9px] text-zinc-400 mt-0.5">{{ $member->phone_number }}</p>
                                    @endif
                                </div>
                            </div>
                        </td>
                        <td class="px-6 py-4 text-center">
                            @if($member->role == 'waiter')
                                <span class="inline-flex items-center px-2 py-0.5 rounded-full text-[9px] font-bold uppercase tracking-widest bg-blue-50 text-blue-600 border border-blue-100">
                                    Waiter App
                                </span>
                            @else
                                <span class="inline-flex items-center px-2 py-0.5 rounded-full text-[9px] font-bold uppercase tracking-widest bg-purple-50 text-purple-600 border border-purple-100">
                                    Biller / POS
                                </span>
                            @endif
                        </td>
                        <td class="px-6 py-4 text-center">
                            <span class="inline-flex items-center px-2 py-0.5 rounded-full text-[9px] font-bold uppercase tracking-widest {{ $member->active ? 'bg-green-50 text-green-600 border border-green-100' : 'bg-zinc-100 text-zinc-400' }}">
                                {{ $member->active ? 'Active' : 'Inactive' }}
                            </span>
                        </td>
                        <td class="px-6 py-4 text-right">
                            <div class="flex items-center justify-end space-x-2 opacity-0 group-hover:opacity-100 transition-opacity">
                                <a href="{{ route('portal.staff.edit', $member) }}" class="p-1.5 text-zinc-400 hover:text-amber-600 hover:bg-amber-50 rounded-sm transition-all">
                                    <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 action="{{ route('portal.staff.destroy', $member) }}" method="POST" onsubmit="return confirm('Remove this staff member?');" class="inline">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="p-1.5 text-zinc-400 hover:text-red-600 hover:bg-red-50 rounded-sm transition-all">
                                        <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="4" class="px-6 py-12 text-center">
                            <div class="max-w-xs mx-auto">
                                <svg class="w-12 h-12 mx-auto text-zinc-200 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path></svg>
                                <p class="text-xs font-bold text-zinc-400 uppercase tracking-widest">No Staff Members Yet</p>
                                <p class="text-[10px] text-zinc-500 mt-2">Start by adding your waiters and billers to help you manage the restaurant.</p>
                            </div>
                        </td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>

    <div class="mt-6">
        {{ $staff->links() }}
    </div>
</x-layouts.portal>
