@extends(Theme::viewName('layout'))
@section('title', trans('gallery.user_settings.title'))

@section('content')
    <div class="container">
        <div class="row">
            <div class="col-lg-8 mr-lg-auto ml-lg-auto">
                <div class="card">
                    <div class="card-header">
                        <ul class="nav nav-tabs card-header-tabs">
                            <li class="nav-item">
                                <a class="nav-link active" href="{{ url('/password/change') }}">@yield('title')</a>
                            </li>
                        </ul>
                    </div>
                    <div class="card-body">
                        @if ($user->is_email_change_in_progress)
                            <div class="alert alert-warning mb-4" role="alert">
                                <p>@lang('gallery.user_settings.change_email_in_progress', ['new_email_address' => $user->new_email_address])</p>
                                <form action="{{ route('userSettings.resetEmailChangeState') }}" method="post">
                                    {{ csrf_field() }}
                                    <button type="submit" class="btn btn-outline-info" name="resend_email">@lang('gallery.user_settings.change_email_resend')</button>
                                    <button type="submit" class="btn btn-outline-info" name="cancel_change">@lang('gallery.user_settings.cancel_email_change')</button>
                                </form>
                            </div>
                        @endif

                        <form action="{{ route('saveUserSettings') }}" method="post">
                            {{ csrf_field() }}

                            <div class="form-group row{{ $errors->has('name') ? ' has-danger' : '' }}">
                                <label class="col-md-4 col-form-label text-md-right" for="user-name">@lang('forms.name_label')</label>

                                <div class="col-md-6">
                                    <input type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" id="user-name" name="name" value="{{ old('name', $user->name) }}">

                                    @if ($errors->has('name'))
                                        <div class="invalid-feedback">
                                            <strong>{{ $errors->first('name') }}</strong>
                                        </div>
                                    @endif
                                </div>
                            </div>

                            <div class="form-group row{{ $errors->has('email') ? ' has-danger' : '' }}">
                                <label class="col-md-4 col-form-label text-md-right" for="user-email">@lang('forms.email_label')</label>

                                <div class="col-md-6">
                                    <input type="text" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" id="user-email" name="email" value="{{ old('email', $user->email) }}"{{ $user->is_email_change_in_progress ? ' readonly="readonly"' : '' }}>

                                    @if ($errors->has('email'))
                                        <div class="invalid-feedback">
                                            <strong>{{ $errors->first('email') }}</strong>
                                        </div>
                                    @endif
                                </div>
                            </div>

                            <div class="form-group row">
                                <div class="col-md-6 offset-md-4">
                                    <a href="{{ route('auth.changePassword') }}" class="btn btn-link"><i class="fa fa-lock"></i>&nbsp;&nbsp;@lang('gallery.user_settings.change_password')</a>
                                </div>
                            </div>

                            <fieldset class="mt-4">
                                <legend class="ml-md-5">Public profile</legend>

                                <div class="form-group row{{ $errors->has('profile_alias') ? ' has-danger' : '' }}">
                                    <label class="col-md-4 col-form-label text-md-right" for="profile-alias">@lang('forms.profile_alias_label')</label>

                                    <div class="col-md-6">
                                        <input type="text" class="form-control{{ $errors->has('profile_alias') ? ' is-invalid' : '' }}" id="profile-alias" name="profile_alias" value="{{ old('profile_alias', $user->profile_alias) }}">
                                        <small id="emailHelp" class="form-text text-muted">@lang('forms.profile_alias_help')</small>

                                        @if ($errors->has('profile_alias'))
                                            <div class="invalid-feedback">
                                                <strong>{{ $errors->first('profile_alias') }}</strong>
                                            </div>
                                        @endif
                                    </div>
                                </div>

                                <div class="form-group row">
                                    <div class="col-md-6 offset-md-4">
                                        <div class="form-check">
                                            <input type="checkbox" class="form-check-input" id="enable-profile-page" name="enable_profile_page"@if (old('enable_profile_page', $user->enable_profile_page)) checked="checked"@endif>
                                            <label class="form-check-label" for="enable-profile-page">@lang('forms.enable_profile_page_label')</label>
                                        </div>
                                    </div>
                                </div>
                            </fieldset>

                            <div class="text-right mt-5">
                                <a href="{{ route('home') }}" class="btn btn-link">@lang('forms.cancel_action')</a>
                                <button type="submit" class="btn btn-success"><i class="fa fa-fw fa-check"></i> @lang('forms.save_action')</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection