<?php $__env->startSection('page_title',__('Request Money')); ?>

<?php $__env->startSection('content'); ?>
<div class="main-content">
	<section class="section">
		<div class="section-header">
			<h1><?php echo app('translator')->get('Request Money'); ?></h1>
			<div class="section-header-breadcrumb">
				<div class="breadcrumb-item active">
					<a href="<?php echo e(route('user.dashboard')); ?>"><?php echo app('translator')->get('Dashboard'); ?></a>
				</div>
				<div class="breadcrumb-item"><?php echo app('translator')->get('Request Money'); ?></div>
			</div>
		</div>

            <!------ alert ------>
            <div class="row ">
                <div class="col-md-12">
                    <div class="bd-callout bd-callout-primary mx-2">
                        <i class="fa-3x fas fa-info-circle text-primary"></i> <?php echo app('translator')->get(@$template->description->short_description); ?>
                    </div>
                </div>
            </div>


		<div class="row mb-3">
			<div class="container-fluid" id="container-wrapper">
				<div class="row justify-content-md-center">
					<div class="col-md-12">
						<div class="card card-primary shadow mb-4">
							<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
								<h6 class="m-0 font-weight-bold text-primary"><?php echo app('translator')->get('Request Money'); ?></h6>
							</div>
							<div class="card-body">
								<form action="<?php echo e(route('requestMoney.initialize')); ?>" method="post">
									<?php echo csrf_field(); ?>
									<div class="form-group">
										<label for="recipient"><?php echo app('translator')->get('Recipient email or username'); ?></label>
										<input type="text" name="recipient" id="recipient"
											   placeholder="<?php echo app('translator')->get('Please enter valid email or username'); ?>" autocomplete="off"
											   value="<?php echo e(old('recipient')); ?>"
											   class="form-control <?php $__errorArgs = ['recipient'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>">
										<div class="invalid-feedback">
											<?php $__errorArgs = ['recipient'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <?php echo app('translator')->get($message); ?> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
										</div>
										<div class="valid-feedback"></div>
									</div>
									<div class="row">
										<div class="col-md-6">
											<div class="form-group search-currency-dropdown">
												<label for="currency"><?php echo app('translator')->get('Currency'); ?></label>
												<select id="currency" name="currency"
														class="form-control <?php $__errorArgs = ['currency'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>">
													<?php $__currentLoopData = $currencies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $currency): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
														<option value="<?php echo e($currency->id); ?>"
																data-currencytype="<?php echo e($currency->currency_type); ?>" <?php echo e(($currency->is_default == 1) ? 'selected' : ''); ?>>
															<?php echo e(__($currency->code)); ?> - <?php echo e(__($currency->name)); ?></option>
													<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
												</select>
												<div class="invalid-feedback">
													<?php $__errorArgs = ['currency'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <?php echo app('translator')->get($message); ?> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
												</div>
											</div>
										</div>
										<div class="col-md-6">
											<div class="form-group">
												<label for="amount"><?php echo app('translator')->get('Amount'); ?></label>
												<input type="text" id="amount" value="<?php echo e(old('amount')); ?>" name="amount"
													   placeholder="<?php echo app('translator')->get('0.00'); ?>"
													   class="form-control <?php $__errorArgs = ['amount'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
													   autocomplete="off">
												<div class="invalid-feedback">
													<?php $__errorArgs = ['amount'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <?php echo app('translator')->get($message); ?> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
												</div>
												<div class="valid-feedback"></div>
											</div>
										</div>
									</div>
									<div class="form-group">
										<label for="note"><?php echo app('translator')->get('Note'); ?></label>
										<textarea name="note" rows="5" class="form-control form-control-sm"></textarea>
									</div>
									<div class="form-group mt-3 security-block">
										<?php if(in_array('request',$enable_for)): ?>
											<label for="security_pin"><?php echo app('translator')->get('Security Pin'); ?></label>
											<input type="password" name="security_pin"
												   placeholder="<?php echo app('translator')->get('Please enter your security PIN'); ?>" autocomplete="off"
												   value="<?php echo e(old('security_pin')); ?>"
												   class="form-control <?php $__errorArgs = ['security_pin'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>">
											<div class="invalid-feedback">
												<?php $__errorArgs = ['security_pin'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <?php echo app('translator')->get($message); ?> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
											</div>
											<div class="valid-feedback"></div>
										<?php endif; ?>
									</div>
									<button type="submit" id="submit" class="btn btn-primary btn-sm btn-block"
											disabled><?php echo app('translator')->get('Request Money'); ?></button>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>

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

<?php $__env->startSection('scripts'); ?>
    <script>
        'use strict';
        $(document).ready(function () {
            let recipientField = $('#recipient');
            let amountField = $('#amount');
            let recipientStatus = false;
            let amountStatus = false;

            function clearMessage(fieldId) {
                $(fieldId).removeClass('is-valid')
                $(fieldId).removeClass('is-invalid')
                $(fieldId).closest('div').find(".invalid-feedback").html('');
                $(fieldId).closest('div').find(".is-valid").html('');
            }

            //for receiver check
            $(document).on('input', "#recipient", function (e) {
                let recipient = $(recipientField).val();
                if (recipient === '') {
                    clearMessage(recipientField)
                }
                if (recipient.length >= 4) {
                    checkRecipient();
                }
            });

            function checkRecipient() {
                $.ajax({
                    method: "GET",
                    url: "<?php echo e(route('requestMoney.checkRecipient')); ?>",
                    dataType: "json",
                    data: {
                        'recipient': recipientField.val()
                    }
                })
                    .done(function (response) {
                        if (response.status) {
                            clearMessage(recipientField)
                            $(recipientField).addClass('is-valid')
                            $(recipientField).closest('div').find(".valid-feedback").html(response.message)
                            recipientStatus = true;
                            submitButton()
                        } else {
                            recipientStatus = false;
                            submitButton()
                            clearMessage(recipientField)
                            $(recipientField).addClass('is-invalid')
                            $(recipientField).closest('div').find(".invalid-feedback").html(response.message);
                        }
                    });
            }

            //for amount limit check
            $(document).on('change, input', "#amount, #charge_from, #currency", function (e) {
                let amount = amountField.val();
                let currency_id = $('#currency').val();
                let transaction_type_id = "<?php echo e(config('transactionType.request')); ?>"; //request
                let currency_type = $('#currency option:selected').data('currencytype');
                let charge_from = 0;
                if ($("#charge_from").is(':checked')) {
                    charge_from = 1;
                }

                if (!isNaN(amount) && amount > 0) {
                    let fraction = amount.split('.')[1];
                    let limit = currency_type == 0 ? 8 : 2;

                    if (fraction && fraction.length > limit) {
                        amount = (Math.floor(amount * Math.pow(10, limit)) / Math.pow(10, limit)).toFixed(limit);
                        amountField.val(amount);
                    }
                    checkAmount(amount, currency_id, transaction_type_id, charge_from)
                } else {
                    clearMessage(amountField);
                    $('.showCharge').html('');
                }
            });

            function checkAmount(amount, currency_id, transaction_type_id, charge_from) {
                $.ajax({
                    method: "GET",
                    url: "<?php echo e(route('requestMoney.checkAmount')); ?>",
                    dataType: "json",
                    data: {
                        'amount': amount,
                        'currency_id': currency_id,
                        'transaction_type_id': transaction_type_id,
                        'charge_from': charge_from,
                    }
                })
                    .done(function (response) {
                        let amountField = $('#amount');
                        if (response.status) {
                            clearMessage(amountField)
                            $(amountField).addClass('is-valid')
                            $(amountField).closest('div').find(".valid-feedback").html(response.message)
                            amountStatus = true;
                            submitButton()
                        } else {
                            amountStatus = false;
                            submitButton()
                            clearMessage(amountField)
                            $(amountField).addClass('is-invalid')
                            $(amountField).closest('div').find(".invalid-feedback").html(response.message);
                        }
                    });
            }

            function submitButton() {
                if (recipientStatus && amountStatus) {
                    $("#submit").removeAttr("disabled");
                } else {
                    $("#submit").attr("disabled", true);
                }
            }
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('user.layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH E:\xamp\htdocs\Paysecure-wallet\project\resources\views/user/requestMoney/create.blade.php ENDPATH**/ ?>