<x-jetstream.form-section submit="updateProfilePersonalForm">
    <x-slot name="title">
    </x-slot>

    <x-slot name="description">
        <div class="">
            @livewire('side-post', [
                'type' => 'SiteContents\User\Edit\PersonalInfo' ?? null,
                'sticky' => false, 'random' => true,
                'fallbackTitle' => __('Personal info'),
                'fallbackDescription' => trans_with_platform('A comprehensive profile helps other @PLATFORM_USERS@ get a proper impression of you. Add a profile photo to become more recognizable on our platform. We ask this to increase trust between our participants and to make the @PLATFORM_NAME_SHORT@ exchanges more personal and enjoyable. Of course, your personal data is only used within @PLATFORM_NAME@.') ])
        </div>
    </x-slot>

    <x-slot name="form">
        <!-- Profile Photo -->
        @if (Laravel\Jetstream\Jetstream::managesProfilePhotos())
            <div x-data="{photoName: null, photoPreview: null}" class="col-span-6 sm:col-span-4">
                <!-- Profile Photo File Input -->
                <input type="file" class="hidden"
                            wire:model.live="photo"
                            x-ref="photo"
                            x-on:change="
                                    photoName = $refs.photo.files[0].name;
                                    const reader = new FileReader();
                                    reader.onload = (e) => {
                                        photoPreview = e.target.result;
                                    };
                                    reader.readAsDataURL($refs.photo.files[0]);
                            " />

                <x-jetstream.label for="photo" value="{{ __('Profile Photo') }}" />

                <!-- Current Profile Photo -->
                <div class="mt-3 mb-3" x-show="! photoPreview">
                    <img src="{{ $this->user->profile_photo_url }}" alt="{{ $this->user->name }}" class="rounded-full profile-photo h-20 w-20 object-cover outline outline-1 outline-offset-1 outline-gray-500">
                </div>

                <!-- New Profile Photo Preview -->
                <div class="mt-3 mb-3" x-show="photoPreview" style="display: none;">
                    <span class="block rounded-full w-20 h-20 bg-cover bg-no-repeat bg-center object-cover outline outline-1 outline-offset-1 outline-gray-500"
                        x-bind:style="'background-image: url(\'' + photoPreview + '\');'">
                    </span>
                </div>

                <x-jetstream.secondary-button class="mt-2 mr-2" type="button" x-on:click.prevent="$refs.photo.click()">
                    {{ __('Change Photo') }}
                </x-jetstream.secondary-button>

                @if ($this->user->profile_photo_path)
                    <x-jetstream.secondary-button type="button" class="mt-2" wire:click="deleteProfilePhoto" x-on:click.prevent="">
                        {{ __('Delete Photo') }}
                    </x-jetstream.secondary-button>
                @endif

                <x-jetstream.input-error for="photo" class="mt-2" />
            </div>
        @endif

        <!-- About field-->
        <div class="col-span-6 sm:col-span-4">
            <x-textarea
                wire:model.live.debounce.500ms="state.about"
                label="{{ $this->aboutLabel }}"
                placeholder="{{ __('Relevant background info about you') }}"
                class="placeholder-gray-300 "
                rows="14"
                maxlength="{{ timebank_config('rules.profile_user.about_max_input') }}" />
            <x-jetstream.input-error for="about" class="mt-2" />
        </div>

        <!-- About_short field -->
        <div class="col-span-6 sm:col-span-4">
            <x-textarea
                wire:model.live.debounce.500ms="state.about_short"
                label="{{ $this->aboutShortLabel }}"
                placeholder="{{ __('Someone who is interested in...') }}"
                class="placeholder-gray-300"
                rows="3"
                maxlength="{{ timebank_config('rules.profile_user.about_short_max_input') }}" />
            <x-jetstream.input-error for="about_short" class="mt-2" />
        </div>

        <!-- Motivation field -->
        <div class="col-span-6 sm:col-span-4">
            <x-textarea
                wire:model.live.debounce.500ms="state.motivation"
                label="{{ $this->motivationLabel }}"
                placeholder="{{__('Just trying out or serious about a new value system?')}}"
                class="placeholder-gray-300"
                rows="5"
                maxlength="{{ timebank_config('rules.profile_user.motivation_max_input') }}" />
            <x-jetstream.input-error for="motivation" class="mt-2" />
        </div>

        <!--- Languages -->
        <div class="col-span-6 sm:col-span-4">
            @livewire('profile.languages-dropdown', ['languages' => $languages])
            <x-jetstream.input-error for="languages" class="mt-2" />
        </div>

        <!--- Social media -->
        <div class="col-span-6 sm:col-span-4">
            @livewire('profile.socials-form')
            <x-jetstream.input-error for="socials" class="mt-2" />
        </div>

        <!-- Birth Date -->
        <div class="grid col-span-3 sm:col-span-3">
            <!-- min age is 5 and max is 120 to prevent obvious faulty inputs / typo's -->
            <label class="block text-sm font-medium text-gray-700 mb-1">{{__('Date of birth') . ' (' . __('only your current age will be visible on your profile page') . ')' }}</label>
            <x-flatpickr
                dateFormat="Y-m-d"
                altFormat="d-m-Y"
                placeholder="{{__('DD-MM-YYYY')}}"
                wire:model="state.date_of_birth"
                :maxDate="now()->subYears(5)"
                :minDate="now()->subYears(120)"
                class="mt-1 block w-full border-gray-300 rounded-md shadow-sm placeholder-gray-300 focus:border-theme-accent focus:ring-1 focus:ring-theme-accent"
            />
            <x-jetstream.input-error for="date_of_birth" class="mt-2" />
        </div>


        <!-- Website -->
        <div class="grid col-span-6 sm:col-span-4">
            <x-jetstream.label for="website" value="{{ __('My website') }}" />
            <x-jetstream.input
                placeholder="website.org"
                              wire:model.blur="website"
                class="placeholder-gray-300"
            />
            <x-jetstream.input-error for="website" class="mt-2" />
        </div>
    </x-slot>

    <!-- List of validation errors -->
    <x-errors />

    <x-slot name="actions">
        <x-jetstream.action-message class="mr-3" on="saved">
            {{ __('Saved') }}
        </x-jetstream.action-message>

        <x-jetstream.button wire:loading.attr="disabled" wire:target="photo">
            {{ __('Save') }}
        </x-jetstream.button>
    </x-slot>
</x-jetstream.form-section>

