import{jsx as _jsx}from"react/jsx-runtime";import React,{useEffect,useRef}from"react";import{createPortal}from"react-dom";import config from"@parent/nitrogen.config.ts";export default React.forwardRef((function({children:e,...t},n){const r=useRef(!1),o=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,c=n.current.contentWindow.document.head.childNodes;for(let e=0;e<c.length;e++){const t=c[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){t.remove();break}}}}function i(e){if(n.current&&n.current.contentWindow)for(let t=0;t<e.length;t++){const r=e[t],o=r.attributes,c=n.current.contentWindow.document.head.childNodes;for(let e=0;e<c.length;e++){const t=c[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){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&&(c(t.removedNodes),i(t.addedNodes))}));return n.observe(e,t),()=>{n.disconnect()}}}),[]),useEffect((()=>{n.current&&n.current.contentWindow&&!r.current&&o&&function(){const e=document.head.querySelectorAll("style");if(!n.current||!n.current.contentWindow)return;for(let t=0;t<e.length;t++){const r=e[t].getAttribute("data-vite-dev-id")??"";-1===r.indexOf("nitrogen/src/tw.scss")&&-1===r.indexOf("nitrogen/src/Bob.scss")&&(r.indexOf("nitrogen/src/")>-1||-1===r.indexOf("nitrogen/node_modules/simplebar-react")&&r.indexOf("nitrogen/node_modules/")>-1)||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:o&&createPortal(e,o)})}));