<?php $__env->startSection('title'); ?>
    <?php echo app('translator')->getFromJson('Profile Settings'); ?> - <?php echo e(config('app.name')); ?>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('meta-tags'); ?>
    <meta name="description" content="<?php echo app('translator')->getFromJson('User Profile Settings'); ?>">
<?php $__env->stopSection(); ?>

<?php $__env->startSection('meta-tags-og'); ?>
    <meta property="og:url" content="<?php echo e(url()->current()); ?>" />
    <meta property="og:type" content="website" />
    <meta property="og:title" content="<?php echo app('translator')->getFromJson('User Profile Settings'); ?> - <?php echo e(config('app.name')); ?>" />
    <meta property="og:description" content="<?php echo app('translator')->getFromJson('View Or Change User Profile Settings'); ?>" />
    <meta property="og:image" content="<?php echo e(url('/img/'.config('settings.site_logo'))); ?>" />
<?php $__env->stopSection(); ?>

<?php $__env->startSection('styles'); ?>
    <?php echo $__env->make('partials.phone_style', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('sidebar'); ?>
    <?php echo $__env->make('includes.user-account-sidebar', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('above_content'); ?>
    <div class="breadcrumb">
        <div class="container">
            <div class="breadcrumb-inner">
                <ul class="list-inline list-unstyled">
                    <li><a href="<?php echo e(url('/')); ?>"><?php echo app('translator')->getFromJson('Home'); ?></a></li>
                    <li class="active"><?php echo app('translator')->getFromJson('Profile Settings'); ?></li>
                </ul>
            </div>
            <!-- /.breadcrumb-inner -->
        </div>
        <!-- /.container -->
    </div>
    <!-- /.breadcrumb -->
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <div class="col-md-9 user_account">
        <div class="shopping-cart">
            <div class="page-title">
                <h2><?php echo app('translator')->getFromJson('Profile Settings'); ?></h2>
            </div>
            <?php if(session()->has('profile_updated')): ?>
                <div class="alert alert-success alert-dismissible" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <?php echo e(session('profile_updated')); ?>

                </div>
            <?php endif; ?>
            <?php echo $__env->make('includes.form_errors', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

            <?php if(config('settings.phone_otp_verification')): ?>
                <?php if(!$user->mobile): ?>
                    <div class="col-sm-8 col-sm-offset-2">
                        <div class="text-danger">
                            <strong>
                                <?php echo app('translator')->getFromJson('Please add your phone number.'); ?>
                            </strong>
                        </div>
                    </div>
                <?php elseif(!$user->mobile->verified): ?>
                    <div class="col-sm-8 col-sm-offset-2">
                        <div class="verify-phone-block">
                        <span class="help-block">
                            <strong class="text-danger">
                                <?php echo app('translator')->getFromJson('Please verify your phone number.'); ?>
                            </strong>
                        </span>
                            <?php echo Form::open(['method'=>'post', 'action'=>'SendVerificationSMS@sendOtp', 'id'=>'send-otp-form']); ?>

                            <div class="form-group">
                                <?php echo Form::submit(__('Click here to send verification code to your phone.'), ['class'=>'btn-primary btn-link', 'name'=>'submit_button', 'id'=>'send-otp-btn']); ?>

                            </div>
                            <?php echo e(Form::close()); ?>

                            <div class="feedback-alert">
                                <br>
                                <div class="alert alert-info" role="alert">
                                    <span class="feedback"></span>
                                </div>
                            </div>
                        </div>
                        <div id="verify-phone"></div>
                    </div>
                <?php endif; ?>
            <?php endif; ?>

            <div class="col-sm-8 col-sm-offset-2 profile-setting-form">
                <?php echo Form::model($user, ['method'=>'patch', 'action'=>['FrontSettingsController@updateProfile'], 'onsubmit'=>'submit_button.disabled = true; submit_button.value = "' . __('Please Wait...') . '"; return true;', 'id'=>'update-profile-form']); ?>


                <div class="form-group<?php echo e($errors->has('name') ? ' has-error' : ''); ?>">
                    <?php echo Form::label('name', __('Name:')); ?>

                    <?php echo Form::text('name', null, ['class'=>'form-control', 'placeholder'=>__('Enter name'), 'required']); ?>

                </div>

                <div class="form-group<?php echo e($errors->has('username') ? ' has-error' : ''); ?>">
                    <?php echo Form::label('username', __('Username:')); ?>

                    <?php echo Form::text('username', null, ['class'=>'form-control', 'placeholder'=>__('Enter username'), 'required']); ?>

                </div>

                <div class="form-group<?php echo e($errors->has('email') ? ' has-error' : ''); ?>">
                    <?php echo Form::label('email', __('Email:')); ?>

                    <?php echo Form::email('email', null, ['class'=>'form-control', 'placeholder'=>__('Enter email'), 'required']); ?>

                </div>

                <?php if(config('settings.phone_otp_verification')): ?>
                    <div class="form-group<?php echo e($errors->has('phone') ? ' has-error' : ''); ?>">
                        <?php echo Form::label('phone-number','Phone Number:'); ?>

                        <input type="text" name="phone-number" id="phone-number" class="form-control"
                               value="<?php echo e(old('phone') ? old('phone') : ($user->mobile ? $user->mobile->number : null)); ?>"
                               placeholder="Enter your phone number">
                    </div>
                <?php endif; ?>

                <div class="form-group<?php echo e($errors->has('password') ? ' has-error' : ''); ?>">
                    <?php echo Form::label('password', __('Password:')); ?>

                    <?php echo Form::password('password', ['class'=>'form-control', 'placeholder'=>__('Enter password')]); ?>

                </div>

                <div class="form-group<?php echo e($errors->has('password') ? ' has-error' : ''); ?>">
                    <?php echo Form::label('password_confirmation', __('Confirm Password:')); ?>

                    <?php echo Form::password('password_confirmation', ['class'=>'form-control', 'placeholder'=>__('Enter password again')]); ?>

                </div>

                <div class="form-group">
                    <button type="submit" class="btn  btn-block" name="submit_button" id="update_btn"> <?php echo app('translator')->getFromJson('Update Profile'); ?>
                    </button>

                </div>

                <?php echo Form::close(); ?>

            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
    <?php echo $__env->make('partials.phone_script', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
    <script>
        var updateProfileForm = $('#update-profile-form');
        var oldEmail = updateProfileForm.find('input[name="email"]').val();
        $(document).on('click', '#update_btn', function (event) {
            event.preventDefault();
            var newEmail = updateProfileForm.find('input[name="email"]').val();
            if (oldEmail != newEmail) {
                if (confirm('<?php echo app('translator')->getFromJson('You have requested to change your email. An activation link will be sent to'); ?> "' + newEmail + '". <?php echo app('translator')->getFromJson('You are going to logout. Click Ok to confirm.'); ?>')) {
                    updateProfileForm.submit();
                }
            } else {
                updateProfileForm.submit();
            }
        });


        $.ajaxSetup({
            headers: {
                'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
            }
        });

        var sendOtpBtn = $('#send-otp-btn');
        var feedback = $('.feedback');
        var feedbackAlert = $('.feedback-alert');
        feedbackAlert.hide();
        $(document).on('submit', '#send-otp-form', function (e) {

            e.preventDefault();
            var data = $(this).serialize();
            var url = $(this).attr('action');

            sendOtpBtn.attr("disabled", "disabled");

            $.post(url, data, function (receivedData) {
                if (!receivedData.error) {
                    if (receivedData.sent) {
                        feedback.html('Verification code was sent to ' + receivedData.number);
                        var ajaxurl = '<?php echo e(route('auth.sms.verify.form')); ?>';
                        $.ajax({
                            url: ajaxurl,
                            type: "GET",
                            success: function (data) {
                                $data = $(data);
                                $('#verify-phone').hide().html($data).fadeIn();
                            }
                        });
                    } else {
                        if (receivedData.message) {
                            feedback.html(receivedData.message);
                        } else {
                            feedback.html('Error occurred while sending verification code. Please try again after some time.');
                        }
                    }
                    feedbackAlert.show();
                } else {
                    feedbackAlert.show();
                    feedback.html('Something went wrong.');
                }

                sendOtpBtn.removeAttr("disabled");
            });

        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.front', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>