(()=>{(function(){"use strict";function p(){try{const t=new URLSearchParams(window.location.search).get("fleek-compat");if(t&&["trusted","windowed","windowed-light","windowed-dark","protected","protected-dark"].includes(t))return t}catch{}try{if(window.parent&&window.parent!==window&&window.frameElement){const e=window.frameElement.closest(".fleek-window");return e?e.getAttribute("data-mode")||"windowed":"trusted"}}catch{}return null}function m(e){return e==="protected"||e==="protected-dark"}function T(e,t){return e==="windowed-light"||e==="protected"?!1:e==="windowed-dark"||e==="protected-dark"?!0:t}function b(){const e=globalThis.FleekDashIframeWpwrapPin;e&&typeof e.refresh=="function"?e.refresh():e&&typeof e.apply=="function"&&e.apply()}function g(e,t,u=null,s=!1){const n=u||document.documentElement,i=T(e,t),o=n.classList.contains("dark"),d=n.classList.contains("light");(o!==i||!o&&!d)&&(n.classList.remove("dark","light"),n.classList.add(i?"dark":"light"),s&&(window.parent?.window?.FleekDash?.debug||window.FleekDash?.debug));const l=["fleek-mode-trusted","fleek-mode-windowed","fleek-mode-windowed-light","fleek-mode-windowed-dark","fleek-mode-protected","fleek-mode-protected-dark"];return n.classList.remove(...l),e&&n.classList.add(`fleek-mode-${e}`),b(),{isDark:i,mode:e,source:m(e)?"forced":"dynamic"}}function D(e,t){if(typeof e!="string")return;const u=t||p();if(m(u)){const n=document.getElementById("fleekdash-palette-vars");n&&n.remove();return}let s=document.getElementById("fleekdash-palette-vars");s||(s=document.createElement("style"),s.id="fleekdash-palette-vars",document.head.appendChild(s)),s.textContent=e,b()}function k(){try{const e=localStorage.getItem("fleekdash-dark-mode")==="true",t=localStorage.getItem("fleekdash-theme")||"starter";return{isDark:e,theme:t}}catch{return{isDark:!1,theme:"starter"}}}function y(){try{if(window.parent&&window.parent!==window&&window.parent.document){const e=window.parent.document.documentElement,t=e.classList.contains("dark"),u=e.getAttribute("data-theme")||"starter";return{isDark:t,theme:u}}}catch{}return null}function v(){try{if(window.frameElement){const e=window.frameElement.closest(".fleek-window");if(e){const t=e.getAttribute("data-mode")||"protected";return{isDark:e.classList.contains("dark"),mode:t}}}}catch{}return null}function w(e={}){const{verbose:t=!1,updateLocalStorage:u=!0,forcedMode:s=null}=e,n=s||p();let i=!1,o="default",d="starter";if(n&&m(n)){o="forced";const c=y();c&&c.theme?d=c.theme:d=k().theme||"starter"}else{const c=y();if(c)i=c.isDark,d=c.theme||"starter",o="parent";else{const h=k();i=h.isDark,d=h.theme||"starter",o="localStorage"}}document.documentElement.setAttribute("data-theme",d);const l=g(n||"windowed",i,document.documentElement,t);if(u&&!m(n)&&!(window.parent!==window))try{localStorage.setItem("fleekdash-dark-mode",String(l.isDark))}catch{}return t&&(window.parent?.window?.FleekDash?.debug||window.FleekDash?.debug),l}function E(e={}){const{verbose:t=!1,observeParent:u=!0,listenStorage:s=!0,listenMessages:n=!0}=e;let i=0,o=null,d=0;w({verbose:t,updateLocalStorage:!1});let l=null;const c=function(a){if(a.key==="fleekdash-dark-mode"||a.key==="fleekdash-color-mode-preference"||a.key==="fleekdash-theme"){const r=p();if(m(r))return;w({verbose:t,updateLocalStorage:!1})}},h=function(a){if(a.data&&a.data.type==="themeChange"){const r=a.data.mode||p(),S=a.data.isDarkMode;if(typeof a.data.paletteVarsCss=="string"&&D(a.data.paletteVarsCss,r),r==="trusted"||r==="windowed"||!r)if(S!=null){const L=Date.now();i=L,o&&clearTimeout(o),g(r||"windowed",S===!0,document.documentElement,!1),requestAnimationFrame(function(){d++;const F=d,C=L;o=setTimeout(function(){F===d&&C===i&&(i=0,o=null)},100)})}else w({verbose:!1,updateLocalStorage:!1,forcedMode:r||null});else w({verbose:!1,updateLocalStorage:!1,forcedMode:r})}};if(s&&typeof Storage<"u"&&window.addEventListener("storage",c),n&&window.addEventListener("message",h),u&&window.parent&&window.parent!==window)try{const a=window.parent.document;if(l=new MutationObserver(function(){Date.now()-i<150||w({verbose:!1})}),l.observe(a.documentElement,{attributes:!0,attributeFilter:["data-theme","class"]}),window.frameElement){const r=window.frameElement.closest(".fleek-window");r&&l.observe(r,{attributes:!0,attributeFilter:["class","data-mode"]})}}catch{}return function(){l&&(l.disconnect(),l=null),s&&typeof Storage<"u"&&window.removeEventListener("storage",c),n&&window.removeEventListener("message",h),o&&(clearTimeout(o),o=null)}}let f=null;const M=E;function I(e={}){return f&&typeof f=="function"&&f(),f=M(e),f}window.addEventListener("beforeunload",function(){f&&(f(),f=null)}),window.fleekDashThemeSync={getParentWindowMode:p,shouldIgnoreThemeChange:m,getThemeBasedOnMode:T,applyThemeBasedOnMode:g,applyPaletteVars:D,getThemeFromLocalStorage:k,getThemeFromParent:y,getThemeFromContainer:v,syncTheme:w,setupThemeSync:I,version:"2.0.0"}})();})();
