!function(){"use strict";const t=new BroadcastChannel("DOBARE-CUSTOMER-CREDIT");let e=null,n=null,o=!1,a=null;const d=async()=>{const t=`${window.wpApiSettings.root}dobare/v1/customer-credit/?_=${Date.now()}`;try{const e=await fetch(t,{headers:{"X-WP-Nonce":wpApiSettings.nonce}});if(!e.ok)throw new Error(`Response status: ${e.status}`);return await e.json()}catch(t){return console.error("❌ Customer Credit Widget: Failed to fetch customer credit data:",t.message),null}},r=()=>{n&&e&&t.postMessage({key:"SEND_CREDIT_DATA",data:Object.assign({},n.data,{currency:window.dobareCustomerCreditData&&window.dobareCustomerCreditData.currency||"تومان"})})};t.onmessage=function(t){switch(t.data.key){case"IFRAME_READY":r();break;case"CREDIT_VIEWED":default:break;case"REMOVE_DOBARE_CREDIT_IFRAME":e&&e.parentNode&&(e.parentNode.removeChild(e),e=null)}};const s=async()=>{if(!window.wpApiSettings||!window.dobareCustomerCreditData)return;document.getElementById("dob-lead-magnet");const t=await d();t&&t.meta&&200===t.meta.status_code&&t.data&&(n=t,(()=>{if(!n||!n.meta||200!==n.meta.status_code||!n.data.is_active)return;if(document.getElementById("dobare-customer-credit"))return e=document.getElementById("dobare-customer-credit"),void r();const t=document.createElement("iframe");if(t.src=window.dobareCustomerCreditData.iframeSrc,t.style.border="none",t.style.width="200px",t.style.height="180px",t.style.position="fixed",t.style.bottom="20px",t.style.zIndex="9998",t.style.overflow="visible",t.style.transition="height 0.3s ease-in-out",t.loading="lazy",t.id="dobare-customer-credit","L"===(n.data.position||"R")?(t.style.left="20px",t.style.right="auto"):(t.style.right="20px",t.style.left="auto"),!document.getElementById("dobare-customer-credit-styles")){const t=document.createElement("style");t.id="dobare-customer-credit-styles",t.textContent="\n\t\t\t\t@media (max-width: 480px) {\n\t\t\t\t\t#dobare-customer-credit {\n\t\t\t\t\t\twidth: 180px !important;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t",document.head.appendChild(t)}t.addEventListener("load",()=>{r()}),"true"!==function(){const t="dobare_customer_credit_dismissed=",e=document.cookie.split(";");for(let n=0;n<e.length;n++){let o=e[n];for(;" "===o.charAt(0);)o=o.substring(1,o.length);if(0===o.indexOf(t))return decodeURIComponent(o.substring(33,o.length))}return null}()&&document.body.appendChild(t),e=t,o=!0})())},i=function(){"requestIdleCallback"in window?window.requestIdleCallback(()=>{s()},{timeout:3e3}):setTimeout(s,0)};"complete"===document.readyState?i():window.addEventListener("load",i),a=setInterval(async()=>{if(o){const t=await d();t&&t.meta&&200===t.meta.status_code&&t.data&&(n=t,r())}},3e5),window.dobareCreditWidgetCleanup=function(){a&&(clearInterval(a),a=null),e&&e.parentNode&&(e.parentNode.removeChild(e),e=null),o=!1}}();