import{s as h}from"./chunk-LvLJmgfZ.js";import{t as f}from"./react-Bj1aDYRI.js";import{t as C}from"./compiler-runtime-B3qBwwSJ.js";import{t as M}from"./jsx-runtime-Blw4afVn.js";import{a as m,c as p,i,l as u,n as v,r as x,s as a,t as c}from"./alert-dialog-Bb8Lz8ko.js";import{t as k}from"./button-DDGiD1NW.js";import{r as g}from"./input-JxFwu-3G.js";import{t as O}from"./dialog-BCVepWLJ.js";var b=C(),d=h(f(),1),e=h(M(),1),j=d.createContext({modal:null,setModal:()=>{}});const y=l=>{let r=(0,b.c)(6),[s,o]=d.useState(null),t;r[0]===s?t=r[1]:(t={modal:s,setModal:o},r[0]=s,r[1]=t);let n;return r[2]!==s||r[3]!==l.children||r[4]!==t?(n=(0,e.jsxs)(j,{value:t,children:[s,l.children]}),r[2]=s,r[3]=l.children,r[4]=t,r[5]=n):n=r[5],n};function w(){let l=d.use(j);if(l===void 0)throw Error("useModal must be used within a ModalProvider");let r=()=>{l.setModal(null)};return{openModal:s=>{l.setModal((0,e.jsx)(O,{open:!0,onOpenChange:o=>{o||r()},children:s}))},openAlert:s=>{l.setModal((0,e.jsx)(c,{open:!0,onOpenChange:o=>{o||r()},children:(0,e.jsxs)(i,{children:[s,(0,e.jsx)(a,{children:(0,e.jsx)(v,{autoFocus:!0,onClick:r,children:"Ok"})})]})}))},openPrompt:s=>{l.setModal((0,e.jsx)(c,{open:!0,onOpenChange:o=>{o||r()},children:(0,e.jsx)(i,{children:(0,e.jsxs)("form",{onSubmit:o=>{o.preventDefault(),s.onConfirm(o.currentTarget.prompt.value),r()},children:[(0,e.jsxs)(p,{children:[(0,e.jsx)(u,{children:s.title}),(0,e.jsx)(m,{children:s.description}),(0,e.jsx)(g,{spellCheck:s.spellCheck,defaultValue:s.defaultValue,className:"my-4 h-8",name:"prompt",required:!0,autoFocus:!0,autoComplete:"off"})]}),(0,e.jsxs)(a,{children:[(0,e.jsx)(x,{onClick:r,children:"Cancel"}),(0,e.jsx)(k,{type:"submit",children:s.confirmText??"Ok"})]})]})})}))},openConfirm:s=>{l.setModal((0,e.jsx)(c,{open:!0,onOpenChange:o=>{o||r()},children:(0,e.jsxs)(i,{children:[(0,e.jsxs)(p,{children:[(0,e.jsx)(u,{className:s.variant==="destructive"?"text-destructive":"",children:s.title}),(0,e.jsx)(m,{children:s.description})]}),(0,e.jsxs)(a,{children:[(0,e.jsx)(x,{onClick:r,children:"Cancel"}),s.confirmAction]})]})}))},closeModal:r}}export{w as n,y as t};
