export*from"@vaadin/master-detail-layout/vaadin-master-detail-layout.js";import{MasterDetailLayout as v}from"@vaadin/master-detail-layout/vaadin-master-detail-layout.js";import*as L from"react";import{createComponent as R}from"./utils/createComponent.js";var P={onBackdropClick:"backdrop-click",onDetailEscapePress:"detail-escape-press"},m=R({elementClass:v,events:P,react:L,tagName:"vaadin-master-detail-layout"});import s,{useEffect as k,useLayoutEffect as x,useRef as p,useState as f}from"react";import{Fragment as A,jsx as d,jsxs as N}from"react/jsx-runtime";function D({children:t}){return t}function b(t,e){let n=s.Children.toArray(t).filter(a=>s.isValidElement(a)),l=s.Children.toArray(e).filter(a=>s.isValidElement(a));if(n.length!==l.length)return!0;for(let a=0;a<n.length;a++){let r=n[a],i=l[a];if(r.type!==i.type||r.key!==i.key)return!0}return!1}function M({children:t}){let e=p(null),n=p(0),l=p(null),a=n.current+1,[r,i]=f("idle"),[c,y]=f(t);return x(()=>{let u=e.current?.closest("vaadin-master-detail-layout");if(u){if(r==="idle"){let o=e.current.childElementCount>0;e.current.setAttribute("slot",o?"detail":"detail-hidden")}else if(r==="starting"){let o=e.current.childElementCount>0,E=l.current.childElementCount>0,C=o&&E?"replace":o?"remove":"add";u._startTransition(C,()=>{i("ready"),y(t),n.current=a})}else if(r==="ready"){let o=e.current.childElementCount>0;e.current.setAttribute("slot",o?"detail":"detail-hidden"),u._finishTransition().then(()=>{i("idle")})}}},[r,c]),k(()=>{r==="idle"&&(b(c,t)?i("starting"):y(t))},[r,t]),N(A,{children:[d("div",{ref:e,style:{display:"contents"},children:c},n.current),r==="starting"&&d("div",{ref:l,style:{display:"none"},children:t},a)]})}function _(t){s.Children.forEach(t,e=>{if(s.isValidElement(e)&&e.type!==D&&e.type!==M)throw new Error("Invalid child in MasterDetailLayout. Only <MasterDetailLayout.Master> and <MasterDetailLayout.Detail> components are allowed. Check the component docs for proper usage.")})}var g=t=>(_(t.children),d(m,{...t})),h=g;h.Master=D;h.Detail=M;export{h as MasterDetailLayout,v as MasterDetailLayoutElement};
//# sourceMappingURL=MasterDetailLayout.js.map
