<?php if( empty($user->payment_set) ) { ?>
<div class="u-popup popView" id="accountModel">
	<uni-view data-v-a75f7a08="" data-v-b2a05bc2="" data-v-30282a05="" class="van-overlay"></uni-view>
    <div class="guize_html" style="width:100%">
		<div class="Ikdcls g_close"><iconify-icon class="beautiful-text" width="45" height="45" icon="carbon:close-filled"></iconify-icon></div>
        <span class="guize_html_nei">
            <center style="margin-top: 10px;">
                <img style="width:100%;" src="{{ asset('users/assets/trade/img/account.png') }}" alt="external-46-business-and-investment-outline-design-circle"/>
            </center>
            <span style="margin-bottom: 20px;font-size: large;"><br>Kindly set your account details to enable you withdraw. Select from the <b>NAIRA</b> and <b>USDT</b> account to set. <b style="color:#F00">Note once set cannot not be changes.</b></span>

		</span>

        <div class="btnyu" style="width:100%;border-radius:0px;margin:10px auto 0px;height:50px;">
			<div class="nav" data-v-1ae6f7fb="" data-v-70859265="" style="border-radius: 0;height:100%">
				<div class="item linkBTN naira" data-href="{{ route('user.account-setup') }}" data-v-1ae6f7fb=""><span data-v-1ae6f7fb="">NAIRA</span></div>
				<div class="item linkBTN usdt" data-href="{{ route('user.usdt-setup')}}" data-v-1ae6f7fb=""><span data-v-1ae6f7fb="">USDT</span></div>
			</div>
        </div>
	</div>
</div>
<?php }else{ ?>
<div class="u-popup popView popCenter" id="withdrawModel">
	<uni-view data-v-a75f7a08="" data-v-b2a05bc2="" data-v-30282a05="" class="van-overlay"></uni-view>
    <div class="guize_html">
        <span class="guize_html_nei">
        @php
			$accountNumber = ($user->bankAccount) ? $user->bankAccount->account_number : 'CRYPTO';
			$accountName = ($user->bankAccount) ? explode(' ', $user->bankAccount->account_name)[0] : $user->withdrawal_usdt_address;
			$bankName = ($user->bankAccount) ? $user->bankAccount->bank_name : 'USDT';
        @endphp

			<div class="team-container !p-0 flex flex-col gap-y-2 !bg-transparent" style="margin-top:0px;margin-bottom:0px;">
				<div class="recharge-input" style="margin-top: -5px;background: none;">
					<div>
						<p class="text-semibold">{{ config('settings')->cur_sym }}</p>
						<input type="number" name="amount" class="amount withAmount" placeholder="Withdraw Amount">
						<iconify-icon class="beautiful-text" width="25" height="25" icon="uil:atm-card"></iconify-icon>
					</div>
				</div>

				<div class="recharge-input" style="margin-top: -18px;">
					<p class="label" style="padding:0px;font-weight: 600;">Withdraw to account</p>
					<div class="input-wrapper">
						<iconify-icon width="20" icon="mingcute:bank-card-line"></iconify-icon>
						<p>{{ $bankName }}</p>
						<div class="inner-input">
							<input type="text" placeholder="{{ $accountName }}" readonly/>
							{{--<iconify-icon width="20" icon="ph:play-fill"></iconify-icon>--}}
						</div>
					</div>
				</div>

				<?php if(config('settings')->debit_with == "balance"){ ?> 
				<input type="hidden" id="debit_with" value="1">
				<?php }elseif( config('settings')->debit_with == "income" ){ ?>
				<input type="hidden" id="debit_with" value="2">
				<?php }else{?>
				<input type="hidden" id="debit_with" value="3">
				<?php }?>

				@if( $user->withdrawal_password )
				<div class="recharge-input" style="margin-top: -18px;">
					<div>
						<input type="password" id="withPassword" class="password" placeholder="Transaction password">
						<iconify-icon class="beautiful-text" width="25" height="25" icon="mdi:security-lock-outline"></iconify-icon>
					</div>
				</div>
				@endif

				<div class="listCur" data-v-1ae6f7fb="" data-v-70859265="" style="width:95%;margin:0 auto;margin-top: -18px;">
				  <label for="radioWithUSDT" class="radio-card currency">
					<input type="radio" name="withdraw_method" id="radioWithUSDT" value="2" data-name="USDT" class="hidden"/>
					<div class="card-content-wrapper">
					  <span class="check-icon"></span>
					  <img class="currencyIcon" src="{{ asset('users/assets/trade/img/usd.svg') }}" alt="" />
					  <div class="card-content">
						<h4><span>method</span><span class="iUjsc">USD</span></h4>
					  </div>
					</div>
				  </label>
				  <label for="radioWithNGN" class="radio-card currency">
					<input type="radio" name="withdraw_method" id="radioWithNGN" value="1" checked data-name="KWACHA" class="hidden" />
					<div class="card-content-wrapper">
					  <span class="check-icon"></span>
					  <img class="currencyIcon" src="{{ asset('users/assets/trade/img/naira.svg') }}" alt="" />
					  <div class="card-content">
						<h4><span>method</span><span class="iUjsc">KWACHA</span></h4>
					  </div>
					</div>
				  </label>
				</div>
				@csrf
				
				<div class="charge-description" style="margin-top: -10px; padding: 5px;">
					{!! config('settings')->withdrawal_info !!}
				</div>
			</div>
        </span>
		
        <div class="btnyu" style="width:100%;border-radius:0px;">
			<div class="nav" data-v-1ae6f7fb="" data-v-70859265="" style="border-radius: 0;">
				<div class="item g_close" data-v-1ae6f7fb=""><span data-v-1ae6f7fb="">CANCEL</span></div>
				<button class="item on withdraw-btn" data-action="topup" data-v-1ae6f7fb=""><span data-v-1ae6f7fb="">WITHDRAW</span>&nbsp;<span id="current-value"></span></button>
			</div>
        </div>
    </div>
</div>
<?php } ?>
@push('script')
<script src="{{ asset('users/assets/trade/js/recharge-amount.js') }}"></script>

<script>
	<?php if(config('settings')->debit_with == "balance"){ ?> 
	var inNg = {{$user->balance}}; var inUS = {{$user->usdt_balance}};
	<?php }elseif( config('settings')->debit_with == "income" ){ ?>
	var inNg = {{$user->income}}; var inUS = {{$user->usdt_income}};
	<?php }else{?>
	var inNg = {{$user->balance + $user->income}}; var inUS = {{ $user->usdt_balance + $user->usdt_income }};
	<?php }?>
    $(".withdraw-btn").click(function() {

        // Form input Value
        var amount = $('.withAmount').val();
        var password = $('#withPassword').val();
		var withMethod = $("input[name='withdraw_method']:checked");
        var token = document.querySelector('input[name="_token"]').value;
        var currency = withMethod.data('name');
		var method = withMethod.val();
        var debit_from = $('#debit_with').val();

        // Enable form submit
        var is_status = true;
		
        // Verify input
        if (!amount) {
            modalMsg("Please enter or select amount");
            is_status = false;
        }

        if (!method) {
            modalMsg("Sorry, The currency to withdraw from");
            is_status = false;
        }

		<?php if( $user->withdrawal_password ){ ?>
        if (!password) {
            modalMessage("Please enter transaction password");
            is_status = false;
        }
		<?php } ?>

		if( currency == 'KWACHA'){
			if (amount > inNg) {
				modalMsg("Sorry, Your KWACHA Balance is lower. Bal: ₦"+inNg);
				is_status = false;
			}
		}

		if( currency == 'USDT'){
			if (amount > inUS) {
				modalMsg("Sorry, Your USDT Balance is lower. Bal: $"+inUS);
				is_status = false;
			}
		}
        // End Verify

        // Send Data
        if (is_status) {

            // AJAX POST
            $.ajax({
                type: "POST",
                url: "{{ route('user.withdraw.money') }}",
                data: {
                    amount: amount,
                    method: method,
                    currency: currency,
                    debit_from: debit_from,
                    password: password,
                    _token: token
                },
                beforeSend: function() {
                    // Handle before sending the request
					loading.showLoading({type: 2,tip: "Please wait..."});
                },
                success: function(data) {
                    // Handle successful request
                    loading.hideLoading();
                    modalMessage(data.message, 200, data.link);
                },
                error: function(xhr, status, error) {
                    var responseText = JSON.parse(xhr.responseText);
                    // Handle errors
                    loading.hideLoading();
                    modalMessage(responseText.message);
                },
                fail: function() {
                    // Handle failed requests
                    loading.hideLoading();
                    modalMessage("Request Failed");
                }
            });
        }

        return false;
    })
	
	<?php if( empty($user->payment_set) ) { ?>
	function withdraw(){
		$("body").addClass('van-overflow-hidden');
		$("#accountModel").slideDown();
	}
	<?php }else { ?>
	function withdraw(){
		$("body").addClass('van-overflow-hidden');
		$("#withdrawModel").slideDown();
	}
	<?php } ?>
	
</script>
@endpush