@extends('layouts.app')

@section('page-title', 'User Management')

@section('content')
<div class="bg-white rounded-lg shadow-sm overflow-hidden">
    <div class="p-6 border-b border-gray-100 flex justify-between items-center">
        <h3 class="text-lg font-semibold text-gray-800">Users List</h3>
        <a href="{{ route('users.create') }}" class="bg-indigo-600 text-white px-4 py-2 rounded-lg hover:bg-indigo-700 transition-colors duration-200 flex items-center">
            <i class="fas fa-plus mr-2"></i> Add New User
        </a>
    </div>

    <div class="overflow-x-auto">
        <table class="w-full text-left border-collapse">
            <thead>
                <tr class="bg-gray-50 text-gray-600 text-sm uppercase tracking-wider">
                    <th class="p-4 font-semibold border-b">Name</th>
                    <th class="p-4 font-semibold border-b">Email</th>
                    <th class="p-4 font-semibold border-b">Role</th>
                    <th class="p-4 font-semibold border-b">Created At</th>
                    <th class="p-4 font-semibold border-b text-right">Actions</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-100">
                @forelse($users as $user)
                <tr class="hover:bg-gray-50 transition-colors duration-150">
                    <td class="p-4 text-gray-800 font-medium">
                        <div class="flex items-center">
                            <div class="h-8 w-8 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-600 font-bold mr-3">
                                {{ substr($user->name, 0, 1) }}
                            </div>
                            {{ $user->name }}
                        </div>
                    </td>
                    <td class="p-4 text-gray-600">{{ $user->email }}</td>
                    <td class="p-4">
                        <span class="px-2 py-1 text-xs font-semibold rounded-full 
                            @if($user->role === 'Branch Manager') bg-purple-100 text-purple-700
                            @elseif($user->role === 'Cashier') bg-green-100 text-green-700
                            @elseif($user->role === 'Receptionist') bg-blue-100 text-blue-700
                            @else bg-gray-100 text-gray-700 @endif">
                            {{ $user->role }}
                        </span>
                    </td>
                    <td class="p-4 text-gray-600 text-sm">{{ $user->created_at->format('M d, Y') }}</td>
                    <td class="p-4 text-right space-x-2">
                        <a href="{{ route('users.edit', $user) }}" class="text-blue-600 hover:text-blue-800" title="Edit">
                            <i class="fas fa-edit"></i>
                        </a>
                        @if(auth()->id() !== $user->id)
                        <form action="{{ route('users.destroy', $user) }}" method="POST" class="inline-block" onsubmit="return confirm('Are you sure you want to delete this user?');">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="text-red-600 hover:text-red-800" title="Delete">
                                <i class="fas fa-trash"></i>
                            </button>
                        </form>
                        @endif
                    </td>
                </tr>
                @empty
                <tr>
                    <td colspan="5" class="p-8 text-center text-gray-500">
                        No users found.
                    </td>
                </tr>
                @endforelse
            </tbody>
        </table>
    </div>

    <div class="p-4 border-t border-gray-100">
        {{ $users->links() }}
    </div>
</div>
@endsection
