import{s as e}from"./chunk-Bj-mKKzh.js";import{n as t}from"./jsx-runtime-CiQ1k8xo.js";import{t as n}from"./react-dom-CvzHKZGB.js";import{t as r}from"./browser-sidebar-manager-BtbIv4P0.js";var i=e(t(),1),a=e(n(),1);function o({adoptionLease:e,adoptedWebContentsId:t,bounds:n,browserTabId:o,children:l,conversationId:u,hostKind:d,initialUrl:f,isVisible:p,scale:m,shouldBootstrapWhenHidden:h,shouldPaint:g,webviewRef:_,windowZoom:v}){let y=(0,i.useRef)(null),b=(0,i.useRef)(!1),x=(0,i.useRef)(r.getMountGeneration(u,o)),S=(0,i.useRef)(c(u,o)),C=(0,i.useSyncExternalStore)(e=>r.subscribe(e),()=>r.getCursorOverlayHost(u,o),()=>null);S.current=c(u,o),(0,i.useLayoutEffect)(()=>(b.current=!0,()=>{b.current=!1}),[]);let w=p&&n!=null;return(0,i.useLayoutEffect)(()=>{if(s({hasManagedWebview:y.current!=null,isPresented:w,shouldBootstrapWhenHidden:h})===`skip`){x.current=r.releaseMountGeneration(u,o);return}return x.current=r.claimMountGeneration(u,o),()=>{r.releaseMountGeneration(u,o)}},[o,u,w,h]),(0,i.useLayoutEffect)(()=>{let e=c(u,o);return()=>{let t=y.current,n=x.current;queueMicrotask(()=>{let i=S.current;if(!(b.current&&i===e)&&t!=null){r.detachElectronWebview(t,_,n),y.current===t&&(y.current=null);return}})}},[o,u,_]),(0,i.useLayoutEffect)(()=>{y.current?.disposed&&(y.current=null);let i=y.current,a=s({hasManagedWebview:i!=null,isPresented:w,shouldBootstrapWhenHidden:h});if(a===`skip`){i!=null&&r.detachElectronWebview(i,_,x.current),y.current===i&&(y.current=null);return}let c=r.getWebview(u,o,f,{adoptionLease:e,adoptedWebContentsId:t,hostKind:d});y.current=c,r.syncElectronWebview(c,{bounds:n,isVisible:w,mountGeneration:x.current,scale:m,shouldBootstrap:a===`bootstrap`,shouldPaint:g,windowZoom:v},_,d)},[o,u,d,f,e,t,n,w,m,g,h,_,v]),C==null||l==null?null:(0,a.createPortal)(l,C)}function s({hasManagedWebview:e,isPresented:t,shouldBootstrapWhenHidden:n}){return t?`sync`:n?e?`sync`:`bootstrap`:`skip`}function c(e,t){return`${e}\0${t}`}export{o as t};
//# sourceMappingURL=browser-sidebar-webview-BiStOkKQ.js.map