<?php
$checkType = ($type == 'confirm-order') ? 'order' :
                (($type == 'deposit') ? 'deposit' :
                (($type == 'withdrawal') ? 'withdrawal' :
                (($type == 'transfer') ? 'transfer' :
                (($type == 'bonus_purchase_pool') ? 'bonus_purchase_pool' :
                (($type == 'cancel_gift_code') ? 'cancel_gift_code' :
                (($type == 'redeem_gift_code') ? 'redeem_gift_code' :
                (($type == 'send_gift_code') ? 'send_gift_code' : 'login')))))));
$user = (Auth::check()) ? Auth::user() : Session::get('user_temp_data');
$userSetting = \App\Models\UserSetting::where('user_id',$user->id)->first();
$faSetting = $userSetting->fa_setting;
$fa3Setting = $userSetting->fa3_setting;
if(isset($MFPAuthType) && $MFPAuthType !== false){
    if ($MFPAuthType == 'otp') {
        $fa3Setting[] = 'login';
    } else {
        $faSetting[] = 'login';
    }
}
?>
<div data-action="{{ url('validate/2fa') }}" id="2fa3faValidateForm" class="m-auto" style="max-width: 300px;" onkeydown="return event.key != 'Enter';">
    @csrf
    <div class="row no-rows">
        <div class="col-12">
            <div class="mt-2">
                @if (!in_array($checkType, $faSetting) && in_array($checkType, $fa3Setting))
                    <input type="hidden" name="AuthType" value="otp">
                @else
                    <input type="hidden" name="AuthType" value="">
                @endif

                <input type="hidden" name="wallet_id" value="">
                <input type="hidden" name="type" value="{{ $type ?? '' }}">
                <input type="hidden" name="nextSubmittedFormId" value="{{ $nextSubmittedFormId ?? ''}}">

                {{----------------- Switch Btn -----------------}}
                @php $authentication2faDivClass = 'pb-2' @endphp
                @if (in_array($checkType, $faSetting) && in_array($checkType, $fa3Setting))
                @php $authentication2faDivClass = 'mb-4 pb-2' @endphp
                <div class="AuthMainSwitch mb-3">
                    <div class="backgroundPill"></div>
                    <button onclick="switchAuthenticationMethod('2fa')" type="button">{{ __('Google 2FA') }}</button>
                    <button onclick="switchAuthenticationMethod('otp')" type="button">{{ __('Email OTP') }}</button>
                </div>
                @endif
                {{----------------- Switch Btn -----------------}}
                @if (in_array($checkType, $faSetting))
                    <div id="authentication_2fa_div" class="{{ $authentication2faDivClass }}">
                        @if($checkType != 'login')
                            <h6 class="fs-6 fw-bold mb-1 text-start">{{ __('Your 6-digit authenticator code') }}</h6>
                        @endif
                        <div class="flex mb-2 rtl:space-x-reverse justify-content-between otp-input-group">
                            <div>
                                <input type="text"  inputmode="numeric" name="code[]" maxlength="1" data-focus-input-init data-focus-input-next="{{ $nextSubmittedFormId ?? '' }}code-2fa-2" id="{{ $nextSubmittedFormId ?? '' }}code-2fa-1" placeholder="0" class="Auth2faCodeInputs otp-inputs hide-placeholder-on-focus block w-10 h-10 py-3 text-sm text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"/>
                            </div>
                            <div>
                                <input type="text"  inputmode="numeric" name="code[]" maxlength="1" data-focus-input-init data-focus-input-prev="{{ $nextSubmittedFormId ?? '' }}code-2fa-1" data-focus-input-next="{{ $nextSubmittedFormId ?? '' }}code-2fa-3" id="{{ $nextSubmittedFormId ?? '' }}code-2fa-2" placeholder="0" class="Auth2faCodeInputs otp-inputs hide-placeholder-on-focus block w-10 h-10 py-3 text-sm text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"/>
                            </div>
                            <div>
                                <input type="text"  inputmode="numeric" name="code[]" maxlength="1" data-focus-input-init data-focus-input-prev="{{ $nextSubmittedFormId ?? '' }}code-2fa-2" data-focus-input-next="{{ $nextSubmittedFormId ?? '' }}code-2fa-4" id="{{ $nextSubmittedFormId ?? '' }}code-2fa-3" placeholder="0" class="Auth2faCodeInputs otp-inputs hide-placeholder-on-focus block w-10 h-10 py-3 text-sm text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"/>
                            </div>
                            <div>
                                <input type="text"  inputmode="numeric" name="code[]" maxlength="1" data-focus-input-init data-focus-input-prev="{{ $nextSubmittedFormId ?? '' }}code-2fa-3" data-focus-input-next="{{ $nextSubmittedFormId ?? '' }}code-2fa-5" id="{{ $nextSubmittedFormId ?? '' }}code-2fa-4" placeholder="0" class="Auth2faCodeInputs otp-inputs hide-placeholder-on-focus block w-10 h-10 py-3 text-sm text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"/>
                            </div>
                            <div>
                                <input type="text"  inputmode="numeric" name="code[]" maxlength="1" data-focus-input-init data-focus-input-prev="{{ $nextSubmittedFormId ?? '' }}code-2fa-4" data-focus-input-next="{{ $nextSubmittedFormId ?? '' }}code-2fa-6" id="{{ $nextSubmittedFormId ?? '' }}code-2fa-5" placeholder="0" class="Auth2faCodeInputs otp-inputs hide-placeholder-on-focus block w-10 h-10 py-3 text-sm text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"/>
                            </div>
                            <div>
                                <input type="text"  inputmode="numeric" name="code[]" maxlength="1" data-focus-input-init data-focus-input-prev="{{ $nextSubmittedFormId ?? '' }}code-2fa-5" id="{{ $nextSubmittedFormId ?? '' }}code-2fa-6" placeholder="0" class="Auth2faCodeInputs otp-inputs hide-placeholder-on-focus block w-10 h-10 py-3 text-sm text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"/>
                            </div>
                        </div>
                        <p class="float-end authLoader p-0 m-0" style="display: none"><i class="fa fa-spinner fa-spin"></i>&nbsp;&nbsp;{{ __('loading') }}...</p>
                        <p class="custom-error text-start p-0 m-0 text-danger code_error"></p>
                    </div>
                @endif
                @if (in_array($checkType, $fa3Setting))
                    <div id="authentication_otp_div" class="mb-4" @if (in_array($checkType, $faSetting)) style="display: none" @endif>
                        @if($checkType != 'login')
                            <h6 class="fs-6 fw-bold mb-1 text-start">{{ __('Your 6-digit email OTP') }}</h6>
                        @endif
                        <div class="flex mb-2 rtl:space-x-reverse justify-content-between otp-input-group">
                            <div>
                                <input type="text"  inputmode="numeric" name="otp[]" maxlength="1" data-focus-input-init data-focus-input-next="{{ $nextSubmittedFormId ?? '' }}otp-3fa-2" id="{{ $nextSubmittedFormId ?? '' }}otp-3fa-1" placeholder="0" class="Auth3faOTPInputs otp-inputs hide-placeholder-on-focus block w-10 h-10 py-3 text-sm text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"/>
                            </div>
                            <div>
                                <input type="text"  inputmode="numeric" name="otp[]" maxlength="1" data-focus-input-init data-focus-input-prev="{{ $nextSubmittedFormId ?? '' }}otp-3fa-1" data-focus-input-next="{{ $nextSubmittedFormId ?? '' }}otp-3fa-3" id="{{ $nextSubmittedFormId ?? '' }}otp-3fa-2" placeholder="0" class="Auth3faOTPInputs otp-inputs hide-placeholder-on-focus block w-10 h-10 py-3 text-sm text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"/>
                            </div>
                            <div>
                                <input type="text"  inputmode="numeric" name="otp[]" maxlength="1" data-focus-input-init data-focus-input-prev="{{ $nextSubmittedFormId ?? '' }}otp-3fa-2" data-focus-input-next="{{ $nextSubmittedFormId ?? '' }}otp-3fa-4" id="{{ $nextSubmittedFormId ?? '' }}otp-3fa-3" placeholder="0" class="Auth3faOTPInputs otp-inputs hide-placeholder-on-focus block w-10 h-10 py-3 text-sm text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"/>
                            </div>
                            <div>
                                <input type="text"  inputmode="numeric" name="otp[]" maxlength="1" data-focus-input-init data-focus-input-prev="{{ $nextSubmittedFormId ?? '' }}otp-3fa-3" data-focus-input-next="{{ $nextSubmittedFormId ?? '' }}otp-3fa-5" id="{{ $nextSubmittedFormId ?? '' }}otp-3fa-4" placeholder="0" class="Auth3faOTPInputs otp-inputs hide-placeholder-on-focus block w-10 h-10 py-3 text-sm text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"/>
                            </div>
                            <div>
                                <input type="text"  inputmode="numeric" name="otp[]" maxlength="1" data-focus-input-init data-focus-input-prev="{{ $nextSubmittedFormId ?? '' }}otp-3fa-4" data-focus-input-next="{{ $nextSubmittedFormId ?? '' }}otp-3fa-6" id="{{ $nextSubmittedFormId ?? '' }}otp-3fa-5" placeholder="0" class="Auth3faOTPInputs otp-inputs hide-placeholder-on-focus block w-10 h-10 py-3 text-sm text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"/>
                            </div>
                            <div>
                                <input type="text"  inputmode="numeric" name="otp[]" maxlength="1" data-focus-input-init data-focus-input-prev="{{ $nextSubmittedFormId ?? '' }}otp-3fa-5" id="{{ $nextSubmittedFormId ?? '' }}otp-3fa-6" placeholder="0" class="Auth3faOTPInputs otp-inputs hide-placeholder-on-focus block w-10 h-10 py-3 text-sm text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"/>
                            </div>
                        </div>
                        <p class="float-end authLoader p-0 m-0" style="display: none"><i class="fa fa-spinner fa-spin"></i>&nbsp;&nbsp;{{ __('loading') }}...</p>
                        <p class="custom-error text-start p-0 m-0 text-danger otp_error"></p>
                        <a href="javascript:void(0)" class="float-end text-end mb-2 mt-1 fs-6 text-primary fw-bold w-100" id="ResendOtpBtn">{{ __('Resend OTP') }}</a>
                    </div>
                @endif
            </div>
        </div>
        @if(isset($showModalCancelBtn) && $showModalCancelBtn == true)
            <div class="col-12">
                <button type="button" class="primarym-btn text-center mt1s w-50 btn-solid" data-dismiss="modal">{!! renderIconHtml('cancel') !!}{{ __('Close') }}</button>
            </div>
        @elseif(isset($cancelBtnHtml) && !empty($cancelBtnHtml))
            <div class="col-12">
                {!! $cancelBtnHtml !!}
            </div>
        @endif

        <div class="col-12 text-center" hidden>
            <button type="button" class="primarym-btn btn submitBtn w-100 w-full text-center mt1s btn-solid">{{ __('Authenticate') }}</button>
        </div>
    </div>
</div>
