(function(){"use strict";function Q(e,t){const n=e.toLowerCase(),r=t.toLowerCase();if(r.startsWith("*.")){const o=r.slice(1);return n.endsWith(o)&&n!==o.slice(1)}return n===r}function v(e,t){if(typeof window>"u"||typeof URL>"u")return null;let n,r;try{const o=new URL(e,window.location.href);r=o.protocol,n=o.hostname}catch{return null}if(r!=="http:"&&r!=="https:"||n===""||n===window.location.hostname)return null;for(const[o,s]of Object.entries(t))if(o!=="necessary"){for(const i of s)if(Q(n,i))return o}return null}const w="data-gdpr-category",h="gdpr-blocked-embed",x="data-gdpr-original",b=[`script[${w}]`,`iframe[${w}]`,"script[src]","iframe[src]","img[src]","link[href]"].join(", ");let l=null,g={categories:{},needs_renewal:!1},R={};function j(e){if(e&&typeof e=="object"&&"categories"in e){const t=e;return{categories:{...t.categories},needs_renewal:t.needs_renewal===!0}}return{categories:{...e},needs_renewal:!1}}function N(e){g=j(e),l!==null&&p()}function V(e){R={...e},l!==null&&p()}function Z(){typeof document>"u"||l!==null||(p(),l=new MutationObserver(e=>{for(const t of e)t.addedNodes.forEach(n=>{n instanceof HTMLElement&&te(n)})}),l.observe(document.documentElement,{childList:!0,subtree:!0}),window.addEventListener("gdpr:consent-changed",ee))}function ee(e){const t=e.detail;t!==null&&typeof t=="object"&&(g=j(t)),p()}function te(e){re(e)&&k(e),e.querySelectorAll(b).forEach(t=>k(t))}function p(){typeof document>"u"||(document.querySelectorAll(`.${h}`).forEach(e=>{const t=e.dataset.gdprBlockedCategory;t&&_(t)&&oe(e)}),document.querySelectorAll(b).forEach(e=>k(e)))}function k(e){if(e.classList.contains(h)||e.hasAttribute("data-gdpr-blocked-category"))return;const t=e.getAttribute(w);if(t!==null&&t!==""){if(_(t))return;H(e,t);return}const n=ne(e);if(n===null)return;const r=v(n,R);r!==null&&(_(r)||H(e,r))}function ne(e){return e instanceof HTMLScriptElement||e instanceof HTMLIFrameElement||e instanceof HTMLImageElement?e.getAttribute("src"):e instanceof HTMLLinkElement?e.getAttribute("href"):null}function re(e){if(typeof e.matches!="function")return!1;try{return e.matches(b)}catch{return!1}}function H(e,t){const n=document.createElement("div");n.className=h,n.dataset.gdprBlockedCategory=t,n.dataset.gdprOriginalTag=e.tagName.toLowerCase(),n.setAttribute(x,e.outerHTML),n.setAttribute("aria-hidden","true"),n.style.display="none",e.replaceWith(n)}function oe(e){const t=e.getAttribute(x);if(!t){e.remove();return}const n=document.createElement("div");n.innerHTML=t;const r=n.firstElementChild;r!==null?e.replaceWith(r):e.remove()}function _(e){return e==="necessary"?!0:g.needs_renewal?!1:g.categories[e]===!0}const se=500,ie=["click","keydown","change","submit","pointerdown","touchstart"];let B=!1,C=0;function ce(e){e.isTrusted&&(C=Date.now())}function ae(){if(!B){B=!0;for(const e of ie){const t=ce;window.addEventListener(e,t,{capture:!0,passive:!0})}}}function M(){const e=window.event;return e&&e.isTrusted?!0:C===0?!1:Date.now()-C<=se}const u=["XSRF-TOKEN","laravel_session","laravel_maintenance","gdpr_session"];let A=!1,a=null,y={functionalConsented:!1,necessaryAllowlist:u};function le(e){const t=e.indexOf("=");return t<=0?null:e.substring(0,t).trim()}function ue(e){return y.necessaryAllowlist.includes(e)}function fe(e){const t=le(e);return t===null?!1:!!(de(e)||ue(t)||y.functionalConsented||M())}function de(e){const t=e.toLowerCase(),n=t.match(/max-age\s*=\s*(-?\d+)/);return!!(n&&parseInt(n[1],10)<=0||t.includes("expires=thu, 01 jan 1970")||t.includes("expires=thu, 01-jan-1970"))}function ge(e){if(A)return;if(A=!0,y=e,a=Object.getOwnPropertyDescriptor(Document.prototype,"cookie")??null,!a||!a.set||!a.get){A=!1;return}const t=a.set,n=a.get;Object.defineProperty(Document.prototype,"cookie",{configurable:!0,get(){return n.call(this)},set(r){fe(r)&&t.call(this,r)}})}function P(e){y=e}const f=[{key:"g7_locale",storage:"localStorage",matchType:"exact"},{key:"auth_token",storage:"localStorage",matchType:"exact"},{key:"g7_cache_version",storage:"localStorage",matchType:"exact"},{key:"g7_cart_key",storage:"localStorage",matchType:"exact"},{key:"g7-devtools-panel",storage:"localStorage",matchType:"exact"},{key:"g7_devtools_",matchType:"prefix"},{key:"g7_filters_",matchType:"prefix"},{key:"g7_columns_",matchType:"prefix"},{key:"g7_order_",matchType:"prefix"}];let $=!1,E=null,m={functionalConsented:!1,necessaryAllowlist:f};function pe(e,t){for(const n of m.necessaryAllowlist){if(n.storage&&n.storage!==t)continue;const r=n.matchType??"exact";if(r==="exact"&&n.key===e||r==="prefix"&&e.startsWith(n.key))return!0}return!1}function ye(e,t){return!!(pe(e,t)||m.functionalConsented||M())}function me(e){if($)return;$=!0,m=e;const t=Storage.prototype;E=t.setItem,t.setItem=function(n,r){const o=this===window.sessionStorage?"sessionStorage":"localStorage";ye(n,o)&&E&&E.call(this,n,r)}}function G(e){m=e}function we(e,t,n){for(const r of n){if(r.storage&&r.storage!==t)continue;const o=r.matchType??"exact";if(o==="exact"&&r.key===e||o==="prefix"&&e.startsWith(r.key))return!0}return!1}function U(e,t,n){const r=[];for(let o=0;o-1?r.substring(0,o):r).trim();if(s&&!e.includes(s))try{document.cookie=`${s}=; Max-Age=0; Path=/`}catch{}}}function W(e={}){const t=e.storageAllowlist??f,n=e.cookieAllowlist??u;U(window.localStorage,"localStorage",t),U(window.sessionStorage,"sessionStorage",t),he(n)}let T=null;function be(){if(typeof window>"u")return null;const t=window.G7Core?.api;return t&&typeof t.get=="function"?t:null}async function K(e){const t=be();if(t)try{return await t.get(e)}catch{return null}try{const n=await fetch("/api"+e,{method:"GET",headers:{Accept:"application/json"},credentials:"same-origin"});return n.ok?await n.json():null}catch{return null}}async function ke(){if(T)return T;const t=(await K("/plugins/sirsoft-gdpr/settings"))?.data;return t?(T=t,t):null}async function q(){const e=await K("/plugins/sirsoft-gdpr/consent/cookie/status"),t=e?.data?.consents;return t==null?null:{categories:t,needs_renewal:e?.data?.needs_renewal===!0,current_policy_version:String(e?.data?.current_policy_version??"")}}const S="data-gdpr-blocked-src",L="data-gdpr-blocked-category",_e="data-gdpr-category";let F=!1,d={blockedDomains:{},consent:{necessary:!0},needs_renewal:!1};function D(e){return e==="necessary"?!0:d.needs_renewal===!0?!1:d.consent?.[e]===!0}function Ce(e,t){const n=e.getAttribute(_e);if(n!==null&&n!=="")return D(n)?null:n;const r=v(t,d.blockedDomains);return r===null||D(r)?null:r}function Ae(e){if(d={blockedDomains:e.blockedDomains??{},consent:e.consent??{necessary:!0},needs_renewal:e.needs_renewal===!0},F||typeof HTMLScriptElement>"u")return;const t=Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype,"src");t===void 0||typeof t.set!="function"||(Object.defineProperty(HTMLScriptElement.prototype,"src",{configurable:!0,enumerable:t.enumerable??!0,get(){return t.get?.call(this)??""},set(n){const r=Ce(this,n);if(r!==null){this.setAttribute(S,n),this.setAttribute(L,r);return}t.set.call(this,n)}}),F=!0)}function I(e){d={blockedDomains:e.blockedDomains??{},consent:e.consent??{necessary:!0},needs_renewal:e.needs_renewal===!0}}function Y(e){if(!D(e)||typeof document>"u")return;document.querySelectorAll(`script[${L}="${e}"]`).forEach(n=>{const r=n.getAttribute(S);if(r===null||r==="")return;const o=document.createElement("script");for(const i of Array.from(n.attributes))i.name===S||i.name===L||i.name==="src"||o.setAttribute(i.name,i.value);const s=n.parentNode;s!==null&&(s.replaceChild(o,n),o.src=r)})}const O="sirsoft-gdpr";function z(){if(typeof window>"u")return{};const n=window.G7Config?.plugins?.[O]?.blocked_domains;if(n==null||typeof n!="object")return{};const r={};for(const[o,s]of Object.entries(n)){if(!Array.isArray(s))continue;const i=s.filter(c=>typeof c=="string"&&c!=="");i.length>0&&(r[o]=i)}return r}function Ee(){return typeof window>"u"?!1:window.G7Config?.plugins?.[O]?.banner_enabled===!0}function J(){const e=window.G7Core?.getActionDispatcher?.();if(!e){setTimeout(J,100);return}e.registerHandler(`${O}.syncConsent`,async()=>{const t=await q();if(t===null)return;const n=!t.needs_renewal&&t.categories.functional===!0;N({categories:t.categories,needs_renewal:t.needs_renewal});const r=z();if(I({blockedDomains:r,consent:t.categories,needs_renewal:t.needs_renewal}),G({functionalConsented:n,necessaryAllowlist:f}),P({functionalConsented:n,necessaryAllowlist:u}),n||W(),!t.needs_renewal)for(const[o,s]of Object.entries(t.categories))s===!0&&o!=="necessary"&&Y(o)})}async function X(){if(typeof window>"u")return;if(J(),Ee()){const c=z();Ae({blockedDomains:c,consent:{necessary:!0}}),ae(),me({functionalConsented:!1,necessaryAllowlist:f}),ge({functionalConsented:!1,necessaryAllowlist:u})}const t=await ke();if(!t||!(t.banner_enabled===!0))return;const r=t.blocked_domains??{};V(r),I({blockedDomains:r,consent:{necessary:!0}}),Z();const s=await q(),i=s!==null&&!s.needs_renewal&&s.categories.functional===!0;if(G({functionalConsented:i,necessaryAllowlist:f}),P({functionalConsented:i,necessaryAllowlist:u}),i||W(),s!==null&&(N({categories:s.categories,needs_renewal:s.needs_renewal}),I({blockedDomains:r,consent:s.categories,needs_renewal:s.needs_renewal}),!s.needs_renewal))for(const[c,Te]of Object.entries(s.categories))Te===!0&&c!=="necessary"&&Y(c)}typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{X()}):X())})();