

(function ($) {

    $(document).ready(function () {

        let esigSettings_signing_reminder_email = document.getElementById("settings-signing_reminder_email");

        esigSettings_signing_reminder_email.addEventListener("click", function (e) {
            if (esigSettings_signing_reminder_email.checked) {
                document.getElementById("esig-reminder-interval-section").style.visibility = "visible";
            } else {
                document.getElementById("esig-reminder-interval-section").style.visibility = "hidden";
            }
        });

        //settings-signing_reminder_email onloading if it is checked then hide the section
        if (esigSettings_signing_reminder_email.checked) {
            document.getElementById("esig-reminder-interval-section").style.visibility = "visible";
        } else {
            document.getElementById("esig-reminder-interval-section").style.visibility = "hidden";
        }


        // add an input event to this id settings-esig-reminder-first-interval
        document.getElementById("settings-esig-reminder-first-interval").addEventListener("input", function (e) {

            let firstInverval = document.querySelector("#settings-esig-reminder-first-interval");
            let secondInverval = document.querySelector("#settings-esig-reminder-second-interval");
            let lastInverval = document.querySelector("#settings-esig-reminder-last-interval");

            // checking first interval  
            if (!isNaN(firstInverval.value) && firstInverval.value <= 0) {
                firstInverval.style.borderColor = "red";
            } else {
                firstInverval.style.borderColor = "";
            }

            // checking second interval  
            if (!isNaN(secondInverval.value) && secondInverval.value <= 0) {
                secondInverval.style.borderColor = "red";
            } else {
                secondInverval.style.borderColor = "";
            }

            // check third and final internval 
            if (!isNaN(lastInverval.value) && lastInverval.value <= 0) {
                lastInverval.style.borderColor = "red";
            } else {
                lastInverval.style.borderColor = "";
            }

            
             
        });

        // add an input event to this id settings-esig-reminder-second-interval
        document.getElementById("settings-esig-reminder-second-interval").addEventListener("input", function (e) {

            let firstInverval = document.querySelector("#settings-esig-reminder-first-interval");
            let secondInverval = document.querySelector("#settings-esig-reminder-second-interval");
            let lastInverval = document.querySelector("#settings-esig-reminder-last-interval");

            if (parseInt(secondInverval.value) <= parseInt(firstInverval.value)) {
                document.getElementById('second-reminder-error').removeAttribute('style');
                secondInverval.style.borderColor = "red";
            } else {
                document.getElementById('second-reminder-error').setAttribute('style', 'display:none');
                secondInverval.style.borderColor = "";
            }
        });

        // add an input event to this id settings-esig-reminder-last-interval
        document.getElementById("settings-esig-reminder-last-interval").addEventListener("input", function (e) {

            let firstInverval = document.querySelector("#settings-esig-reminder-first-interval");
            let secondInverval = document.querySelector("#settings-esig-reminder-second-interval");
            let lastInverval = document.querySelector("#settings-esig-reminder-last-interval");

            if (parseInt(lastInverval.value) <= parseInt(secondInverval.value)) {
                document.getElementById('last-reminder-error').removeAttribute('style');
                lastInverval.style.borderColor = "red";
            } else {
                document.getElementById('last-reminder-error').setAttribute('style', 'display:none');
                lastInverval.style.borderColor = "";
            }
        });

    });

})(jQuery);