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