document.addEventListener("DOMContentLoaded",(()=>{setInterval((function(){const{url:e,directories:t}=maxiblocks;if(!t)return;const i="1.1.9";t.forEach((t=>{const o=t.split("/").pop();let s=o;"page-404"===o&&(s="page:-404");const r=`edit-site-patterns-maxiblocks-go/${s}`,a=document.getElementById(r)||document.getElementById(s);if(!a||a.classList.contains("maxiblocks-go-custom-pattern")||a.classList.contains("query-results")){const t=document.querySelectorAll("div.dataviews-view-grid, div.block-editor-block-patterns-list");if(!t||0===t.length)return;t.forEach((t=>{const r=t.querySelectorAll(":scope > .dataviews-view-grid__card, .block-editor-block-patterns-list__list-item");if(!r||0===r.length)return;let a=!0;r.forEach((t=>{if(t.classList.contains("maxiblocks-go-custom-pattern"))return void(a=!1);const r=t.querySelector("div.edit-site-patterns__pattern-title")||t.querySelector("div.dataviews-view-grid__title-actions");let c=t.querySelector("div.block-editor-block-patterns-list__item")?.id;if(c&&!c.includes("maxiblocks-go/")&&(c=t.querySelector("div.block-editor-block-patterns-list__item")?.getAttribute("aria-label")?.toLowerCase()?.replace(/\s+/g,"-")),r||c){const l=r?r?.textContent?.toLowerCase()?.replace(/\s+/g,"-"):c?.replace("maxiblocks-go/","");if(l===s){a=!1;const s=`${e}${o}/preview-${o}.webp`,r=`${l} preview image`,c=t.querySelector(".maxi-blocks-pattern-preview img");if(c)c.src=s,c.alt=r,c.classList.add("maxiblocks-go-pattern-preview-image"),t.classList.add("maxiblocks-go-custom-pattern");else{const e=t.querySelector(".block-editor-block-preview__container iframe");if(e){if(!e?.parentNode)return;const o=new Image;o.src=`${s}?ver=${i}`,o.alt=r,o.classList.add("maxiblocks-go-pattern-preview-image"),e.parentNode?.insertBefore(o,e),e.style.display="none";const a=e.parentNode?.querySelector("img.maxi-blocks-pattern-preview-image");a&&(a.style.display="none"),t.classList.add("maxiblocks-go-custom-pattern")}}}else if(a){a=!1;if(!document.querySelector(".edit-site-start-template-options__modal"))return;const e=wp.data.select("core/edit-site")?.getEditedPostContext()?.templateSlug||wp?.data?.select("core/edit-site")?.getEditedPostId();if(!e.includes("maxiblocks-go//"))return;const i=`MaxiBlocks Go template type: ${function(e){let t;return t=e.includes("category")||e.includes("tag")||e.includes("author")||e.includes("taxonomy")||e.includes("date")?"Archive":e.includes("404")?"404 Not Found":e.includes("home")?"Blog Home":e.includes("front-page")?"Front Page":e.includes("search")?"Search":e.includes("single")?"Single Post":"Index",t}(e.replace("maxiblocks-go//",""))}`,o=t.querySelector(".block-editor-block-patterns-list__item-title");if(!o)return;o.textContent=i,t.classList.add("maxiblocks-go-custom-pattern")}}}))}))}else{const t=a.querySelector("iframe"),s=a.querySelector(".maxi-blocks-pattern-preview img"),r=`${e}${o}/preview-${o}.webp`,c=`${o} preview image`;if(t||s){a.classList.add("maxiblocks-go-custom-pattern");const e=new Image;if(e.src=`${r}?ver=${i}`,e.alt=c,e.classList.add("maxiblocks-go-pattern-preview-image"),t){const i=t?.parentNode;if(!i)return;try{i.insertBefore(e,t),t.style.display="none";const o=i.querySelector("img.maxi-blocks-pattern-preview-image");o&&(o.style.display="none")}catch(e){console.error("Error replacing iframe with image:",e)}}else s&&(s.src=r,s.alt=c,s.classList.add("maxiblocks-go-pattern-preview-image"))}}}))}),500)}));