!function(){"use strict";var e=["ar","he","ur","fa"];function t(){document.querySelectorAll(".ez-moon-phase-widget:not([data-ezhp-initialized])").forEach(function(t){t.setAttribute("data-ezhp-initialized","true");var a,n=t.querySelector(".ez-moon-zodiac-dropdown"),o=t.querySelector(".ez-moon-content-result"),r=t.dataset.language||"en",c=(a=r,-1!==e.indexOf(a)||"rtl"===t.getAttribute("dir")),i="true"===t.dataset.ctaEnabled,l=t.dataset.ctaText||"",d=t.dataset.ctaImageUrl||"",s=t.dataset.ctaImageAlt||"",m=t.dataset.ctaUrl||"",p=t.dataset.ctaLinkType||"button",u=t.dataset.ctaLinkText||"",g="true"===t.dataset.ctaImageClickable,h=t.dataset.ctaElementId||"";n&&o&&n.addEventListener("change",function(){var e=this.value;if(e){o.innerHTML='<div class="ezhp-progress-container"><div class="ezhp-progress-bar"></div></div>';var t="/wp-json/ezhp/v1/moon-content?zodiacSign="+encodeURIComponent(e)+"&language="+encodeURIComponent(r);fetch(t,{method:"GET",headers:{Accept:"application/json"}}).then(function(e){if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(function(e){if(e&&e.moonContentHtml){var t=e.moonContentHtml;i&&m&&(t=function(e,t){var a=(new DOMParser).parseFromString(e,"text/html"),n=a.querySelector('[data-elementid="cb-moon-reading"]');if(!n)return e;var o=a.createElement("div");if(o.className="ez-moon-cta",t.ctaElementId&&(o.id=t.ctaElementId),t.ctaText){var r=a.createElement("p");r.className="ez-moon-cta-text",r.textContent=t.ctaText,o.appendChild(r)}if(t.ctaImageUrl){var c=a.createElement("img");if(c.src=t.ctaImageUrl,c.alt=t.ctaImageAlt||"",c.className="ez-moon-cta-image","image"===t.ctaLinkType||t.ctaImageClickable){var i=a.createElement("a");i.href=t.ctaUrl,i.target="_blank",i.rel="noopener noreferrer",i.className="ez-moon-cta-image-link",i.appendChild(c),o.appendChild(i)}else o.appendChild(c)}if("image"!==t.ctaLinkType&&t.ctaLinkText){var l=a.createElement("a");l.href=t.ctaUrl,l.target="_blank",l.rel="noopener noreferrer",l.textContent=t.ctaLinkText,l.className="button"===t.ctaLinkType?"wp-element-button ez-moon-cta-button":"ez-moon-cta-link",o.appendChild(l)}return n.parentNode.replaceChild(o,n),a.body.innerHTML}(t,{ctaText:l,ctaImageUrl:d,ctaImageAlt:s,ctaUrl:m,ctaLinkType:p,ctaLinkText:u,ctaImageClickable:g,ctaElementId:h,isRtl:c})),o.innerHTML=t}else o.innerHTML="<p>No moon content available for this sign.</p>"}).catch(function(e){o.innerHTML="<p>Unable to load moon content. Please try again.</p>",console.error("EZ Moon Phase Widget Error:",e)})}else o.innerHTML=""})})}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",t):t(),new MutationObserver(function(e){var a=!1;e.forEach(function(e){e.addedNodes.length&&e.addedNodes.forEach(function(e){1===e.nodeType&&(e.classList&&e.classList.contains("ez-moon-phase-widget")||e.querySelector&&e.querySelector(".ez-moon-phase-widget"))&&(a=!0)})}),a&&t()}).observe(document.body,{childList:!0,subtree:!0})}();