"use strict";const o=require("react/jsx-runtime"),e=require("react"),N=require("react-dom"),y=require("../tools/tools.cjs"),O=require("./modal-backdrop.cjs"),A=require("./modal-body.cjs"),K=require("./modal-content.cjs"),V=require("./modal-dialog.cjs"),z=require("./modal-footer.cjs"),p=require("./modal-header.cjs"),b=require("./modal-title.cjs"),t=function(I){const{as:W="div",backdropProps:G,body:B,bodyProps:J,centered:Q,className:h,container:s,contentProps:U,dialogProps:X,dropOldClass:C,fade:M=!0,footer:k,footerProps:Y,fullscreen:Z,header:x,headerProps:v,onVisibleChange:r,scrollable:$,size:ee,static:d,style:j,title:c,titleProps:q,toggle:oe,variables:S,visible:n=!1,...te}=I,[i,g]=e.useState(!1),[E,P]=e.useState(!1),[_,D]=e.useState(!1),[u,F]=e.useState(n),[se,T]=e.useState(n),[H,L]=e.useState(!1),[l,R]=e.useState(typeof s!="string"?s:null),w=e.useRef(null),ae=e.useMemo(()=>{const a=y.classx(!C&&"modal",M&&!l&&"fade",E&&"show",i&&"d-block",_&&"modal-static",h),f=y.stylex((m,de)=>({tKey:y.convertBsKeyToVar(de)}),S,j);return{className:a,style:f}},[i,h,l,C,M,_,E,j,S]),le=e.useCallback(()=>{if(!H){if(d){D(!0);return}F(!1),T(!1),r==null||r(!1)}},[H,r,d]),ne=e.useCallback(()=>{L(!0)},[]),re=e.useCallback(()=>{L(!1)},[]);return e.useEffect(()=>{if(u&&!i){g(!0);return}const a=w.current;if(!a)return;const f=()=>{u||g(!1),d&&D(!1)};a.addEventListener("transitionend",f);let m;return u?m=requestAnimationFrame(()=>P(!0)):P(!1),()=>{a.removeEventListener("transitionend",f),m&&cancelAnimationFrame(m)}},[i,d,u]),e.useEffect(()=>{F(n),T(n)},[n]),e.useEffect(()=>{if(typeof s=="string"){const a=s.startsWith("#")?document.getElementById(s.slice(1)):document.querySelector(s);R(a)}else R(s)},[s]),o.jsx(o.Fragment,{children:document!==void 0&&o.jsxs(o.Fragment,{children:[N.createPortal(o.jsx(W,{...te,...ae,onClick:le,ref:w,children:o.jsx(V.ModalDialog,{...X,centered:Q,fullscreen:Z,scrollable:$,size:ee,children:o.jsxs(K.ModalContent,{...U,onMouseEnter:ne,onMouseLeave:re,children:[x?o.jsxs(p.ModalHeader,{...v,children:[c&&o.jsx(b.ModalTitle,{...q,children:c}),x]}):o.jsx(p.ModalHeader,{...v,children:c&&o.jsx(b.ModalTitle,{...q,children:c})}),B&&o.jsx(A.ModalBody,{...J,children:B}),k&&o.jsx(z.ModalFooter,{...Y,children:k})]})})}),l||document.body),N.createPortal(o.jsx(O.ModalBackdrop,{...G,fade:M,toggle:oe,visible:se}),l||document.body)]})})};t.Dialog=V.ModalDialog;t.Content=K.ModalContent;t.Header=p.ModalHeader;t.Footer=z.ModalFooter;t.Title=b.ModalTitle;t.Body=A.ModalBody;t.Backdrop=O.ModalBackdrop;t.displayName="BRL.Modal";exports.Modal=t;
//# sourceMappingURL=modal.cjs.map
