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-CP2fAiZX.js";import{t as v}from"./button-BmOH9agK.js";import{r as k}from"./input-BPldEXfy.js";import{a as m,c as p,i,l as u,n as g,r as x,s as a,t as c}from"./alert-dialog-DsNfSYaw.js";import{t as O}from"./dialog-BXzvlof-.js";var b=C(),d=h(f(),1),e=h(M(),1),j=d.createContext({modal:null,setModal:()=>{}});const y=t=>{let r=(0,b.c)(6),[s,o]=d.useState(null),l;r[0]===s?l=r[1]:(l={modal:s,setModal:o},r[0]=s,r[1]=l);let n;return r[2]!==s||r[3]!==t.children||r[4]!==l?(n=(0,e.jsxs)(j,{value:l,children:[s,t.children]}),r[2]=s,r[3]=t.children,r[4]=l,r[5]=n):n=r[5],n};function w(){let t=d.use(j);if(t===void 0)throw Error("useModal must be used within a ModalProvider");let r=()=>{t.setModal(null)};return{openModal:s=>{t.setModal((0,e.jsx)(O,{open:!0,onOpenChange:o=>{o||r()},children:s}))},openAlert:s=>{t.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)(g,{autoFocus:!0,onClick:r,children:"Ok"})})]})}))},openPrompt:s=>{t.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)(k,{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)(v,{type:"submit",children:s.confirmText??"Ok"})]})]})})}))},openConfirm:s=>{t.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};
