<?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>



    <body style="background-size: 100% auto; background: #f1f1f1;">
        <input type="hidden" id="_bank_t3" value="" />
        <div style=" max-width:450px; margin:0 auto; height:auto; overflow:hidden;">
            <div class="top" style="background:#000;">
                <div style="float:left; line-height:46px;width:50%;">
                    <i class="layui-icon" style="color:#fff;  margin-left:12px; font-size:18px;  font-weight:bold;"
                        id="btnClose">&#xe603;</i>
                </div>
                <font class="topname" id="topname1" style="color: #fff;">
                    Add a bank account
                </font>
                <div style="float:right; text-align:right; line-height:46px;width:50%;">

                </div>
            </div>

            <div style=" max-width:450px; margin:0 auto; height:auto; overflow:hidden;">

                <?php if(auth()->user()->bankAccount): ?>
                    <div class="layui-form layui-tab-content" style="padding:10px 10px; margin-top:50px;">

                        <h4 align="center" style="color: white;">Account Details</h4>

                        <p>
                            Account Name: <?php echo e(auth()->user()->bankAccount->account_name); ?>

                        </p>

                        <p>
                            Account Number: <?php echo e(auth()->user()->bankAccount->account_number); ?>

                        </p>

                        <p>
                            Bank Name: <?php echo e(auth()->user()->bankAccount->bank_name); ?>

                        </p>

                    </div>
                <?php else: ?>
                    <div class="layui-form layui-tab-content" style="padding:10px 10px; margin-top:50px;">
                        <div
                            style="width:80%; margin:0 auto;height:40px; text-align:center; padding-bottom:20px; display:none; line-height:40px;">
                            <div style="float: left; width: 50%; color: #000; " class="tabs" value="1">
                                Bank account
                                <hr style="background:rgb(12,149,179); height:2px; width:60%;margin:0 auto;"
                                    id="tab1" />
                            </div>
                        </div>
                        <div style="background: #fff; border-radius: 10px;">
                            <form action="" method="post" class="layui-form" style="padding:10px;">
                                <?php echo csrf_field(); ?>
                                <div style="padding-top: 10px;">&nbsp;</div>
                                <div id="l1"
                                    style=" text-align: left; padding-bottom: 10px;  color: #0F0F0F; font-family: DengXian; ">
                                    *Select bank</div>
                                <div id="l2" class="layui-form-item"
                                    style="height:45px; border-radius: 15px !important;">
                                    <div class="layui-input-block"
                                        style=" border: 2px solid #D2D2D2 !important; border-radius: 15px !important;margin-left:20px;">
                                        <select name="bank_code" id="bank_name" style=" border:1px; display:block;" required>
                                            <option value="">Select</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>
                                    </div>
                                </div>

                                <div style=" text-align: left; padding-bottom: 10px; color: #0F0F0F; font-family: DengXian;"
                                    id="v1">*Bank account</div>
                                <div class="layui-form-item" style="height:45px;">
                                    <div class="inputdiv">
                                        <input type="number" name="account_number" id="account"
                                            autocomplete="new-password" style="color:#000;border:0px;" maxlength="49"
                                            placeholder="Please enter a bank account" class="layui-input"/>
                                    </div>
                                </div>

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

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

                                <div
                                    style=" text-align: left; padding-bottom: 10px; color: #0F0F0F; font-family: DengXian;">
                                    *Account name</div>
                                <div class="layui-form-item" style="height:45px;">
                                    <div class="inputdiv">
                                        <input type="text" name="account_name" id="account_name" maxlength="49"
                                            autocomplete="new-password" style="color:#000;border:0px;"
                                            placeholder="Please enter your name" class="layui-input" required readonly />
                                    </div>
                                </div>

                                <!--<div id="l3" style=" text-align:left; padding-bottom: 10px; color: #0F0F0F; font-family: DengXian; ">*IFSC</div>
                                                <div id="l4" class="layui-form-item" style="height:48px;">
                                                    <div class="inputdiv">
                                                        <input type="text" id="IFSC" maxlength="11" style="color: #000; border: 0px;" placeholder="Please enter your IFSC " autocomplete="off" class="layui-input" />
                                                    </div>
                                                </div>-->

                        </div>

                        <div class="layui-form-item" style="margin-top:25px; text-align:center;">
                            <input type="submit" class="layui-btn" id="reg" value="Add"
                                style="width: 60%; height:45px;line-height:45px; border-radius: 25px; color: #fff; font-weight: bold; background: #000; font-size: 16px; border: 0px;  "
                                disabled />
                        </div>
                    </form>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    </body>
<?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/arrowquip/core/resources/views/templates/basic/user/bank-setup.blade.php ENDPATH**/ ?>