/*!
 * (C) Gasco https://gasco-web-component.herokuapp.com/ - MIT License
 */
import{c as t}from"./p-67499028.js";import{c as n}from"./p-bcb6a654.js";const a=t=>n().duration(t?400:300),r=t=>{let r,e;const s=t.width+8,o=n(),i=n();return t.isEndSide?(r=s+"px",e="0px"):(r=-s+"px",e="0px"),o.addElement(t.menuInnerEl).fromTo("transform",`translateX(${r})`,`translateX(${e})`),i.addElement(t.backdropEl).fromTo("opacity",.01,.25),a(!1).addAnimation([o,i])},e=t=>{let r,e;const s=t.width;t.isEndSide?(r=-s+"px",e=s+"px"):(r=s+"px",e=-s+"px");const o=n().addElement(t.menuInnerEl).fromTo("transform",`translateX(${e})`,"translateX(0px)"),i=n().addElement(t.contentEl).fromTo("transform","translateX(0px)",`translateX(${r})`),c=n().addElement(t.backdropEl).fromTo("opacity",.01,.32);return a(!1).addAnimation([o,i,c])},s=t=>{const r=t.width*(t.isEndSide?-1:1)+"px",e=n().addElement(t.contentEl).fromTo("transform","translateX(0px)",`translateX(${r})`);return a(!1).addAnimation(e)},o=(()=>{const n=new Map,a=[],o=async t=>{if(await w(),"start"===t||"end"===t){return m((n=>n.side===t&&!n.disabled))||m((n=>n.side===t))}if(null!=t)return m((n=>n.menuId===t));return m((t=>!t.disabled))||(a.length>0?a[0].el:void 0)},i=async()=>(await w(),p()),c=(t,a)=>{n.set(t,a)},u=t=>{const n=t.side;a.filter((a=>a.side===n&&a!==t)).forEach((t=>t.disabled=!0))},p=()=>m((t=>t._isOpen)),l=()=>a.some((t=>t.isAnimating)),m=t=>{const n=a.find(t);if(void 0!==n)return n.el},w=()=>Promise.all(Array.from(document.querySelectorAll("gasco-menu")).map((n=>new Promise((a=>t(n,a))))));return c("reveal",s),c("push",e),c("overlay",r),"undefined"!=typeof document&&document.addEventListener("gascoBackButton",(t=>{const n=p();n&&t.detail.register(99,(()=>n.close()))})),{registerAnimation:c,get:o,getMenus:async()=>(await w(),a.map((t=>t.el))),getOpen:i,isEnabled:async t=>{const n=await o(t);return!!n&&!n.disabled},swipeGesture:async(t,n)=>{const a=await o(n);return a&&(a.swipeGesture=t),a},isAnimating:async()=>(await w(),l()),isOpen:async t=>{if(null!=t){const n=await o(t);return void 0!==n&&n.isOpen()}return void 0!==await i()},enable:async(t,n)=>{const a=await o(n);return a&&(a.disabled=!t),a},toggle:async t=>{const n=await o(t);return!!n&&n.toggle()},close:async t=>{const n=await(void 0!==t?o(t):i());return void 0!==n&&n.close()},open:async t=>{const n=await o(t);return!!n&&n.open()},_getOpenSync:p,_createAnimation:(t,a)=>{const r=n.get(t);if(!r)throw new Error("animation not registered");return r(a)},_register:t=>{a.indexOf(t)<0&&(t.disabled||u(t),a.push(t))},_unregister:t=>{const n=a.indexOf(t);n>-1&&a.splice(n,1)},_setOpen:async(t,n,a)=>{if(l())return!1;if(n){const n=await i();n&&t.el!==n&&await n.setOpen(!1,!1)}return t._setOpen(n,a)},_setActiveMenu:u}})();export{o as m}