@extends('layouts.admin')

@section('title', 'Edit User')

@section('content')
<div class="min-h-screen bg-slate-50">
    <div class="mx-auto max-w-4xl px-4 py-6 sm:px-6 lg:px-8">

        <div class="mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
            <div>
                <h1 class="text-2xl font-bold text-slate-800 md:text-3xl">Edit User</h1>
                <p class="mt-1 text-sm text-slate-500">ইউজারের তথ্য আপডেট করুন</p>
            </div>

            <a href="{{ route('admin.users.index') }}"
               class="rounded-xl border border-slate-300 bg-white px-4 py-2 text-sm font-semibold text-slate-700 transition hover:bg-slate-50">
                Back
            </a>
        </div>

        <div class="rounded-3xl border border-slate-200 bg-white p-6 shadow-sm">
            <form action="{{ route('admin.users.update', $user) }}" method="POST" class="space-y-6">
                @csrf
                @method('PUT')

                <div class="grid grid-cols-1 gap-6 md:grid-cols-2">
                    <div>
                        <label class="mb-2 block text-sm font-semibold text-slate-700">
                            Username <span class="text-rose-500">*</span>
                        </label>
                        <input type="text"
                               name="username"
                               value="{{ old('username', $user->username) }}"
                               class="w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm outline-none transition focus:border-blue-500 focus:ring-4 focus:ring-blue-100">
                        @error('username')
                            <p class="mt-1 text-sm text-rose-600">{{ $message }}</p>
                        @enderror
                    </div>

                    <div>
                        <label class="mb-2 block text-sm font-semibold text-slate-700">Phone</label>
                        <input type="text"
                               name="phone"
                               value="{{ old('phone', $user->phone) }}"
                               class="w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm outline-none transition focus:border-blue-500 focus:ring-4 focus:ring-blue-100">
                        @error('phone')
                            <p class="mt-1 text-sm text-rose-600">{{ $message }}</p>
                        @enderror
                    </div>

                    <div class="md:col-span-2">
                        <label class="mb-2 block text-sm font-semibold text-slate-700">Email</label>
                        <input type="email"
                               name="email"
                               value="{{ old('email', $user->email) }}"
                               class="w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm outline-none transition focus:border-blue-500 focus:ring-4 focus:ring-blue-100">
                        @error('email')
                            <p class="mt-1 text-sm text-rose-600">{{ $message }}</p>
                        @enderror
                    </div>

                    <div class="md:col-span-2">
                        <label class="mb-2 block text-sm font-semibold text-slate-700">
                            Status <span class="text-rose-500">*</span>
                        </label>
                        <select name="status"
                                class="w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm outline-none transition focus:border-blue-500 focus:ring-4 focus:ring-blue-100">
                            <option value="active" {{ old('status', $user->status) === 'active' ? 'selected' : '' }}>Active</option>
                            <option value="blocked" {{ old('status', $user->status) === 'blocked' ? 'selected' : '' }}>Blocked</option>
                        </select>
                        @error('status')
                            <p class="mt-1 text-sm text-rose-600">{{ $message }}</p>
                        @enderror
                    </div>
                </div>

                <div class="rounded-2xl border border-slate-200 bg-slate-50 p-4">
                    <div class="grid grid-cols-1 gap-4 text-sm text-slate-600 md:grid-cols-3">
                        <div>
                            <span class="block text-xs uppercase text-slate-400">Joined</span>
                            <span class="font-semibold text-slate-800">
                                {{ optional($user->created_at)?->format('d M Y h:i A') ?? '—' }}
                            </span>
                        </div>
                        <div>
                            <span class="block text-xs uppercase text-slate-400">Last Login</span>
                            <span class="font-semibold text-slate-800">
                                {{ optional($user->last_login_at)?->format('d M Y h:i A') ?? '—' }}
                            </span>
                        </div>
                        <div>
                            <span class="block text-xs uppercase text-slate-400">Last Activity</span>
                            <span class="font-semibold text-slate-800">
                                {{ optional($user->last_activity_at)?->format('d M Y h:i A') ?? '—' }}
                            </span>
                        </div>
                    </div>
                </div>

                <div class="flex flex-wrap items-center gap-3">
                    <button type="submit"
                            class="rounded-2xl bg-blue-600 px-6 py-3 text-sm font-semibold text-white shadow-sm transition hover:bg-blue-700">
                        Update User
                    </button>

                    <a href="{{ route('admin.users.show', $user) }}"
                       class="rounded-2xl border border-slate-300 bg-white px-6 py-3 text-sm font-semibold text-slate-700 transition hover:bg-slate-50">
                        View Details
                    </a>
                </div>
            </form>
        </div>
    </div>
</div>
@endsection