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