@extends($activeTemplate . 'layouts.app')

@section('panel')
    <main>
        <div class="account-section bg-img" data-background-image="{{ asset('assets/images/account-bg.png') }}">
            @include('Template::user.auth.auth_sidebar')

            <div class="account-content">
                <form action="{{ route('user.password.verify.code') }}" method="POST" class="account-form verify-gcaptcha">
                    @csrf
                    <input type="hidden" name="email" value="{{ $email }}">
                    
                    <div class="verification-code-wrapper">
                        <div class="verification-area">
                            <div class="account-heading">
                                <a href="{{ route('home') }}" class="account-heading__logo">
                                    <img class="logo-img" src="{{ siteLogo() }}" alt="Logo">
                                </a>
                                <h3 class="account-heading__title">{{ __($pageTitle) }}</h3>
                                <h5 class="account-heading__text">@lang('Enter the verification code from your email.')</h5>
                            </div>
                            <div class="verification-code">
                                <input type="text" name="code" class="overflow-hidden" autocomplete="off">
                                <div class="boxes">
                                    <span>-</span>
                                    <span>-</span>
                                    <span>-</span>
                                    <span>-</span>
                                    <span>-</span>
                                    <span>-</span>
                                </div>
                            </div>
                            <button type="submit" class="btn btn--base mt-3 w-100 btn--md">@lang('Submit')</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

    </main>
@endsection

@push('script')
    <script>
        (function($) {
            'use strict';
            $('[name=code]').on('input', function() {

                $(this).val(function(i, val) {
                    if (val.length == 6) {
                        $('form').find('button[type=submit]').html('<i class="las la-spinner fa-spin"></i>');
                        $('form').find('button[type=submit]').removeClass('disabled');
                        $('form')[0].submit();
                    } else {
                        $('form').find('button[type=submit]').addClass('disabled');
                    }
                    if (val.length > 6) {
                        return val.substring(0, val.length - 1);
                    }
                    return val;
                });

                for (let index = $(this).val().length; index >= 0; index--) {
                    $($('.boxes span')[index]).html('');
                }
            });

        })(jQuery)
    </script>
@endpush
