<html>

<x-head />

<body>

    <x-header />

    <div class="bradcam_area bradcam_bg_1">
        <div class="container">
            <div class="row">
                <div class="col-xl-12">
                    <div class="bradcam_text">

                        @if(Auth::user() && Auth::user()->id == $user->id)
                        <h3>Личный кабинет</h3>
                        @else
                        <h3>Пользователь: {{$user->name}}</h3>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="container mt-5 mb-5">
        <div class="row">
            <div class="col-md-8 offset-md-2">
                <div class="card">
                    <div class="card-header text-center">
                        @if(Route::is('user'))
                        @if(Auth::user() && Auth::user()->id == $user->id)
                        <h3>Мой профиль</h3>
                        @else
                        <h3>Профиль пользователя: {{$user->name}}</h3>
                        @endif
                        @endif

                        @if(Route::is('edit_user'))
                        <h3>Редактирование профиля</h3>
                        @endif
                    </div>
                    @if(Route::is('user'))
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-4">
                                <img src="public/{{$user->avatar}}" class="img-fluid rounded-circle" alt="Avatar">
                            </div>
                            <div class="col-md-8">
                                <h4>Имя: {{ $user->name }}</h4>
                                <h4>Почта: {{ $user->email }}</h4>
                                <h4 class="mt-4">О себе:</h4>
                                <p>{{ $user->comment }}</p>
                                <h4 class="mt-4">Дата создания аккаунта: {{$user->created_at}}</h4>
                                @if(Auth::user() && Auth::user()->role == 'admin' || Auth::user() && Auth::user()->id == $user->id)
                                <a href="{{Route('edit_user', $user->id)}}" class="btn btn-primary mt-4">Изменить</a>
                                @endif
                            </div>
                        </div>
                    </div>
                    @endif
                    @if(Route::is('edit_user'))
                    <div class="card-body">
                        <form action="{{ Route('edituser', $user->id) }}" method="post" class="registration_form" enctype="multipart/form-data">
                            @csrf
                            <div class="form-row">
                                <div class="form-group col-md-6">
                                    <label for="name">Имя</label>
                                    <input type="text" class="form-control" id="nameEdit" name="nameEdit" placeholder="Введите имя" value="{{$user->name}}">
                                </div>
                                <div class="form-group col-md-6">
                                    <label for="email">Почта</label>
                                    <input type="email" class="form-control" id="emailEdit" name="emailEdit" placeholder="Введите почту" value="{{$user->email}}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="comment">О себе</label>
                                <textarea type="text" class="form-control" id="commentEdit" cols="30" rows="10" name="commentEdit" placeholder="Введите информацию о себе" >{{$user->comment}}</textarea>
                            </div>
                            @error("resumeEdit")
                            <div class="alert alert-danger">Давай пиши чё-то</div>
                            @enderror
                            <div class="form-group">
                                <label for="avatar">Аватар</label>
                                <input type="file" class="form-control-file" id="avatar" name="avatar">
                            </div>
                            <button type="submit" class="btn btn-success">Изменить</button>
                        </form>
                    </div>
                    @endif
                </div>
            </div>
        </div>
    </div>

    <x-footer />

    <x-scripts />
</body>

</html>