@extends('main.layouts.main')

@section('content')
    <div class="register-page">
        <div class="register-welcome" style="margin-right: 50px;">
            <i class="fad fa-user-edit" style="font-size: 400px;"></i>
        </div>
        <form action="{{ route('user_save') }}" method="post" class="register" enctype="multipart/form-data">
            @if(Session::has('success'))
                <p class="msg-success">{{ Session::get('success') }}</p>
            @endif
            <h3>Редактирование профиля</h3>
            @csrf
            <label for="avatar">Изображение профиля</label>
            <img src="{{ (!$user->avatar_url) ? asset('/assets/main/images/other/nouser.png') : $user->avatar_url }}" class="avatar-edit" alt="Это вы">
            <input type="file" name="avatar" onchange="selectAvatar(event)" id="avatar" accept="image/x-png,image/gif,image/jpeg">
            @error('avatar')
                <span class="invalid-feedback" role="alert">
                <strong>{{ $message }}</strong>
                </span>
            @enderror
            <label for="name">Ваше имя</label>
            <input type="text" id="name" name="name" value="{{ $user->name }}" placeholder="Введите ваше имя..">
            @error('name')
            <span class="invalid-feedback" role="alert">
                <strong>{{ $message }}</strong>
            </span>
            @enderror
            <label for="surname">Ваша фамилия</label>
            <input type="text" name="surname" value="{{ $user->surname }}" id="surname" placeholder="Введите вашу фамилию..">
            @error('surname')
            <span class="invalid-feedback" role="alert">
                <strong>{{ $message }}</strong>
            </span>
            @enderror
            <label for="email">Электронная почта</label>
            <input type="email" name="email" value="{{ $user->email }}" id="email" placeholder="Введите ваш email..">
            @error('email')
            <span class="invalid-feedback" role="alert">
                <strong>{{ $message }}</strong>
            </span>
            @enderror
            <label for="username">Имя пользователя</label>
            <input type="text" name="username" value="{{ $user->username }}" id="username" placeholder="Придумайте логин..">
            @error('username')
            <span class="invalid-feedback" role="alert">
                <strong>{{ $message }}</strong>
            </span>
            @enderror
            <label for="password">Пароль</label>
            <input type="password" name="password" value="no-change-password" id="password" placeholder="Придумайте пароль..">
            @error('password')
            <span class="invalid-feedback" role="alert">
                <strong>{{ $message }}</strong>
            </span>
            @enderror
            <label for="password_confirmation">Подтверждение пароля</label>
            <input type="password" name="password_confirmation" id="password_confirmation"
                   placeholder="Введите пароль еще раз..">
            @error('password_confirmation')
            <span class="invalid-feedback" role="alert">
                <strong>{{ $message }}</strong>
            </span>
            @enderror
            <label>Дата рождения</label>
            <div>
                <select name="day">
                    @for($i = 0; $i < $dob->month->days_count; $i++)
                        <option value="{{ $i + 1 }}" {{ ($i + 1 == $dob->day) ? 'selected' : '' }}>{{ $i + 1 }}</option>
                    @endfor
                </select>
                @error('day')
                <span class="invalid-feedback" role="alert">
                    <strong>{{ $message }}</strong>
                </span>
                @enderror
                <select name="month">
                    @foreach($months as $month)
                        <option value="{{ $month->title }}" days-count="{{ $month->days_count }}" {{ ($month->title == $dob->month->title) ? 'selected' : '' }}>{{ $month->title }}</option>
                    @endforeach
                </select>
                @error('month')
                <span class="invalid-feedback" role="alert">
                    <strong>{{ $message }}</strong>
                </span>
                @enderror
                <select name="year">
                    @for($i = $year["min"]; $i <= $year["max"]; $i++)
                        <option value="{{ $i }}" {{ ($i == $dob->year) ? 'selected' : '' }}>{{ $i }}</option>
                    @endfor
                </select>
                @error('year')
                <span class="invalid-feedback" role="alert">
                    <strong>{{ $message }}</strong>
                </span>
                @enderror
            </div>
            <label for="country">Страна</label>
            <select name="country_id" id="country">
                @foreach($countries as $country)
                    <option value="{{ $country->id }}" {{ ($country->name == $user->country->name) ? 'selected' : '' }}>{{ $country->name }}</option>
                @endforeach
            </select>
            @error('country')
            <span class="invalid-feedback" role="alert">
                    <strong>{{ $message }}</strong>
                </span>
            @enderror
            <label for="city">Город</label>
            <select name="city_id" id="city">
                @foreach($cities as $city)
                    <option value="{{ $city->id }}" {{ ($city->name == $user->city->name) ? 'selected' : '' }}>{{ $city->name }}</option>
                @endforeach
            </select>
            @error('city')
            <span class="invalid-feedback" role="alert">
                    <strong>{{ $message }}</strong>
                </span>
            @enderror
            <label for="skill">Род деятельности (skill)</label>
            <input type="text" name="skill" value="{{ $user->skill }}" id="skill">
            @error('skill')
            <span class="invalid-feedback" role="alert">
                <strong>{{ $message }}</strong>
            </span>
            @enderror
            <label for="about">О себе</label>
            <textarea name="about" rows="4" id="about">{{ $user->about }}</textarea>
            @error('about')
            <span class="invalid-feedback" role="alert">
                <strong>{{ $message }}</strong>
            </span>
            @enderror
            <button type="submit">Вперед</button>
    </div>
@endsection
