@extends('adminlte::page')

@section('title', config('app.name') . ' | ' . __('Profile'))

@section('content_header')

    <h4>{{__('Profile')}} / {{__('Settings')}}</h4>

@stop

@section('css')

    <link rel="stylesheet" href="/css/profile.css">

@stop

@section('js')

    @if (session()->has('success'))

        <script>
            toastr.success("{{session('success')}}")
        </script>

    @elseif(session()->has('error'))

        <script>
            toastr.error("{{session('error')}}")
        </script>

    @endif

@stop

@section('content')


    @if (!is_null($profile))

        <x-modal id="deleteProfileConfirmationModal" modal-label="deleteProfileConfirmationModal" modal-title="{{ __('Please confirm') }}" include-close-button="true">

            <p>{{ __('Deleting your profile is an irreversible operation. You will not be able to recover any previously entered information.') }}</p>
            <p>{{ __('After you delete your profile, the following will happen:') }}</p>

            <ul>
                <li>{{ __('Your account will no longer be listed on the public Directory page.') }}</li>
                <li>{{ __('Your profile page will become inaccesible to everyone with an error message.') }}</li>
                <li>{{ __('Your profile configuration page will become inaccessible with an error message.') }}</li>
                <li>{{ __('In a future update, the public Directory page might become inaccessible to users without a profile.') }}</li>
            </ul>

            <p>{{ __('If you change your mind and want your profile back, you will be able to create a new blank profile from your profile configuration page, restoring access to the features mentioned above.') }}</p>
            <p>{{ __('Are you sure you want to delete your profile?') }}</p>

            <x-slot name="modalFooter">
                <form name="deleteProfileConfirmation" method="post" action="{{ route('deleteProfile') }}">
                    @csrf
                    @method('DELETE')
                    <x-button type="submit" color="danger" icon="fas fa-trash" id="deleteProfileConfirmationBtn">{{ __('Yes, delete my profile') }}</x-button>
                </form>
            </x-slot>

        </x-modal>

        <div class="row">

            <div class="col">

            </div>

            <div class="col">

                <div class="card card-primary card-outline">
                    <div class="card-body box-profile">
                        <div class="text-center">
                            @if($profile->avatarPreference == 'gravatar')
                                <img class="profile-user-img img-fluid img-circle" src="https://gravatar.com/avatar/{{md5(Auth::user()->email)}}" alt="{{ __('User profile picture') }}">
                            @else
                                <img class="profile-user-img img-fluid img-circle" src="https://crafatar.com/avatars/{{Auth::user()->uuid}}" alt="{{ __('User profile picture') }}">
                            @endif
                        </div>

                        <h3 class="profile-username text-center">{{Auth::user()->name}}</h3>

                        <p class="text-muted text-center">{{$profile->profileShortBio}}</p>

                        <div class="text-center">

                            <button type="button" class="btn btn-sm btn-success" onclick="window.location.href='{{route('showSingleProfile', ['user' => Auth::user()->id])}}'"><i class="fas fa-eye"></i></button>

                        </div>
                    </div>

                    <div class="card-footer text-center">

                        <a href="https://github.com/{{$github}}" class="pr-2 pl-2"><i class="fab fa-github fa-2x"></i></a>
                        <a href="#" onclick="toastr.info('{{__('Discord tag: :discordTag', ['discordTag' => $discord])}}')" class="pr-2 pl-2"><i class="fab fa-discord fa-2x"></i></a>
                        <a href="https://twitter.com/{{$twitter}}" class="pr-2 pl-2"><i class="fab fa-twitter fa-2x"></i></a>
                        <a href="https://instagram.com/{{$insta}}" class="pr-2 pl-2"><i class="fab fa-instagram fa-2x"></i></a>

                    </div>

                    <!-- /.card-body -->
                </div>

            </div>


            <div class="col">


            </div>

        </div>


        <form method="POST" action="{{route('saveProfileSettings')}}" id="saveProfileSettings">

            @method('PATCH')
            @csrf

            <div class="row mt-3">

                <div class="col">

                    <div class="card">

                        <div class="card-header">

                            <div class="card-title"><h3>{{__('Basic Information')}}</h3></div>

                        </div>

                        <div class="card-body">

                            <div class="row">

                                <div class="col">

                                    <label for="firstName">{{__('First / Last name')}}</label>
                                    <input disabled type="text" class="form-control" id="firstName" value="{{Auth::user()->name}}">

                                </div>

                            </div>

                            <div class="form-group mt-3">

                                <label for="shortBio">{{__('Short bio')}}</label>
                                <input  type="text" name="shortBio" id="shortBio" class="form-control" value="{{$profile->profileShortBio}}">

                            </div>

                            <div class="form-group mt-3">

                                <label for="dob">{{__('Date of birth')}}</label>
                                <input type="text" disabled name="dob" id="dob" class="form-control" value="{{ (is_null($profile->user->dob)) ? __('Not set yet') : __(':dob (:age yrs old)', ['dob' => $profile->user->dob, 'age' => \Carbon\Carbon::parse($profile->user->dob)->age]) }}">

                            </div>

                            <div class="form-group mt-3">

                                <label for="aboutMe">{{__('About me')}}</label>
                                <textarea name="aboutMe" id="aboutMe" rows="8" class="form-control">{{$profile->profileAboutMe}}</textarea>
                                <p class="text-muted"><a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet">{{__('Markdown supported')}}</a></p>

                            </div>

                        </div>

                    </div>

                </div>

                <div class="col">

                    <div class="card">

                        <div class="card-header">
                            <div class="card-title"><h3>{{__('Preferences & Media')}}</h3></div>
                        </div>

                        <div class="card-body">

                            <label>{{__('Retrieve avatar from: ')}} </label>

                            <div class="form-group mb-3">

                                <label>
                                    <input type="radio" name="avatarPref" value="MOJANG" {{($profile->avatarPreference == 'crafatar') ? 'checked' : ''}}>
                                    <img alt="{{ __('Mojang Logo (Minecraft)') }}" height="150px" width="150px" src="data:image/svg+xml;utf8;base64, ">
                                </label>

                                <label>
                                    <input type="radio" name="avatarPref" value="GRAVATAR" {{($profile->avatarPreference == 'gravatar') ? 'checked' : ''}}>
                                    <img alt="{{ __('Gravatar logo') }}" src="/img/gravatar.png">
                                </label>

                            </div>

                            <label>{{__('Social Media')}}</label>

                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <span class="input-group-text"><i class="fab fa-github"></i></span>
                                </div>
                                <input name="socialGithub" type="text" class="form-control" placeholder="{{__('GitHub Username')}}" value="{{$github}}">
                            </div>

                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <span class="input-group-text"><i class="fab fa-discord"></i></span>
                                </div>
                                <input name="socialDiscord" type="text" class="form-control" placeholder="{{__('Discord Handle')}}" value="{{$discord}}">
                            </div>

                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <span class="input-group-text"><i class="fab fa-twitter"></i></span>
                                </div>
                                <input name="socialTwitter" type="text" class="form-control" placeholder="{{__('Twitter Username')}}" value="{{$twitter}}">
                            </div>

                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <span class="input-group-text"><i class="fab fa-instagram"></i></span>
                                </div>
                                <input name="socialInsta" type="text" class="form-control" placeholder="{{__('Instagram Username')}}" value="{{$insta}}">
                            </div>

                        </div>

                    </div>

                </div>

            </div>

            <div class="row mt-3 mb-5">

                <div class="col text-right">
                    <button type="button" class="btn btn-success" onclick="document.getElementById('saveProfileSettings').submit()"><i class="fas fa-save"></i> {{__('Update Profile')}}</button>
                </div>

                <div class="col text-left">
                    <button type="button" class="btn btn-warning" onclick="$('#deleteProfileConfirmationModal').modal('show')"><i class="fas fa-exclamation-triangle"></i> {{ __('Delete Profile') }}</button>
                </div>

            </div>

        </form>

    @else

        <div class="row">

            <div class="col">
                <x-card id="noProfile" card-title="{{ __('Create a profile') }}" footer-style="">

                    <x-slot name="cardHeader"></x-slot>

                    <x-alert alert-type="danger" title="{{ __('No profile found!') }}" icon="fa-user-alt-slash">
                        <p>{{ __("Your account currently has no profile on file. This means that your account will not be visibile in the public profile Directory, and you will not be able to access your profile until you create one.") }}</p>
                        <p>{{ __("There are many benefits to creating a profile! For instance, you'll be able to set a profile picture, as well as sharing your social media and anything else you'd like. Creating a profile is instant and you can begin configuring it right away. If you later change your mind, you may also delete your profile at any time.") }}</p>
                    </x-alert>

                    <x-slot name="cardFooter">
                        <form name="createProfile" method="post" action="{{ route('createProfile') }}">
                            @csrf
                            <x-button type="submit" color="success" icon="fas fa-plus" size="sm" id="createProfile" link="#" target="_blank">{{ __('Create profile') }}</x-button>
                        </form>
                    </x-slot>
                </x-card>
            </div>

        </div>

    @endif

@stop
@section('footer')
    @include('breadcrumbs.dashboard.footer')
@stop
