(()=>{"use strict";const t=window.wp.i18n;document.addEventListener("DOMContentLoaded",function(){const e=document.querySelectorAll(".godam-pdf-wrapper");function n(t){try{t=String(t).trim();const e=new URL(t,window.location.href);return("http:"===e.protocol||"https:"===e.protocol)&&e.pathname.toLowerCase().endsWith(".pdf")}catch(t){return!1}}const r=/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,o=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);r||o?e.forEach(function(t){const e=t.querySelector('object[type="application/pdf"]');if(!e)return;const r=e.getAttribute("data-sources");if(!r)return;let o=[];try{o=JSON.parse(r)}catch(t){return}function c(t){return t+"?v="+Date.now()}async function i(t){try{return(await fetch(t,{method:"HEAD",cache:"no-store"})).ok}catch(t){return!1}}o.length,setTimeout(async function(){for(const t of o){if(!n(t))continue;const r=c(t);if(await i(r))return void e.setAttribute("data",encodeURI(r))}},100)}):e.forEach(function(e){const r=e.querySelector('object[type="application/pdf"]');if(!r)return;const o=r.getAttribute("data-sources");if(!o)return;let c=[];try{c=JSON.parse(o)}catch(t){return}if(0===c.length)return;let i=null;function a(r){if(r>=c.length){const n=e.querySelector('object[type="application/pdf"]'),r=n?n.querySelector("p"):null;return void(r&&(r.innerHTML=(0,t.__)("<strong>Unable to load PDF.</strong> All sources are unavailable.","godam")))}const u=c[r];n(u)?function(t,r){if(!n(t))return;const c=e.querySelector('object[type="application/pdf"]');if(!c)return;if(c.getAttribute("data")===t)return;const u=document.createElement("object");u.id=c.id||"pdfObject",u.type="application/pdf",u.width="100%",u.height="100%",u.setAttribute("data",encodeURI(t)),u.setAttribute("data-sources",o),u.setAttribute("data-current-index",r);const d=c.querySelector("p");if(d){const e=d.cloneNode(!0),r=e.querySelector("a");r&&n(t)&&(r.href=encodeURI(t)),u.appendChild(e)}u.addEventListener("error",function(){const t=parseInt(u.getAttribute("data-current-index")||"0",10);i&&clearTimeout(i),a(t+1)}),c.parentNode.replaceChild(u,c)}(u,r):a(r+1),i&&clearTimeout(i),i=setTimeout(function(){const t=e.querySelector('object[type="application/pdf"]'),n=t?t.querySelector("p"):null;var o;n&&(o=n).offsetWidth>0&&o.offsetHeight>0&&a(r+1)},1e4)}r.addEventListener("error",function(){const t=parseInt(r.getAttribute("data-current-index")||"0",10);i&&clearTimeout(i),a(t+1)}),r.setAttribute("data-current-index","0")})})})();