"use client"
import{f as u}from"./chunk-NTYX2MSW.mjs";import{createContext as h,useCallback as p,useContext as K,useEffect as l,useId as m,useState as g}from"react";import{jsx as v}from"react/jsx-runtime";var b=h({listeners:[],setListeners:()=>{}});function C({children:t}){let[s,n]=g([]);return v(b.Provider,{value:{listeners:s,setListeners:n},children:t})}function N(t,s,n={}){let o=m(),{listeners:d,setListeners:c}=K(b),a=p(e=>{let r=e.target,S=document.getElementById("modal-backdrop");if(e.metaKey||e.ctrlKey||r.tagName==="INPUT"||r.tagName==="TEXTAREA"||S||(Array.isArray(t)?!t.includes(e.key):e.key!==t))return;let y=d.filter(i=>i.enabled!==!1&&(Array.isArray(i.key)?i.key.includes(e.key):i.key===e.key));y.length&&u(y,(L,f)=>(f.priority??0)-(L.priority??0)).slice(-1)[0].id!==o||(e.preventDefault(),s(e))},[t,d,o,s]);l(()=>(document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)),[a]),l(()=>(c(e=>[...e.filter(r=>r.id!==o),{id:o,key:t,...n}]),()=>c(e=>e.filter(r=>r.id!==o))),[JSON.stringify(t),n.enabled,n.priority])}export{b as a,C as b,N as c};
