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,...t},n){const r=useRef(!1),o=useRef(0),i=n.current?.contentWindow?.document?.body;function c(e){if(n.current&&n.current.contentWindow)for(let t=0;t<e.length;t++){const r=e[t],o=r.attributes,i=n.current.contentWindow.document.head.childNodes,c=r.getAttribute("data-vite-dev-id")??"";for(let e=0;e<i.length;e++){const t=i[e];if(t.tagName!==r.tagName)continue;let n=!0;for(let e=0;e<o.length;e++){const r=o[e];if(t.getAttribute(r.name)!==r.value){n=!1;break}}if(n&&(!import.meta.env.DEV||-1===c.indexOf("/node_modules/simplebar-react"))){t.remove();break}}}}function d(e){if(n.current&&n.current.contentWindow)for(let t=0;t<e.length;t++){const r=e[t],o=r.attributes,i=n.current.contentWindow.document.head.childNodes,c=r.getAttribute("data-vite-dev-id")??"";for(let e=0;e<i.length;e++){const t=i[e];if(t.tagName!==r.tagName)continue;let n=!0;for(let e=0;e<o.length;e++){const r=o[e];if(t.getAttribute(r.name)!==r.value){n=!1;break}}if(n&&(!import.meta.env.DEV||-1===c.indexOf("/node_modules/simplebar-react"))){t.remove();break}}n.current.contentWindow.document.head.appendChild(r.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",""+o.current++)})),c(t.removedNodes),d(t.addedNodes))}));return n.observe(e,t),()=>{n.disconnect()}}}),[]),useEffect((()=>{n.current&&n.current.contentWindow&&!r.current&&i&&function(){const e=document.head.querySelectorAll(import.meta.env.DEV?"style":"style, link:not([data-noiframe])");if(!n.current||!n.current.contentWindow)return;for(let t=0;t<e.length;t++){const r=e[t].getAttribute("data-vite-dev-id")??"";e[t].getAttribute("href"),import.meta.env.DEV&&-1===r.indexOf("@nitrogenbuilder/core/src/tw.scss")&&-1===r.indexOf("@nitrogenbuilder/core/src/Bob.scss")&&(r.indexOf("@nitrogenbuilder/core/src/")>-1||-1===r.indexOf("@nitrogenbuilder/core/node_modules/simplebar-react")&&r.indexOf("@nitrogenbuilder/core/node_modules/")>-1)||(e[t].getAttribute("data-nitrogen-id")||e[t].setAttribute("data-nitrogen-id",""+o.current++),n.current.contentWindow.document.head.appendChild(e[t].cloneNode(!0)))}const t=document.createElement("style");t.innerHTML=config.cssInjection,n.current.contentWindow.document.head.appendChild(t),r.current=!0}()}),[n.current]),_jsx("iframe",{id:"editor-iframe",...t,width:"100%",height:"100%",resize:"0",scrolling:"0",ref:n,children:i&&createPortal(e,i)})}));