(function() {
    var jQuery,
    jQuery_version = '3.2.1';

    
    if (window.jQuery === undefined) {
        var script = document.createElement('script');

        script.setAttribute('type', 'text/javascript');
        script.setAttribute('src', 'https://ajax.googleapis.com/ajax/libs/jquery/' + jQuery_version + '/jquery.min.js');

        if (script.readyState) {
            script.onreadystatechange = function() {
                if (this.readyState == 'complete' || this.readyState == 'loaded') {
                    jQuery = window.jQuery.noConflict();

                    init();
                }
            };
        } else {
            script.onload = function() {
                jQuery = window.jQuery.noConflict();

                init();
            };
        }

        (document.getElementsByTagName('head')[0] || document.documentElement).appendChild(script);
    } else {
        jQuery = window.jQuery;

        init();
    }

    function init() {
        jQuery(($) =>  {
            let rmtoken = window.localStorage.getItem('wsd_rm_autocare')
            fetch('https://www.autocareadvocacy.org/wp-json/wsd/v1/widget/6769', {
                mode: "cors",
                credentials: "include",
                headers: {
                    "X-Wsd-Remember": rmtoken
                }
            })
                .then(response => response.json())
                .then(data => $('#industry').html(data.form))

            $(document).on('submit', '#industry form#wsd_widgets_action', function(event) {
                event.preventDefault();
                $("#submit_0").prop("disabled", true).val("Submitting Form");
                const rmcb = this.querySelector('[name="remember_me"]')
                if (rmcb && !rmcb.checked) {
                    rmtoken = null
                    window.localStorage.removeItem('wsd_rm_autocare')
                }
                                fetch('https://www.autocareadvocacy.org/wp-json/wsd/v1/actionwidget/6769/', {
                    method: "POST",
                    body: jQuery(this).serialize(),
                    headers: {
                        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
                        "X-Wsd-Remember": rmtoken
                    },
                    credentials: "include",
                    mode: "cors"
                })
                    .then(response => response.json())
                    .then(data => {
                        if (data.rmtoken)
                            window.localStorage.setItem( 'wsd_rm_autocare', data.rmtoken )
                        $('#industry').html(data.message)
                    })
                            });
        });
    }
})();