<?php $__env->startSection('content'); ?>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"
        integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="
        crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    </head>

    <form action="" method="post">
        <?php echo csrf_field(); ?>
        <input type="hidden" name="balance" value="2">
        <input type="hidden" name="method_code" value="1">

        <body>
            <div class="bank-wrap">
                <div class="navbar">
                    <span onclick="onBack()">
                        <i></i>
                    </span>
                    
                </div>
                <h1>Bank Account</h1>
                

                <div class="list-wrap">
                    <ul class="uls">

                        <?php if(auth()->user()->bankAccount): ?>
                            <li>
                                <input type="text" placeholder="Bank Name" class="w-full" data-v-fde8aada=""
                                    value="<?php echo e(auth()->user()->bankAccount->bank_name); ?>" readonly><!---->
                            </li>

                            <li>
                                <input type="number" placeholder="Your Account Number" data-v-fde8aada=""class="w-full"
                                    value="<?php echo e(auth()->user()->bankAccount->account_number); ?>" readonly><!---->
                            </li>

                            <input type="hidden" name="bank_name" id="bank_code">

                            <span style="color:
                            red;"
                                class="text-danger text-error block"></span>

                            <li>
                                <input name="account_name" id="account_name"
                                    value="<?php echo e(auth()->user()->bankAccount->account_name); ?>" data-v-fde8aada=""
                                    type="text" placeholder="Your Name" class="w-full" readonly><!---->
                            </li>
                        <?php else: ?>
                            <li>

                                <select data-v-fde8aada="" class=" flex1 w-full" name="bank_code" id="bank_name">
                                    <option value="">-- Choose Bank --</option>
                                    <?php $__currentLoopData = $banks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $bank): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($bank['bank_code']); ?>"><?php echo e($bank['name']); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </li>

                            <li class="li">
                                <input type="number" name="account_number" id="account" placeholder="Your Account Number"
                                    class="w-full">
                                <b class="close"></b>
                            </li>

                            <input type="hidden" name="bank_name" id="bank_code">
                            <span style="color:
                            red;"
                                class="text-danger text-error block"></span>

                            <li>
                                <input name="account_name" id="account_name" data-v-fde8aada="" type="text"
                                    placeholder="Your Name" class="w-full" readonly required>
                            </li>
                        <?php endif; ?>

                    </ul>
                    <style>
                        .test {
                            height: 200px;
                            width: 300px;
                        }
                    </style>
                    <center>


                        <button id="reg" disabled type="submit" class="btn test">Submit</button>

                    </center>

                </div>


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

<?php $__env->startPush('script-lib'); ?>
    <textarea style="display: none;" id="all_banks"><?php echo $all_banks; ?></textarea>

    <script>
        let all_banks = JSON.parse($("#all_banks").val());
        //console.info(all_banks);
        (function($) {
            "use strict";

            function getByValue(value) {

                let arr = all_banks;
                for (var i = 0, iLen = arr.length; i < iLen; i++) {
                    //console.log(arr[i]);
                    if (arr[i].bank_code == value) return arr[i].name;
                }
            }


            $("#bank_name").change(function(e) {
                //alert($(this).val());
                //let code = $("#bank_name").val(); //getByValue().bank_code;
                //let account = $("#account").val();

                //console.log(t, code);


                let code = $("#bank_name").val(); //getByValue().bank_code;
                let account = $("#account").val();

                //console.log(code, account);

                let t = getByValue(code);

                //console.log(t);

                $("#bank_code").val(t);
                if (account != "" && code != "") {

                    get_account_info(code, account);

                    //console.log(account, code);
                }

            });

            $("#account").change(function() {

                let code = $("#bank_name").val(); // getByValue($("#bank_name").val()).bank_code;
                let account = $("#account").val();
                if (account == "" || code == "") {
                    $("#reg").prop('disabled', true);
                    $("#account_name").val("");
                    $(".text-error").text("Your bank name and account number are required, please try again");
                    return;
                }

                get_account_info(code, account);

                //console.log(account, code);


            });





            function get_account_info(code, account) {

                $(".preloaders").show();
                $(".text-error").text("Fetching account details");

                $.ajax({
                    url: "<?php echo e(route('account.fetch')); ?>",
                    type: 'get',
                    dataType: 'json',
                    data: {
                        'bank-verification': '',
                        'code': code,
                        'account': account
                    },
                    success: function(response) {
                        if (response.status == "error") {
                            $("#account_name").val("");
                            $(".preloaders").hide();
                            $(".text-error").text(
                                "Could not resolve account name, please check your account number or bank name and try again"
                            );
                            $("#reg").prop('disabled', true);
                            return;
                        }

                        $(".text-error").text("");
                        $("#reg").removeAttr('disabled');
                        $(".preloaders").hide();
                        console.log(response.data);
                        $("#account_name").val(response.data.account_name);

                        //console.log(response);
                    },

                    error: function(err) {
                        console.log(err.responseText);
                        $(".preloaders").hide();
                    }
                });
            }

            $('.withdraw-thumbnail').hide();
            $('.clickBtn').on('click', function() {
                var classNmae = $('.fileinput').attr('class');
                if (classNmae != 'fileinput fileinput-exists') {
                    $('.withdraw-thumbnail').hide();
                } else {
                    $('.fileinput-preview img').css({
                        "width": "100%",
                        "height": "300px",
                        "object-fit": "contain"
                    });

                    $('.withdraw-thumbnail').show();
                }

            });

        })(jQuery);
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.users', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /Applications/AMPPS/www/forge/core/resources/views/templates/basic/user/bank-setup.blade.php ENDPATH**/ ?>