<!-- DEBUG-VIEW START 1 APPPATH/Views/login.php -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?= $pageTitle; ?> | <?= PROJECT_NAME; ?></title>
    <link rel="icon" type="image/x-icon" href="<?= ApiBaseUrl()['url'] . $header_data[0]['leftImage'] ?>">
    <!-- Google Font: Source Sans Pro -->
    <link rel="stylesheet"
        href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="<?= base_url('assets/payonline'); ?>/css/all.min.css">
    <!-- icheck bootstrap -->
    <link rel="stylesheet" href="<?= base_url('assets/payonline'); ?>/css/icheck-bootstrap.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="<?= base_url('assets/payonline'); ?>/css/adminlte.min.css">
    <!-- SweetAlert2 -->
    <link href='<?= base_url('assets/css/toast.css') ?>' rel='stylesheet' type='text/css'>

    <!-- sweet alert -->
    <script src="https://common.olemiss.edu/_js/sweet-alert/sweet-alert.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://common.olemiss.edu/_js/sweet-alert/sweet-alert.css">


    <!-- country_code links -->
    <link rel="stylesheet" type="text/css" href="<?= base_url('assets/css/intlTelInput.css?1549804213570'); ?>">
    <!-- country_code links -->

    <!-- <script src='https://www.google.com/recaptcha/api.js'></script> -->
    <style>
        /* :root {
            --main-color-new-theme: #7d1456;
            --main-color-new-theme-light: #2e2656;
        } */

        .login-box-msg,
        .register-box-msg {
            padding: 0;
        }

        .submitbutton {
            background-color: #7E4555;
        }

        .submitbutton:hover {
            background-color: #EE4D23;
        }

        /*body .modal-dialog { margin-left: 0; }*/

        .iti {
            /*position: relative;*/
            display: -webkit-box !important;
        }


        #signupModal {
            display: none;
        }

        .inSignup {
            display: none;
        }

        .form-floating-group {
            position: relative;
            /* margin-bottom: 20px; */
        }

        .form-floating-group input {
            width: 100%;
            padding: 14px 12px 6px;
            border: 1px solid #000;
            border-radius: 8px;
            font-size: 16px;
            outline: none;
        }

        .form-floating-group label {
            position: absolute;
            top: 10px;
            left: 12px;
            color: #000;
            font-weight: bold;
            pointer-events: none;
            transition: 0.2s ease all;
            background-color: #fff;
            padding: 0 4px;
        }

        .form-floating-group input:focus+label,
        .form-floating-group input:not(:placeholder-shown)+label {
            top: -8px;
            left: 10px;
            font-size: 13px;
            color: #000;
        }

        .required {
            color: red;
        }

        #loginPhoneNumber {
            border-radius: 8px;
            border: 1px solid black;
            height: 47px;
            font-weight: 600;
            color: black;
        }

        .email-suggestion-list {
            list-style: none;
            margin: 0;
            padding: 0;
            border: 1px solid #ccc;
            position: absolute;
            z-index: 1000;
            background-color: white;
            width: 100%;
            max-width: 300px;
            display: none;
        }

        .email-suggestion-list li {
            padding: 8px;
            cursor: pointer;
        }

        .email-suggestion-list li:hover {
            background-color: #f0f0f0;
        }
    </style>
    <link rel="stylesheet" type="text/css" href="<?= base_url('assets/css/ldld.min.css'); ?>">
    <script type="text/javascript" charset="utf8" src="<?= base_url('assets/js/ldld.min.js'); ?>"></script>
</head>

<body class="hold-transition login-page" style="display:grid!important;justify-items: center!important;">

    <!--- popup --->


    <?php
    $getQRSetting = getQRSetting();
    ?>


    <div class="login-box my-4">

        <div class="card card-outline card-danger">

            <div class="card-body login-card-body">
                <!-- <p class="login-box-msg">Sign in to start your session</p> -->

                <div class="row">


                    <!-- LOGIN BOX -->
                    <div class="col-md-12" id="loginModal">
                        <?php
                        if ($getQRSetting['login'] == "WITHOUTOTP") {
                        ?>
                            <form action="#" method="post" id="phonemyForm">
                                <div class="modal-body p-0">
                                    <div class="container">
                                        <img src="<?= ApiBaseUrl()['url'] . $header_data[0]['leftImage']; ?>"
                                            class="img-fluid my-3" height="90px" width="90px"
                                            style="display: block;margin-left: auto;margin-right: auto;">
                                        <h6 style="text-align: center;font-weight: bold;color: var(--main-color-new-theme);font-size: 1.2rem;">

                                            <?= GetProjectName() ?>
                                        </h6>
                                        <h5 class="text-center mb-2" style="font-weight: 700;color: black;">LOGIN</h5>


                                        <div class="row g-0">
                                            <div class="col-xl-12">
                                                <div class="row  mb-3" style="text-align:center;">
                                                    <div class="col-md-12">

                                                        <div class="hs-toast-wrapper mb-3" id="login-error-flashmsg"></div>
                                                        <div class="hs-toast-wrapper mb-3" id="login-success-flashmsg"></div>

                                                    </div>
                                                </div>
                                            </div>
                                        </div>


                                        <div class="row d-flex justify-content-center align-items-center">
                                            <div class="col-xl-12">
                                                <div class="row">
                                                    <div class="col-xl-12">


                                                        <span class="email_section ">
                                                            <div class="row ">
                                                                <div class="col-md-12 mb-2">
                                                                    <div class="form-floating-group">
                                                                        <input type="email" name="email" id="loginEmail" class="form-input" placeholder=" " oninput="this.value = this.value.toLowerCase();loginBy('email');showEmailSuggestions();">
                                                                        <label for="email">Enter your email id</label>
                                                                    </div>
                                                                    <ul id="email-suggestion-list" class="email-suggestion-list"></ul>

                                                                    <span class="otpsendmsg"
                                                                        style="color: green; font-size: 13px;"></span>
                                                                </div>
                                                            </div>

                                                        </span>

                                                        <span class="mobile_section">
                                                            <div class="text-center mb-2">--OR--</div>
                                                            <div class="row">
                                                                <div class="col-md-12 mb-0 ">
                                                                    <input type="tel" placeholder="Ex. +1 (702) 123-4567"
                                                                        id="loginPhoneNumber" name="phone"
                                                                        class="phone-with-country-code form-control"
                                                                        value="+1" minlength="10" maxlength="15"
                                                                        onkeypress="return (event.charCode !=8 && event.charCode ==0 || (event.charCode >= 48 && event.charCode <= 57 || event.charCode==43 ))"
                                                                        oninput="nonEditCuntryCode(this);loginBy('phone');">
                                                                    <span class="otpsendmsg_number"
                                                                        style="color: green; font-size: 18px;margin-left: 12px;"></span>
                                                                </div>


                                                            </div>
                                                        </span>

                                                        <div class="col-md-12 mb-4">
                                                            <center>
                                                                <button class="btn btn-success"
                                                                    onclick="WithoutOtpLogin(event)" style="background-color: green!important;">LOGIN</button>
                                                            </center>

                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="d-flex justify-content-center text-center modal-footer">
                                    <div class="row">
                                        <p class="mb-0 text-center">Please sign-in with your registered phone number or email id.</p>
                                    </div>

                                </div>


                            </form>

                        <?php
                        } else {
                        ?>
                            <form action="#" method="post" id="phonemyForm"
                                onsubmit="return LoginUser('<?= base_url('signin') ?>')">
                                <div class="modal-body p-0">
                                    <div class="container">
                                        <img src="<?= ApiBaseUrl()['url'] . $header_data[0]['leftImage']; ?>"
                                            class="img-fluid my-3" height="90px" width="90px"
                                            style="display: block;margin-left: auto;margin-right: auto;">
                                        <h6 style="text-align: center;font-weight: bold;color: var(--main-color-new-theme);font-size: 1.2rem;">

                                            <?= GetProjectName() ?>
                                        </h6>
                                        <h5 class="text-center mb-2" style="font-weight: 700;color: black;">LOGIN</h5>


                                        <div class="row g-0">
                                            <div class="col-xl-12">
                                                <div class="row  mb-3" style="text-align:center;">
                                                    <div class="col-md-12">
                                                        <div id="login-error-flashmsg"></div>
                                                        <div id="login-success-flashmsg"></div>

                                                    </div>
                                                </div>
                                            </div>
                                        </div>


                                        <div class="row d-flex justify-content-center align-items-center">
                                            <div class="col-xl-12">
                                                <div class="row">
                                                    <div class="col-xl-12">


                                                        <span class="email_section ">
                                                            <div class="row ">
                                                                <div class="col-md-12 mb-2">
                                                                    <!-- <input type="email" id="loginEmail"
                                                                    placeholder="Enter your email Id" name="email"
                                                                    class="form-control" oninput="this.value = this.value.toLowerCase();loginBy('email');" /> -->
                                                                    <div class="form-floating-group">
                                                                        <input type="email" name="email" id="loginEmail" class="form-input" placeholder=" " oninput="this.value = this.value.toLowerCase();loginBy('email');showEmailSuggestions();">
                                                                        <label for="email">Enter your email Id</label>
                                                                    </div>
                                                                    <ul id="email-suggestion-list" class="email-suggestion-list"></ul>

                                                                    <span class="otpsendmsg"
                                                                        style="color: green; font-size: 13px;"></span>
                                                                </div>
                                                            </div>

                                                            <div class="row" id="otptoggle" style="display:none;">
                                                                <div class="col-md-8 mb-2">
                                                                    <input type="number" id="emailotp" name="emailotp"
                                                                        placeholder="Please enter OTP to continue."
                                                                        class="form-control" required />
                                                                </div>
                                                                <div class="col-md-4 mb-2">
                                                                    <button id="emailotpverifybtn"
                                                                        class="btn btn-success verifyBtn"
                                                                        onclick="verifyEmailOtp('<?= base_url('email-otp-verification') ?>')">VERIFY</button>
                                                                </div>
                                                            </div>
                                                        </span>

                                                        <span class="mobile_section">
                                                            <div class="text-center mb-2">--OR--</div>
                                                            <div class="row">
                                                                <div class="col-md-12 mb-0 ">
                                                                    <input type="tel" placeholder="Ex. +1 (702) 123-4567"
                                                                        id="loginPhoneNumber" name="phone"
                                                                        class="phone-with-country-code form-control"
                                                                        value="+1" minlength="10" maxlength="15"
                                                                        onkeypress="return (event.charCode !=8 && event.charCode ==0 || (event.charCode >= 48 && event.charCode <= 57 || event.charCode==43 ))"
                                                                        oninput="nonEditCuntryCode(this);loginBy('phone');">
                                                                    <span class="otpsendmsg_number"
                                                                        style="color: green; font-size: 18px;margin-left: 12px;"></span>
                                                                </div>

                                                                <div class="col-md-12 mb-4">
                                                                    <center>
                                                                        <button id="emailotpntn" class="btn btn-success"
                                                                            onclick="sendEmailOtp('<?= base_url('send-email-otp') ?>')" style="background-color: green!important;">LOGIN</button>
                                                                    </center>

                                                                </div>
                                                            </div>
                                                        </span>

                                                        <div class="row mobile-section otpmobilebox" id="mobiletoggle"
                                                            style="display:none;">
                                                            <div class="col-md-8 mb-4">
                                                                <input type="number" id="mobileotp" name="mobileotp"
                                                                    placeholder="Please enter OTP to continue."
                                                                    class="form-control" />
                                                                <span class="otpsendmsg_number_error"
                                                                    style="color: red; font-size: 18px;margin-left: 12px;"></span>
                                                            </div>
                                                            <div class="col-md-4 mb-4">
                                                                <button id="mobileotpverifybtn"
                                                                    class="btn btn-success verifyBtn"
                                                                    onclick="submitPhoneNumberAuthCode()">VERIFY</button>
                                                            </div>
                                                        </div>
                                                        <div id="recaptcha-container"></div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="d-flex justify-content-center text-center modal-footer">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <button type="submit" class="btn btn-warning" id="loginBtn" style="font-weight: 500;"> LOGIN</button>
                                            <button type="button" class="loginBtnClose btnClose btn btn-danger ms-2"
                                                data-dismiss="modal" hidden>CLOSE</button>
                                        </div>
                                        <p class="mb-0 text-center">Please sign-in with your registered phone number or email id.</p>
                                    </div>

                                </div>


                            </form>
                        <?php
                        }
                        ?>


                        <div class="row">
                            <div class="col-sm-12  text-center">
                                <!-- <a href="<?= base_url('registration') ?>" class="inLogin text-dark">New User? <b class="text-center">Sign Up</b></a> -->
                                <a href="<?= base_url('registration') ?>" onclick="loader.on();" id="signupLink" style="color: var(--main-color-new-theme);">Are you new to Chatwala? <br><b class="text-danger">Register Now</b></a>
                            </div>
                        </div>
                    </div>

                </div>


            </div>
        </div>
    </div>


    <!-- END HARE LOGIN CHECK -->


    <div class="ldld full" style="z-index: 9999;"></div>

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script type="text/javascript" src="<?= base_url('assets/js/intlTelInput.js?1549804213570'); ?>"></script>
    <script src="<?= base_url('assets/js/toast.js') ?>"></script>
    <script type="text/javascript">
        var loader = new ldLoader({
            root: ".ldld.full"
        });
    </script>
    <!-- <script>
  $('#email').popover();
</script> -->




    <script type="text/javascript">
        const commonDomains = ["gmail.com", "yahoo.com", "outlook.com", "hotmail.com", "rediffmail.com", "yahoo.in"];

        function showEmailSuggestions() {
            const input = document.getElementById("loginEmail");
            const list = document.getElementById("email-suggestion-list");
            const value = input.value.trim();

            list.innerHTML = "";
            list.style.display = "none";

            // Only proceed if @ is present
            if (value.includes("@")) {
                const [prefix, domainPart] = value.split("@");

                // Prevent showing suggestions if nothing before @
                if (!prefix) return;

                const matchedDomains = commonDomains.filter(domain =>
                    domain.startsWith(domainPart.toLowerCase())
                );

                // If there's at least one match, show list
                if (matchedDomains.length > 0) {
                    matchedDomains.forEach(domain => {
                        const suggestion = document.createElement("li");
                        suggestion.textContent = `${prefix}@${domain}`;
                        suggestion.style.cursor = "pointer";
                        suggestion.style.padding = "5px";

                        suggestion.onclick = () => {
                            input.value = suggestion.textContent;
                            list.style.display = "none";
                        };

                        list.appendChild(suggestion);
                    });

                    list.style.display = "block";
                }
            }
        }

        // ✅ Hide suggestions when clicking outside
     
             document.addEventListener("DOMContentLoaded", function () {
    document.addEventListener("click", function (e) {
        const input = document.getElementById("loginEmail"); // or loginEmail if you're using that
        const list = document.getElementById("email-suggestion-list");

        if (input && list && !input.contains(e.target) && !list.contains(e.target)) {
            list.style.display = "none";
        }
    });
});


        // $(function() {
        //     $('.modal').modal({
        //         backdrop: 'static',
        //         keyboard: false
        //     });
        // })

        $("#loginBtn").hide();

        function sendEmailOtp(url) {
            //test
            var email = $('#loginEmail').val();
            var phoneval = $('#loginPhoneNumber').val();
            var phoneLength = $('#loginPhoneNumber').val().length;

            if (email == "" && phoneLength < 12) {
                // $("#login-error-flashmsg").html("Please enter valid email or valid mobile number.");
                showToast({
                    eleWrapper: '#login-error-flashmsg',
                    msg: 'Please enter valid email or valid mobile number.',
                    theme: 'error',
                    closeButton: false,
                    autoClose: true,
                    duration: 60000,
                    afterShow: function() {
                        console.log('After show function');
                    },
                    afterClose: function() {
                        console.log('After close function');
                    }
                });
            } else {
                $("#login-error-flashmsg").html("");

                if (email == "") {
                    event.preventDefault();
                    LoginUser('<?= base_url('signin') ?>');

                } else {

                    var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
                    if (email.match(mailformat)) {

                        var btn = document.getElementById('emailotpntn');
                        btn.disabled = true;
                        btn.innerText = 'SENDING';

                        event.preventDefault();
                        var url = url;
                        var email = $('#loginEmail').val();
                        //alert(email);
                        $.ajax({
                            url: url,
                            type: "POST",
                            dataType: "json",
                            data: {
                                'email': email
                            },
                            success: function(data) {


                                if (data['statusCode'] == '1') {
                                    $("#emailotpntn").hide();
                                    $(".mobile_section").hide();

                                    btn.disabled = true;
                                    btn.innerText = 'SENT';
                                    $('#otptoggle').toggle();
                                    var btn2 = document.getElementById('emailotpverifybtn');
                                    btn2.disabled = false;
                                    btn.disabled = true;
                                    $("#login-success-flashmsg").html("OTP sent on this email id!");
                                    $(".mobile-section").hide();

                                } else {
                                    btn.disabled = false;
                                    btn.innerText = 'Login';


                                    showToast({
                                        eleWrapper: '#login-error-flashmsg',
                                        msg: ' This email id is not registerd please signup.',
                                        theme: 'error',
                                        closeButton: false,
                                        autoClose: true,
                                        duration: 60000,
                                        afterShow: function() {
                                            console.log('After show function');
                                        },
                                        afterClose: function() {
                                            console.log('After close function');
                                        }
                                    });

                                }
                            }
                        });

                    } else {
                        btn.disabled = false;
                        btn.innerText = 'LOGIN';
                        $("#login-error-flashmsg").html("Please enter a valid email address.");
                    }

                    //test end

                }
            }
        }

        function verifyEmailOtp(url) {
            var btn = document.getElementById('emailotpverifybtn');
            btn.disabled = true;
            btn.innerText = 'VERIFYING';

            event.preventDefault();
            var url = url;
            var otp = $('#emailotp').val();

            if (otp == "") {
                $("#login-success-flashmsg").html("");
                $("#login-error-flashmsg").html("Please enter 6 digit OTP!");
                btn.disabled = false;
                btn.innerText = 'VERIFY';

            } else {
                var email = $('#loginEmail').val();
                $.ajax({
                    url: url,
                    type: "POST",
                    dataType: "json",
                    data: {
                        'otp': otp,
                        'email': email
                    },
                    success: function(data) {

                        if (data['statusCode'] == 1) {
                            btn.disabled = true;
                            btn.innerText = 'VERIFIED';
                            //$("#loginBtn").show();

                            PhoneLogin('<?= base_url('signin') ?>');


                        } else {
                            $("#login-error-flashmsg").html("");
                            $("#login-success-flashmsg").html("");
                            $("#login-error-flashmsg").html(data['message']);
                            btn.disabled = false;
                            btn.innerText = 'VERIFY';
                        }


                    }
                });
            }
        }





        function LoginUser(url) {
            var btn = document.getElementById('emailotpntn');
            btn.disabled = true;
            btn.innerText = 'PLEASE WAIT...';

            event.preventDefault();
            var url = url;
            var email = $('#loginEmail').val();
            var phone = $('#loginPhoneNumber').val();


            // alert(email);  

            // newphone = phone.replaceAll(" ","").slice(-10);
            // NOTE: REMOVE COUNTRY CODE FROM MOBILE NO

            var newphone = 0;
            var cuntryCode = $("#loginModal .iti__selected-flag").attr('title');
            cuntryCode = (cuntryCode.split(':')[1]).trim();
            var value = phone.replace(cuntryCode, ''); //replace all $ with empty string
            newphone = value;

            $.ajax({
                url: url,
                type: "POST",
                dataType: "json",
                data: {
                    'email': email,
                    'phone': newphone
                },
                success: function(data) {

                    console.log("data");
                    console.log(data);

                    if (data.statusCode == 1) {
                        btn.disabled = true;
                        btn.innerText = 'SENT';

                        if (phone != "") {
                            submitPhoneNumberAuth();
                            $("#emailotpntn").hide();
                            $(".email_section").hide();
                            $("#loginPhoneNumber").attr('disabled', 'disabled');
                        } else {

                            $('#otptoggle').css("display", "none");

                            var btn2 = document.getElementById('emailotpverifybtn');
                            btn2.disabled = false;
                            btn.disabled = true;

                            // alert('Login Successful.');
                            $('.loginBtnClose').click();

                        }

                    } else {
                        btn.disabled = false;
                        btn.innerText = 'Login';

                        // $("#login-error-flashmsg").html("This phone no. is not registered please signup !");

                        showToast({
                            eleWrapper: '#login-error-flashmsg',
                            msg: 'This phone no. is not registered please signup !',
                            theme: 'error',
                            closeButton: false,
                            autoClose: true,
                            duration: 60000,
                            afterShow: function() {
                                console.log('After show function');
                            },
                            afterClose: function() {
                                console.log('After close function');
                            }
                        });




                    }
                }
            });

        }


        //Phone Login

        function PhoneLogin(url) {

            event.preventDefault();
            var url = url;
            var email = $('#loginEmail').val();
            var phone = $('#loginPhoneNumber').val();

            // newphone = phone.replaceAll(" ","").slice(-10);


            var newphone = 0;
            var cuntryCode = $("#loginModal .iti__selected-flag").attr('title');
            cuntryCode = (cuntryCode.split(':')[1]).trim();
            var value = phone.replace(cuntryCode, ''); //replace all $ with empty string
            newphone = value;


            $.ajax({
                url: url,
                type: "POST",
                dataType: "json",
                data: {
                    'email': email,
                    'phone': newphone,
                    'sessionCreate': 1
                },
                success: function(data) {
                    console.log(data);
                    if (data.statusCode == 1) {
                        // alert('Login Successful.');

                        loader.on();

                        window.location.href = "<?= base_url('admin/update-profile') ?>";

                    } else {
                        $("#login-error-flashmsg").html("This phone no. is not registered please signup !");
                    }
                }
            });

        }
    </script>
    <!-- Mobile OTP AUTH BY FIREBASE -->
    <!-- Add the latest firebase dependecies from CDN -->
    <script src="https://www.gstatic.com/firebasejs/6.3.3/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/6.3.3/firebase-auth.js"></script>


    <script>
        // Paste the config your copied earlier
        var firebaseConfig = {
            // apiKey: "AIzaSyDOZaA5y9troVat374EID1ARxuMfMfL-dA",
            // authDomain: "partyplanet-65d19.firebaseapp.com",
            // databaseURL: "https://medium-d924f.firebaseio.com",
            // projectId: "partyplanet-65d19",
            // storageBucket: "partyplanet-65d19.appspot.com",
            // messagingSenderId: "1012225783641",
            // appId: "1:1012225783641:web:76cfa38acda53641e6be48"

            apiKey: "AIzaSyAcxU5AvD6qtVG76xDCXaf2vzuPIX_DwMw",
            authDomain: "login-7aff9.firebaseapp.com",
            projectId: "login-7aff9",
            storageBucket: "login-7aff9.appspot.com",
            messagingSenderId: "981533541532",
            appId: "1:981533541532:web:9846cc5487bb8fead35959",
            measurementId: "G-57D5BT4B2F"
        };


        firebase.initializeApp(firebaseConfig);

        // Create a Recaptcha verifier instance globally
        // Calls submitPhoneNumberAuth() when the captcha is verified
        window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier(
            "recaptcha-container", {
                size: "normal",
                callback: function(response) {
                    submitPhoneNumberAuth();
                }
            }
        );

        // This function runs when the 'sign-in-button' is clicked
        // Takes the value from the 'phoneNumber' input and sends SMS to that phone number
        function submitPhoneNumberAuth() {
            var phoneNumber = document.getElementById("loginPhoneNumber").value;
            var appVerifier = window.recaptchaVerifier;
            firebase
                .auth()
                .signInWithPhoneNumber(phoneNumber, appVerifier)
                .then(function(confirmationResult) {
                    window.confirmationResult = confirmationResult;

                    if (confirmationResult.verificationId) {
                        $("#mobiletoggle").toggle();
                        $('#mobileotp').focus();
                        $(".otpsendmsg_number").html("OTP has been sent on this mobile number.");
                        $("#recaptcha-container").remove();
                    }


                })
                .catch(function(error) {
                    console.log(error);
                    // $(".otpsendmsg_number").html("OTP has been sent on this mobile number.");
                    $("#login-error-flashmsg").html(error.message);

                });
        }

        function submitPhoneNumberAuthCode() {
            var btn = document.getElementById('mobileotpverifybtn');
            btn.disabled = true;
            btn.innerText = 'VERIFYING';


            var code = document.getElementById("mobileotp").value;
            if (code == "") {
                btn.disabled = false;
                btn.innerText = 'VERIFY';
                $(".otpsendmsg_number").html("");
                $(".otpsendmsg_number_error").html("Please enter OTP");
            } else {
                confirmationResult
                    .confirm(code)
                    .then(function(result) {
                        var user = result.user;
                        // console.log(user);




                        PhoneLogin('<?= base_url('signin') ?>');


                        // console.log("USER LOGGED IN");

                    })
                    .catch(function(error) {
                        alert('Invalid OTP/OTP Expired!!')
                        var btn = document.getElementById('mobileotpverifybtn');
                        btn.disabled = false;
                        btn.innerText = 'VERIFY';
                        console.log(error);
                    });

                //This function runs everytime the auth state changes. Use to verify if the user is logged in
                firebase.auth().onAuthStateChanged(function(user) {});
            }
        }

        function nonEditCuntryCode(el) {
            var cuntryCode = $("#loginModal .iti__selected-flag").attr('title');
            // alert(cuntryCode);
            cuntryCode = (cuntryCode.split(':')[1]).trim();

            if (el.value.length > cuntryCode.length) {
                var value = el.value.replace(cuntryCode, '');; //replace all $ with empty string
                el.value = cuntryCode + value;
            } else {
                el.value = cuntryCode;
            }
        }

        function loginBy(type) {


            if (type == 'email') {
                var cuntryCode = $("#loginModal .iti__selected-flag").attr('title');
                cuntryCode = (cuntryCode.split(':')[1]).trim();
                $("#loginPhoneNumber").val(cuntryCode);
            } else {
                $("#loginEmail").val('');
            }



        }
    </script>
    <script type="text/javascript" src="<?= base_url('assets/js/country_code.js') ?>"></script>
    <script type="text/javascript" src="<?= base_url('assets/js/country_code2.js') ?>"></script>
    <script>
        function WithoutOtpLogin(e) {
            e.preventDefault(); // Prevent the default form submission
            // alert('ok');
            // Gather the form dataalert
            var email = $("#loginEmail").val();
            var phone = $("#loginPhoneNumber").val();
            var newphone = 0;
            loader.on();



            var cuntryCode = $("#loginModal .iti__selected-flag").attr('title');
            cuntryCode = (cuntryCode.split(':')[1]).trim();
            var value = phone.replace(cuntryCode, '');
            newphone = value;
            console.log(newphone);
            $.ajax({
                url: '<?= base_url('signin') ?>', // Replace with your API endpoint
                type: 'POST', // Assuming the API expects POST requests
                data: {
                    email: email,
                    phone: newphone,
                    sessionCreate: 1,
                },
                success: function(response) {
                    loader.off();
                    console.log(response);
                    response = JSON.parse(response);
                    // alert(response);
                    //  alert(response.statusCode);

                    if (response.statusCode == '1') {
                        loader.on();
                        window.location.href = "<?= base_url('admin/update-profile') ?>";
                    } else {
                        //   openSignupModal();
                        // alert('Form submitted successfully');
                        if (response == "User not found!!" || response == "Something Went Wrong!!") {
                            // $("#login-error-flashmsg").html(response);
                            showToast({
                                eleWrapper: '#login-error-flashmsg',
                                msg: response,
                                theme: 'error',
                                closeButton: false,
                                autoClose: true,
                                duration: 60000,
                                afterShow: function() {
                                    console.log('After show function');
                                },
                                afterClose: function() {
                                    console.log('After close function');
                                }
                            });
                        } else {
                            // $("#login-error-flashmsg").html(response.data.message);
                            showToast({
                                eleWrapper: '#login-error-flashmsg',
                                msg: response.data.message,
                                theme: 'error',
                                closeButton: false,
                                autoClose: true,
                                duration: 60000,
                                afterShow: function() {
                                    console.log('After show function');
                                },
                                afterClose: function() {
                                    console.log('After close function');
                                }
                            });
                        }

                    }
                },
                error: function(xhr, status, error) {
                    loader.off();
                    // Handle error
                    // console.error('Error submitting form:', error);
                    alert('Error submitting form');
                }
            });
        }
    </script>