// source --> https://stargb.com/wp-content/plugins/simple-banner/simple-banner.js 
jQuery(document).ready(function ($) {
    const { pro_version_enabled, debug_mode, banner_params } = simpleBannerScriptParams;

    banner_params.forEach((bannerParams, i) => {
        const banner_id = i === 0 ? '' : `_${i+1}`;
        const { 
            simple_banner_text,
            simple_banner_disabled_page_paths,
            disabled_on_current_page,
            close_button_enabled,
            close_button_expiration,
            simple_banner_insert_inside_element,
            simple_banner_prepend_element,
            keep_site_custom_css,
            keep_site_custom_js,
            wp_body_open,
            wp_body_open_enabled,
        } = bannerParams;

        const strings = {
            simpleBanner: `simple-banner${banner_id}`,
            simpleBannerText: `simple-banner-text${banner_id}`,
            simpleBannerCloseButton: `simple-banner-close-button${banner_id}`,
            simpleBannerButton: `simple-banner-button${banner_id}`,
            simpleBannerScrolling: `simple-banner-scrolling${banner_id}`,
            simpleBannerSiteCustomCss: `simple-banner-site-custom-css${banner_id}`,
            simpleBannerSiteCustomJs: `simple-banner-site-custom-js${banner_id}`,
            simpleBannerHeaderMargin: `simple-banner-header-margin${banner_id}`,
            simpleBannerHeaderPadding: `simple-banner-header-padding${banner_id}`,
            simpleBannerClosedCookie: `simplebannerclosed${banner_id}`,
        }

        const isSimpleBannerTextSet = simple_banner_text && simple_banner_text !== undefined && simple_banner_text !== "";
        const isDisabledByPagePath = simple_banner_disabled_page_paths ? simple_banner_disabled_page_paths.split(',')
            .filter(Boolean)
            .some(path => {
                const pathname = path.trim();
                if (pathname.at(0) === '*' && pathname.at(-1) === '*') {
                    return window.location.pathname.includes(pathname.slice(1, -1));
                }
                if (pathname.at(0) === '*') {
                    return window.location.pathname.endsWith(pathname.slice(1));
                }
                if (pathname.at(-1) === '*') {
                    return window.location.pathname.startsWith(pathname.slice(0, -1));
                }
                return window.location.pathname === pathname;
            }) : false;
        const isSimpleBannerEnabledOnPage = !pro_version_enabled || 
            (pro_version_enabled && !disabled_on_current_page && !isDisabledByPagePath);
        const isSimpleBannerVisible = isSimpleBannerTextSet && isSimpleBannerEnabledOnPage;

        if (isSimpleBannerVisible) {
            if (!wp_body_open || !wp_body_open_enabled) {
                const closeButton = close_button_enabled ? `<button aria-label="Close" id="${strings.simpleBannerCloseButton}" class="${strings.simpleBannerButton}">&#x2715;</button>` : '';
                const prependElement = document.querySelector(simple_banner_insert_inside_element || simple_banner_prepend_element || 'body');

                $(
                    `<div id="${strings.simpleBanner}" class="${strings.simpleBanner}"><div class="${strings.simpleBannerText}"><span>${simple_banner_text}</span></div>${closeButton}</div>`
                ).prependTo(prependElement || 'body');
            }

            // could move this out of the loop but not entirely necessary
            const bodyPaddingLeft = $('body').css('padding-left')
            const bodyPaddingRight = $('body').css('padding-right')

            if (bodyPaddingLeft != "0px") {
                $('head').append(`<style type="text/css" media="screen">.${strings.simpleBanner}{margin-left:-${bodyPaddingLeft};padding-left:${bodyPaddingLeft};}</style>`);
            }
            if (bodyPaddingRight != "0px") {
                $('head').append(`<style type="text/css" media="screen">.${strings.simpleBanner}{margin-right:-${bodyPaddingRight};padding-right:${bodyPaddingRight};}</style>`);
            }

            // Add scrolling class
            function scrollClass() {
                const scroll = document.documentElement.scrollTop;
                if (scroll > $(`#${strings.simpleBanner}`).height()) {
                    $(`#${strings.simpleBanner}`).addClass(strings.simpleBannerScrolling);
                } else {
                    $(`#${strings.simpleBanner}`).removeClass(strings.simpleBannerScrolling);
                }
            }
            document.addEventListener("scroll", scrollClass);
        }

        // Add close button function to close button and close if cookie found
        function closeBanner() {
            if (!keep_site_custom_css && document.getElementById(strings.simpleBannerSiteCustomCss)) document.getElementById(strings.simpleBannerSiteCustomCss).remove();
            if (!keep_site_custom_js && document.getElementById(strings.simpleBannerSiteCustomJs)) document.getElementById(strings.simpleBannerSiteCustomJs).remove();
            // Header Margin/Padding only available for Banner #1
            if (document.getElementById(strings.simpleBannerHeaderMargin)) document.getElementById(strings.simpleBannerHeaderMargin).remove();
            if (document.getElementById(strings.simpleBannerHeaderPadding)) document.getElementById(strings.simpleBannerHeaderPadding).remove();
            if (document.getElementById(strings.simpleBanner)) document.getElementById(strings.simpleBanner).remove();
        }
        
        if (isSimpleBannerVisible) {
            const sbCookie = strings.simpleBannerClosedCookie;

            if (close_button_enabled){
                if (getCookie(sbCookie) === "true") {
                    closeBanner();
                    // Set cookie again here in case the expiration has changed
                    setCookie(sbCookie, "true", close_button_expiration);
                } else {
                    document.getElementById(strings.simpleBannerCloseButton).onclick = function() {
                        closeBanner();
                        setCookie(sbCookie, "true", close_button_expiration);
                    };
                }
            } else {
                // disable cookie if it exists
                if (getCookie(sbCookie) === "true") {
                    document.cookie = `${strings.simpleBannerClosedCookie}=true; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
                }
            }
        }
        
    })

    // Cookie Getter/Setter
    function setCookie(cname,cvalue,expiration) {
        let d;
        if (expiration === '' || expiration === '0' || parseFloat(expiration)) {
            const exdays = parseFloat(expiration) || 0;
            d = new Date();
            d.setTime(d.getTime() + (exdays*24*60*60*1000));
        } else {
            d = new Date(expiration);
        }
        const expires = "expires=" + d.toUTCString();
        document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
    }
    function getCookie(cname) {
        const name = cname + "=";
        const decodedCookie = decodeURIComponent(document.cookie);
        const ca = decodedCookie.split(';');
        for(let i = 0; i < ca.length; i++) {
            let c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }

    // Debug Mode
    // Console log all variables
    if (pro_version_enabled && debug_mode) {
        console.log(simpleBannerScriptParams);
    }
});
// source --> https://stargb.com/wp-content/plugins/sticky-menu-or-anything-on-scroll/assets/js/jq-sticky-anything.min.js 
/**
* @preserve Sticky Anything 2.22 | (c) WebFactory Ltd | GPL2 Licensed
*/

var stickyAnythingBreakpoint = '' // solely to use as a debugging breakpoint, if needed.

!function(e){function t(t,i){e(".sticky-element-original").clone().insertAfter(e(".sticky-element-original")).addClass("sticky-element-cloned").removeClass("element-is-not-sticky").addClass("element-is-sticky").css("position","fixed").css("top",t+"px").css("margin-left","0").css("z-index",i).removeClass("sticky-element-original").hide()}e.fn.stickThis=function(i){var n,s=e.extend({top:0,minscreenwidth:0,maxscreenwidth:99999,zindex:1,legacymode:!1,dynamicmode:!1,debugmode:!1,pushup:"",adminbar:!1},i),l=e(this).length,r=e(s.pushup).length;return r<1?(1==s.debugmode&&s.pushup&&console.error('STICKY ANYTHING DEBUG: There are no elements with the selector/class/ID you selected for the Push-up element ("'+s.pushup+'").'),s.pushup=""):r>1&&(1==s.debugmode&&console.error("STICKY ANYTHING DEBUG: There are "+r+' elements on the page with the selector/class/ID you selected for the push-up element ("'+s.pushup+'"). You can select only ONE element to push the sticky element up.'),s.pushup=""),l<1?1==s.debugmode&&console.error('STICKY ANYTHING DEBUG: There are no elements with the selector/class/ID you selected for the sticky element ("'+this.selector+'").'):l>1?1==s.debugmode&&console.error("STICKY ANYTHING DEBUG: There There are "+r+' elements with the selector/class/ID you selected for the sticky element ("'+this.selector+'"). You can only make ONE element sticky.'):1==s.legacymode?(e(this).addClass("sticky-element-original").addClass("element-is-not-sticky"),1!=s.dynamicmode&&t(s.top,s.zindex,s.adminbar),checkElement=setInterval(function(){!function(i,n,s,l,o,r,d){var a=e(".sticky-element-original").offset();if(orgElementTop=a.top,o){var c=e(o).offset();pushElementTop=c.top}var m=window,g="inner";"innerWidth"in window||(g="client",m=document.documentElement||document.body);viewport=m[g+"Width"],d&&e("body").hasClass("admin-bar")&&viewport>600?adminBarHeight=e("#wpadminbar").height():adminBarHeight=0;e(window).scrollTop()>=orgElementTop-i-adminBarHeight&&viewport>=n&&viewport<=s?(orgElement=e(".sticky-element-original"),coordsOrgElement=orgElement.offset(),leftOrgElement=coordsOrgElement.left,widthOrgElement=orgElement[0].getBoundingClientRect().width,widthOrgElement||(widthOrgElement=orgElement.css("width")),heightOrgElement=orgElement.outerHeight(),paddingOrgElement=[orgElement.css("padding-top"),orgElement.css("padding-right"),orgElement.css("padding-bottom"),orgElement.css("padding-left")],paddingCloned=paddingOrgElement[0]+" "+paddingOrgElement[1]+" "+paddingOrgElement[2]+" "+paddingOrgElement[3],1==r&&e(".sticky-element-cloned").length<1&&t(i,l),elementHeight=0,heightOrgElement<1?elementHeight=e(".sticky-element-cloned").outerHeight():elementHeight=e(".sticky-element-original").outerHeight(),o&&e(window).scrollTop()>pushElementTop-i-elementHeight-adminBarHeight?stickyTopMargin=pushElementTop-i-elementHeight-e(window).scrollTop():stickyTopMargin=adminBarHeight,e(".sticky-element-cloned").css("left",leftOrgElement+"px").css("top",i+"px").css("width",widthOrgElement).css("margin-top",stickyTopMargin).css("padding",paddingCloned).show(),e(".sticky-element-original").css("visibility","hidden")):(1==r?e(".sticky-element-cloned").remove():e(".sticky-element-cloned").hide(),e(".sticky-element-original").css("visibility","visible"))}(s.top,s.minscreenwidth,s.maxscreenwidth,s.zindex,s.pushup,s.dynamicmode,s.adminbar)},10)):(e(this).addClass("sticky-element-original").addClass("element-is-not-sticky"),orgAssignedStyles=(n=e(this),o={},o.display=n.css("display"),o.float=n.css("float"),o.flex=n.css("flex"),o["box-sizing"]=n.css("box-sizing"),o.clear=n.css("clear"),o.overflow=n.css("overflow"),o.transform=n.css("transform"),o),orgInlineStyles=e(".sticky-element-original").attr("style"),null==orgInlineStyles&&(orgInlineStyles=""),e(".sticky-element-original").addClass("sticky-element-active").before('<div class="sticky-element-placeholder" style="width:0; height:0; margin:0; padding:0; visibility:hidden;"></div>'),checkElement=setInterval(function(){!function(t,i,n,s,l,o,r,d){$listenerElement=e(".sticky-element-active");var a=$listenerElement.offset();if(orgElementTop=a.top,l){var c=e(l).offset();pushElementTop=c.top}var m=window,g="inner";"innerWidth"in window||(g="client",m=document.documentElement||document.body);viewport=m[g+"Width"],o&&e("body").hasClass("admin-bar")&&viewport>600?adminBarHeight=e("#wpadminbar").height():adminBarHeight=0;if(e(window).scrollTop()>=orgElementTop-t-adminBarHeight&&viewport>=i&&viewport<=n){for(var h in coordsOrgElement=$listenerElement.offset(),leftOrgElement=coordsOrgElement.left,widthPlaceholder=$listenerElement[0].getBoundingClientRect().width,widthPlaceholder||(widthPlaceholder=$listenerElement.css("width")),heightPlaceholder=$listenerElement[0].getBoundingClientRect().height,heightPlaceholder||(heightPlaceholder=$listenerElement.css("height")),widthSticky=e(".sticky-element-original").css("width"),"0px"==widthSticky&&(widthSticky=e(".sticky-element-original")[0].getBoundingClientRect().width),heightSticky=e(".sticky-element-original").height(),paddingOrgElement=[e(".sticky-element-original").css("padding-top"),e(".sticky-element-original").css("padding-right"),e(".sticky-element-original").css("padding-bottom"),e(".sticky-element-original").css("padding-left")],paddingSticky=paddingOrgElement[0]+" "+paddingOrgElement[1]+" "+paddingOrgElement[2]+" "+paddingOrgElement[3],marginOrgElement=[$listenerElement.css("margin-top"),$listenerElement.css("margin-right"),$listenerElement.css("margin-bottom"),$listenerElement.css("margin-left")],marginPlaceholder=marginOrgElement[0]+" "+marginOrgElement[1]+" "+marginOrgElement[2]+" "+marginOrgElement[3],assignedStyles="",r)"inline"==r[h]?assignedStyles+=h+":inline-block; ":assignedStyles+=h+":"+r[h]+"; ";elementHeight=0,heightPlaceholder<1?elementHeight=e(".sticky-element-cloned").outerHeight():elementHeight=e(".sticky-element-original").outerHeight(),l&&e(window).scrollTop()>pushElementTop-t-elementHeight-adminBarHeight?stickyTopMargin=pushElementTop-t-elementHeight-e(window).scrollTop():stickyTopMargin=adminBarHeight,assignedStyles+="width:"+widthPlaceholder+"px; height:"+heightPlaceholder+"px; margin:"+marginPlaceholder+";",e(".sticky-element-original").removeClass("sticky-element-active").removeClass("element-is-not-sticky").addClass("element-is-sticky").css("cssText","margin-top: "+stickyTopMargin+"px !important; margin-left: 0 !important").css("position","fixed").css("left",leftOrgElement+"px").css("top",t+"px").css("width",widthSticky).css("padding",paddingSticky).css("z-index",s),e(".sticky-element-original").each(function(){this.style.setProperty("margin-top",stickyTopMargin,"important")}),e(".sticky-element-placeholder").hasClass("sticky-element-active")||e(".sticky-element-placeholder").addClass("sticky-element-active").attr("style",assignedStyles)}else e(".sticky-element-original").addClass("sticky-element-active").removeClass("element-is-sticky").addClass("element-is-not-sticky").attr("style",d),e(".sticky-element-placeholder").hasClass("sticky-element-active")&&e(".sticky-element-placeholder").removeClass("sticky-element-active").removeAttr("style").css("width","0").css("height","0").css("margin","0").css("padding","0")}(s.top,s.minscreenwidth,s.maxscreenwidth,s.zindex,s.pushup,s.adminbar,orgAssignedStyles,orgInlineStyles)},10)),this}}(jQuery);