"use client"
import{h as u}from"./chunk-HIGE3J6C.mjs";import{createContext as L,useCallback as f,useContext as h,useEffect as l,useId as K,useState as p}from"react";import{jsx as g}from"react/jsx-runtime";var b=L({listeners:[],setListeners:()=>{}});function C({children:t}){let[s,o]=p([]);return g(b.Provider,{value:{listeners:s,setListeners:o},children:t})}function N(t,s,o={}){let i=K(),{listeners:d,setListeners:c}=h(b),a=f(e=>{let r=e.target,S=document.getElementById("modal-backdrop");if(console.log({target:r}),e.metaKey||e.ctrlKey||r.tagName==="INPUT"||r.tagName==="TEXTAREA"||!!S!=!!o.modal||(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,m)=>(m.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};
