import{jsx as _jsx}from"react/jsx-runtime";import React,{useEffect,useRef}from"react";import{createPortal}from"react-dom";import config from"../../../../../nitrogen.config.js";export default React.forwardRef((function({children:e,inspectorWidth:t,onClick:n,...r},o){const i=useRef(!1),c=useRef(0),d=o.current?.contentWindow?.document?.body;function u(e){if(o.current&&o.current.contentWindow)for(let t=0;t<e.length;t++){const n=e[t],r=n.attributes,i=o.current.contentWindow.document.head.childNodes,c=n.getAttribute("data-vite-dev-id")??"";for(let e=0;e<i.length;e++){const t=i[e];if(t.tagName!==n.tagName)continue;let o=!0;for(let e=0;e<r.length;e++){const n=r[e];if(t.getAttribute(n.name)!==n.value){o=!1;break}}if(o&&(!import.meta.env.DEV||-1===c.indexOf("/node_modules/simplebar-react"))){t.remove();break}}}}function a(e){if(o.current&&o.current.contentWindow)for(let t=0;t<e.length;t++){const n=e[t],r=n.attributes,i=o.current.contentWindow.document.head.childNodes,c=n.getAttribute("data-vite-dev-id")??"";for(let e=0;e<i.length;e++){const t=i[e];if(t.tagName!==n.tagName)continue;let o=!0;for(let e=0;e<r.length;e++){const n=r[e];if(t.getAttribute(n.name)!==n.value){o=!1;break}}if(o&&(!import.meta.env.DEV||-1===c.indexOf("/node_modules/simplebar-react"))){t.remove();break}}o.current.contentWindow.document.head.appendChild(n.cloneNode(!0))}}return useEffect((()=>{const e=document.querySelector("head");if(e){const t={childList:!0,subtree:!0},n=new MutationObserver(((e,t)=>{for(const t of e)"childList"===t.type&&(t.addedNodes.forEach((e=>{e.getAttribute("data-nitrogen-id")||e.setAttribute("data-nitrogen-id",""+c.current++)})),u(t.removedNodes),a(t.addedNodes))}));return n.observe(e,t),()=>{n.disconnect()}}}),[]),useEffect((()=>{o.current&&o.current.contentWindow&&!i.current&&d&&(!function(){const e=document.head.querySelectorAll(import.meta.env.DEV?"style":"style, link:not([data-noiframe])");if(!o.current||!o.current.contentWindow)return;for(let t=0;t<e.length;t++){const n=e[t].getAttribute("data-vite-dev-id")??"";e[t].getAttribute("href"),import.meta.env.DEV&&-1===n.indexOf("@nitrogenbuilder/core/src/tw.scss")&&-1===n.indexOf("@nitrogenbuilder/core/src/Bob.scss")&&(n.indexOf("@nitrogenbuilder/core/src/")>-1||-1===n.indexOf("@nitrogenbuilder/core/node_modules/simplebar-react")&&n.indexOf("@nitrogenbuilder/core/node_modules/")>-1)||(e[t].getAttribute("data-nitrogen-id")||e[t].setAttribute("data-nitrogen-id",""+c.current++),o.current.contentWindow.document.head.appendChild(e[t].cloneNode(!0)))}const t=document.createElement("style");t.innerHTML=config.cssInjection,o.current.contentWindow.document.head.appendChild(t),i.current=!0}(),o.current.contentDocument.addEventListener("contextmenu",(e=>{e.preventDefault()})),n&&o.current.contentDocument.addEventListener("click",n))}),[o.current]),_jsx("iframe",{id:"editor-iframe",...r,width:"100%",height:"100%",resize:"0",scrolling:"0",ref:o,children:d&&createPortal(e,d)})}));