!function(){"use strict";const e=new BroadcastChannel("DOBARE-CUSTOMER-CREDIT"),t=document.getElementById("credit-button"),a=document.getElementById("credit-popup"),d=document.getElementById("credit-amount"),n=document.getElementById("customer-credit-container"),s=document.getElementById("credit-toggle");let o=!1,c=null;const i=()=>{(()=>{const e=[`dobare_customer_credit_dismissed=${encodeURIComponent("true")}`,"path=/"];e.push(`max-age=${Math.max(0,Math.floor(3600))}`),document.cookie=e.join("; ")})(),e.postMessage({key:"REMOVE_DOBARE_CREDIT_IFRAME"})};window.removeCreditIframeFromDom=i;const r=()=>{o=!o,o?(a.classList.remove("hidden"),n.classList.remove("collapsed"),n.classList.add("expanded"),t&&t.setAttribute("aria-expanded","true"),e.postMessage({key:"CREDIT_VIEWED",data:c})):(a.classList.add("hidden"),n.classList.remove("expanded"),n.classList.add("collapsed"),t&&t.setAttribute("aria-expanded","false"))};t.addEventListener("click",e=>{e.stopPropagation(),r()}),s&&s.addEventListener("click",e=>{e.stopPropagation(),i()}),document.addEventListener("click",e=>{o&&!n.contains(e.target)&&r()}),e.onmessage=function(e){switch(e.data.key){case"SEND_CREDIT_DATA":c=e.data.data,(()=>{if(c&&c.credit_amount){const t=c.currency||"تومان";d.textContent=((e=c.credit_amount)&&0!==e?e.toString().replace(/\B(?=(\d{3})+(?!\d))/g,"٬").replace(/\d/g,e=>"۰۱۲۳۴۵۶۷۸۹"[e]):"۰")+" "+t}var e})();break;case"UPDATE_POSITION":default:break;case"POPUP_DISMISS":i()}},window.addEventListener("load",()=>{e.postMessage({key:"IFRAME_READY"})}),window.addEventListener("resize",()=>{})}();