import{r as l,fE as f,j as u,K as d}from"./index-43bf7a1c.js";import{D as v}from"./DialogContent-d5902709.js";import{D as g}from"./DialogTitle-20dc6f66.js";import{D as h}from"./DialogActions-d63c6496.js";function p(s,t=!0){const e=l.useContext(f).navigator;l.useEffect(()=>{if(!t)return;const a=e.push,r=e.replace,o=e.go;return e.push=(...n)=>{s({retry:()=>{e.push=a,a(...n)}})},e.replace=(...n)=>{s({retry:()=>{e.replace=r,r(...n)}})},e.go=(...n)=>{s({retry:()=>{e.go=o,o(...n)}})},()=>{e.push=a,e.replace=r,e.go=o}},[e,s,t]),l.useEffect(()=>{if(!t)return;const a=r=>{r.preventDefault(),r.returnValue=""};return window.addEventListener("beforeunload",a),()=>window.removeEventListener("beforeunload",a)},[t])}const j=({watchValues:s,isApiCalling:t=!1})=>{const[e,a]=l.useState(!1),[r,o]=l.useState(!1),[n,c]=l.useState(null);return l.useEffect(()=>{s&&a(!0)},[s]),p(({retry:i})=>{t?i():(c({retry:i}),o(!0))},e&&!t),{openDialog:r,hasUnsavedChanges:e,resetUnsavedChanges:()=>{a(!1)},handleStay:()=>{o(!1)},handleLeave:()=>{o(!1),n==null||n.retry()}}},L=({open:s,onStay:t,onLeave:e})=>u.jsxs(v,{open:s,onClose:t,children:[u.jsx(g,{children:"⚠️ You have unsaved changes. Do you really want to leave?"}),u.jsxs(h,{children:[u.jsx(d,{onClick:t,variant:"outlined",children:"Stay"}),u.jsx(d,{color:"error",variant:"contained",onClick:e,children:"Leave"})]})]});export{L as U,j as u};
