<section>
    <header>
        <h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
            {{ __('Profile Information') }}
        </h2>

        @if ($user->discord_id)
        <div class="p-2 rounded-lg bg-rose-600/80 mt-4">
            <p class="p-2 text-sm dark:text-gray-200 text-white">
                {{ __('Changing your name or email will not affect Discord authentication, as your Discord ID has been stored.') }}
            </p>
        </div>
        @else
        <div class="p-2 rounded-lg bg-green-600/80 mt-4">
            <p class="p-2 text-sm dark:text-gray-200 text-white">
                {{ __('If you want to use Discord authentication, ensure the email addresses match for initial login. After login with Discord, email can be changed.') }}
            </p>
        </div>
        @endif
    </header>

    <form id="send-verification" method="post" action="{{ route('verification.send') }}">
        @csrf
    </form>

    <form method="post" action="{{ route('profile.update') }}" class="mt-6 space-y-6" enctype="multipart/form-data">
        @csrf
        @method('patch')

        <div>
            <x-input-label for="image" :value="__('Avatar')" />
            <div class="mt-2 flex items-center gap-4">
                <img
                    src="{{ $user->getAvatar() }}"
                    alt="{{ $user->name }}"
                    class="h-16 w-16 rounded-full object-cover"
                >
                <input
                    id="image"
                    name="image"
                    type="file"
                    accept="image/*"
                    class="block w-full text-sm text-gray-900 dark:text-gray-100
                        file:mr-4 file:rounded-md file:border-0
                        file:bg-rose-600 file:px-4 file:py-2
                        file:text-sm file:font-semibold file:text-white
                        hover:file:bg-rose-500"
                />
            </div>
            <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">
                JPG, PNG, WebP or GIF. Max 8MB. Will be cropped to 128×128.
            </p>
            <x-input-error class="mt-2" :messages="$errors->get('image')" />
        </div>

        <div>
            <x-input-label for="name" :value="__('Name')" />
            <x-text-input id="name" name="name" type="text" class="mt-1 block w-full" :value="old('name', $user->name)" required autofocus autocomplete="name" />
            <x-input-error class="mt-2" :messages="$errors->get('name')" />
        </div>

        <div>
            <x-input-label for="email" :value="__('Email')" />
            <x-text-input id="email" name="email" type="email" class="mt-1 block w-full" :value="old('email', $user->email)" required autocomplete="email" />
            <x-input-error class="mt-2" :messages="$errors->get('email')" />

            @if ($user instanceof \Illuminate\Contracts\Auth\MustVerifyEmail && ! $user->hasVerifiedEmail())
                <div>
                    <p class="text-sm mt-2 text-gray-800 dark:text-gray-200">
                        {{ __('Your email address is unverified.') }}

                        <button form="send-verification" class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800">
                            {{ __('Click here to re-send the verification email.') }}
                        </button>
                    </p>

                    @if (session('status') === 'verification-link-sent')
                        <p class="mt-2 font-medium text-sm text-green-600 dark:text-green-400">
                            {{ __('A new verification link has been sent to your email address.') }}
                        </p>
                    @endif
                </div>
            @endif
        </div>

        <div class="flex items-center gap-4">
            <x-primary-button>{{ __('Save') }}</x-primary-button>

            @if (session('status') === 'profile-updated')
                <p
                    x-data="{ show: true }"
                    x-show="show"
                    x-transition
                    x-init="setTimeout(() => show = false, 2000)"
                    class="text-sm text-gray-600 dark:text-gray-400"
                >{{ __('Saved.') }}</p>
            @endif
        </div>
    </form>
</section>
