import{toConsumableArray as l}from"../../_virtual/_rollupPluginBabelHelpers.js";import{useCallback as n,useEffect as e}from"react";import o from"./useAnimationProps.js";import i from"../../hooks/useKeyEvent/index.js";function t(t){var a=t.instance,u=t.show,r=t.onClose,s=t.alertDialog,d=o(t.triggerElement,a),c=n((function(){s||null==r||r()}),[s,r]);return i({callback:function(l){(null==a?void 0:a.$el.contains(document.activeElement))&&(l.stopPropagation(),c())},capture:!0,keys:["Escape"]}),e((function(){var n,e,o;if(a){var i,t=null==a?void 0:a.$el.childNodes[1].animate;if(u)null==a||a.show(),t&&(null===(e=null==a?void 0:(n=a.$el.childNodes[1]).animate)||void 0===e||(i=e).call.apply(i,[n].concat(l(d()))));else if(t){var r,s=null===(o=null==a?void 0:a.$el.childNodes[1])||void 0===o?void 0:(r=o).animate.apply(r,l(d(!0)));null==s||s.finished.then((function(){return null==a?void 0:a.hide()}))}else null==a||a.hide()}}),[u,a,d]),e((function(){return null==a||a.on("hide",(function(){return null==r?void 0:r()})),function(){null==a||a.off("hide")}}),[a,r]),{closeDialogIfNeeded:c}}export{t as default};
