"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("vue"),o=require("../../_util/KeyCode.js"),b=require("../../_util/raf.js"),D=require("../utils/uiUtil.js");function p({open:a,value:M,isClickOutside:r,triggerOpen:f,forwardKeydown:c,onKeydown:T,blurToCancel:y,onSubmit:d,onCancel:h,onFocus:w,onBlur:R}){const u=l.shallowRef(!1),s=l.shallowRef(!1),v=l.shallowRef(!1),n=l.shallowRef(!1),m=l.shallowRef(!1),q=l.computed(()=>({onMousedown:()=>{u.value=!0,f(!0)},onKeydown:e=>{if(T(e,()=>{m.value=!0}),!m.value){switch(e.which){case o.default.ENTER:{a.value?d()!==!1&&(u.value=!0):f(!0),e.preventDefault();return}case o.default.TAB:{u.value&&a.value&&!e.shiftKey?(u.value=!1,e.preventDefault()):!u.value&&a.value&&!c(e)&&e.shiftKey&&(u.value=!0,e.preventDefault());return}case o.default.ESC:{u.value=!0,h();return}}!a.value&&![o.default.SHIFT].includes(e.which)?f(!0):u.value||c(e)}},onFocus:e=>{u.value=!0,s.value=!0,w&&w(e)},onBlur:e=>{if(v.value||!r(document.activeElement)){v.value=!1;return}y.value?setTimeout(()=>{let{activeElement:t}=document;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;r(t)&&h()},0):a.value&&(f(!1),n.value&&d()),s.value=!1,R&&R(e)}}));l.watch(a,()=>{n.value=!1}),l.watch(M,()=>{n.value=!0});const i=l.shallowRef();return l.onMounted(()=>{i.value=D.addGlobalMousedownEvent(e=>{const t=D.getTargetFromEvent(e);if(a.value){const E=r(t);E?(!s.value||E)&&f(!1):(v.value=!0,b.default(()=>{v.value=!1}))}})}),l.onBeforeUnmount(()=>{i.value&&i.value()}),[q,{focused:s,typing:u}]}exports.default=p;
