@extends('layouts.admin')

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

@section('content')
<div class="bg-white rounded-xl shadow-sm p-6">
    <!-- Search -->
    <form method="GET" class="flex gap-3 mb-6">
        <input type="text" name="search" value="{{ request('search') }}" 
            placeholder="Search by name or email..."
            class="border border-gray-300 rounded-lg px-4 py-2 flex-1 max-w-md">
        <button type="submit" class="bg-gray-800 text-white px-6 py-2 rounded-lg hover:bg-gray-900">
            Search
        </button>
    </form>

    <!-- Users Table -->
    <div class="overflow-x-auto">
        <table class="w-full text-sm">
            <thead class="bg-gray-50">
                <tr class="text-gray-500">
                    <th class="text-left py-3 px-4">User</th>
                    <th class="text-left py-3 px-4">Email</th>
                    <th class="text-left py-3 px-4">Roles</th>
                    <th class="text-left py-3 px-4">Last Login</th>
                    <th class="text-left py-3 px-4">Actions</th>
                </tr>
            </thead>
            <tbody>
                @forelse($users as $user)
                <tr class="border-b hover:bg-gray-50">
                    <td class="py-3 px-4">
                        <div class="flex items-center gap-3">
                            <div class="w-8 h-8 bg-gray-200 rounded-full flex items-center justify-center text-gray-600 font-bold">
                                {{ strtoupper(substr($user->name, 0, 1)) }}
                            </div>
                            <span class="font-medium">{{ $user->name }}</span>
                        </div>
                    </td>
                    <td class="py-3 px-4 text-gray-600">{{ $user->email }}</td>
                    <td class="py-3 px-4">
                        @foreach($user->roles as $role)
                            <span class="px-2 py-1 rounded-full text-xs font-medium
                                {{ $role->name === 'admin' ? 'bg-red-100 text-red-700' : 
                                   ($role->name === 'vendor' ? 'bg-blue-100 text-blue-700' : 'bg-gray-100 text-gray-700') }}">
                                {{ ucfirst($role->name) }}
                            </span>
                        @endforeach
                    </td>
                    <td class="py-3 px-4 text-gray-500">
                        {{ $user->last_login_at ? $user->last_login_at->diffForHumans() : 'Never' }}
                    </td>
                    <td class="py-3 px-4">
                        <a href="{{ route('admin.password-resets.show', $user) }}" 
                           class="bg-blue-600 text-white px-3 py-1.5 rounded text-xs hover:bg-blue-700">
                            Reset Password
                        </a>
                    </td>
                </tr>
                @empty
                <tr>
                    <td colspan="5" class="py-8 text-center text-gray-500">No users found.</td>
                </tr>
                @endforelse
            </tbody>
        </table>
    </div>

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