"use strict";const L=require("react/jsx-runtime"),n=require("react"),w=require("../button/button.cjs"),C=require("../tools/tools.cjs"),N=require("./alert-heading.cjs"),R=require("./alert-link.cjs"),g={clickToClose:!0},j=A=>{const{clickToClose:c,dismissible:d,fade:t,onVisibleChange:s,visible:e}=A,[l,i]=n.useState(!t&&typeof e=="boolean"?e:!0),[a,o]=n.useState(!1),b=n.useRef(null),f=n.useCallback(()=>{t?o(!1):i(!1)},[t]),m=n.useCallback(()=>{typeof e=="boolean"&&d||c&&f(),s==null||s(!e)},[c,d,f,s,e]);return n.useEffect(()=>{typeof e=="boolean"?t?e?i(!0):o(!1):i(e):t&&o(!0)},[t,e]),n.useEffect(()=>{if(!t)return;const r=b.current;if(r){const k=()=>{typeof e=="boolean"?e||i(!1):!a&&l&&i(!1)};return r.addEventListener("transitionend",k),typeof e=="boolean"&&e&&requestAnimationFrame(()=>{o(!0)}),()=>r.removeEventListener("transitionend",k)}},[t,e,l,a]),{alertElement:b,handleClose:m,isShowing:a,isVisible:l}},v=function(c){const{as:d="div",className:t,clickToClose:s=g.clickToClose,closeButton:e,closeButtonProps:l,dismissible:i,dropOldClass:a,fade:o,onVisibleChange:b,style:f,variables:m,variant:r,visible:k,...S}=c,{alertElement:T,handleClose:E,isShowing:q,isVisible:p}=j({clickToClose:s,dismissible:i,fade:o,onVisibleChange:b,visible:k}),x=n.useCallback(u=>{var y;E(),(y=l==null?void 0:l.onClick)==null||y.call(l,u)},[l,E]),_=n.useMemo(()=>{const u=C.classx(!a&&"alert",r&&`alert-${r}`,i&&"alert-dismissible",o&&"fade",q&&"show",t),y=C.stylex((H,h)=>({tKey:C.convertBsKeyToVar(h)}),m,f);return{className:u,style:y}},[t,i,a,o,q,f,m,r]);return p&&L.jsxs(d,{...S,..._,ref:T,children:[c.children,i&&(e||L.jsx(w.Button,{btnClose:!0,...C.mergeProps(l,{onClick:u=>x(u)})}))]})};v.Link=R.AlertLink;v.Heading=N.AlertHeading;v.displayName="BRL.Alert";exports.Alert=v;
//# sourceMappingURL=alert.cjs.map
