<x-app-layout>
    <div>

        <!-- Content Header (Page header) -->
        <div class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1 class="m-0">Profile Settings</h1>
                    </div><!-- /.col -->
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-right">
                            <li class="breadcrumb-item"><a href="#">Home</a></li>
                            <li class="breadcrumb-item active">Profile Settings</li>
                        </ol>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.container-fluid -->
        </div>
        <!-- /.content-header -->
        <!-- Main content -->
        <div class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        @include('admin.layouts.partials.validation')
                        <div class="card">
                            <div class="card-header">
                                <a href="{{ route('admin.dashboard') }}" class="btn btn-info float-right"><i
                                        class="fas fa-list"></i> List</a>
                            </div>
                            <!-- /.card-header -->
                            <form id="quickForm" novalidate="novalidate" method="POST"
                                action="{{ route('admin.profile.update') }}" enctype="multipart/form-data">
                                @csrf
                                @method('put')
                                <div class="card-body">
                                    <div class="row">
                                        <div class="col-lg-12">

                                            <div class="row">
                                                <div class="col-sm-2">
                                                    <div class="form-group">
                                                        <label for="name"
                                                            class="control-label asterisk">Name</label>
                                                    </div>
                                                </div>
                                                <div class="col-sm-8">
                                                    <div class="form-group">
                                                        <div class="input-group">
                                                            <div class="input-group-prepend">
                                                                <span class="input-group-text"><i
                                                                        class="fas fa-pen"></i></span>
                                                            </div>
                                                            <input id="name" type="text" name="name"
                                                                value="{{ old('name', $user->name) }}"
                                                                placeholder="Enter name" class="form-control" />
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>


                                            <div class="row">
                                                <div class="col-sm-2">
                                                    <div class="form-group">
                                                        <label for="email"
                                                            class="control-label asterisk">Email</label>
                                                    </div>
                                                </div>
                                                <div class="col-sm-8">
                                                    <div class="form-group">
                                                        <div class="input-group">
                                                            <div class="input-group-prepend">
                                                                <span class="input-group-text"><i
                                                                        class="fas fa-pen"></i></span>
                                                            </div>
                                                            <input id="email" type="email" name="email"
                                                                value="{{ old('email', $user->email) }}"
                                                                placeholder="Enter email" class="form-control" />
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="row">
                                                <div class="col-sm-2">
                                                    <div class="form-group">
                                                        <label for="avatar"
                                                            class="control-label asterisk">Avatar</label>
                                                    </div>
                                                </div>
                                                <div class="col-sm-8">
                                                    <div class="form-group">
                                                        <div class="input-group">
                                                            <div class="input-group-prepend">
                                                                <span class="input-group-text"><i
                                                                        class="fas fa-pen"></i></span>
                                                            </div>
                                                            <input type="file" class="custom-file-input"
                                                                id="photo1" name="profile"
                                                                value="{{ $user->profile }}">
                                                            <label class="custom-file-label" for="photo1">File
                                                                Upload</label>
                                                        </div>
                                                    </div>

                                                    <div class="form-group">
                                                        <div class="mt-2 mb-4">
                                                            @if ($user->profile == null)
                                                                <img id="imgPreview" src="" alt="imgPreview"
                                                                    width="150px" height="150px"
                                                                    style="border:1px solid #000">
                                                            @else
                                                                <img src="/images/{{ $user->profile }}"
                                                                    alt="{{ $user->name }}" id="imgPreview"
                                                                    class="img-fluid" width="150px" height="150px">
                                                            @endif
                                                        </div>
                                                    </div>

                                                </div>
                                            </div>

                                        </div>
                                    </div>
                                </div>
                                <!-- /.card-body -->
                                <div class="card-footer">
                                    <div class="row">
                                        <div class="col-sm-2"></div>
                                        <div class="col-lg-4 col-6">
                                        </div>
                                        <div class="col-lg-4 col-6" style="text-align: end;">
                                            <button type="submit" class="btn btn-primary">Update</button>
                                        </div>
                                    </div>
                                </div>
                            </form>
                            <!-- /.card-body -->
                        </div>
                        <!-- /.card -->
                    </div>
                </div>
            </div>
        </div>

    </div>
    </div>

    @section('scripts')
        <script>
            $(document).ready(() => {
                $('#photo1').change(function() {
                    const file = this.files[0];
                    console.log(file);
                    if (file) {
                        let reader = new FileReader();
                        reader.onload = function(event) {
                            console.log(event.target.result);
                            $('#imgPreview').attr('src', event.target.result);
                        }
                        reader.readAsDataURL(file);
                    }
                });
            });
        </script>
    @endsection
</x-app-layout>
