import{r as l,fE as f,j as u,K as d}from"./index-60a3c753.js";import{D as v}from"./DialogContent-89e21f2e.js";import{D as g}from"./DialogTitle-fe69da5c.js";import{D as h}from"./DialogActions-e754942c.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};
