@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.verify.mobile') }}" method="POST" class="account-form verify-gcaptcha">
                    @csrf

                    <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('A 6 digit verification code sent to your mobile number') : +{{ showMobileNumber(auth()->user()->mobile) }}</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>
                            <p class="mt-3 fs-14">
                                @lang('If you don\'t get any code'), <span class="countdown-wrapper">@lang('try again after') <span id="countdown" class="fw-bold">--</span> @lang('seconds')</span> <a href="{{ route('user.send.verify.code', 'sms') }}" class="try-again-link d-none"> @lang('Try again')</a>
                            </p>
                            <a href="{{ route('user.logout') }}" class="fs-14 text--danger">@lang('Logout')</a>
                        </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('');
                }
            });

            var distance = Number("{{ isset($user->ver_code_send_at) ? $user->ver_code_send_at->addMinutes(2)->timestamp - time() : '' }}");
            var x = setInterval(function() {
                distance--;
                document.getElementById("countdown").innerHTML = distance;
                if (distance <= 0) {
                    clearInterval(x);
                    document.querySelector('.countdown-wrapper').classList.add('d-none');
                    document.querySelector('.try-again-link').classList.remove('d-none');
                }
            }, 1000);

        })(jQuery)
    </script>
@endpush
