import{d as w,N as C,O as S,e as b,o as k,Y as B,b as n,w as s,a as D,u as t,d9 as E,aG as r,da as I,bT as $,$ as c,cO as A,cM as L,a0 as N}from"./index.a1506152.js";import{G as V,U as P}from"./UnsavedChangesHandler.f60d6853.js";(function(){try{var a=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},d=new Error().stack;d&&(a._sentryDebugIds=a._sentryDebugIds||{},a._sentryDebugIds[d]="b733059a-2b28-4869-8e01-d607c9a13680",a._sentryDebugIdIdentifier="sentry-dbid-b733059a-2b28-4869-8e01-d607c9a13680")}catch{}})();const T={class:"popup-container"},U={style:{padding:"0px 4px"}},z=w({__name:"SaveButton",props:{model:{},neverShowPopover:{type:Boolean},disabled:{type:Boolean}},emits:["save"],setup(a,{emit:d}){var h;const l=a,m=e=>{var o;return(o=e.parentElement)!=null?o:document.body},p=new C(S.boolean(),"dontShowUnsavedChanges"),v=b((h=p.get())!=null?h:!1),_=()=>{p.set(!0),v.value=!0},i=b(!1);async function f(){i.value=!0;try{await l.model.save(),d("save")}catch(e){console.error(e),L.error({message:"Error saving"})}finally{i.value=!1}}return addEventListener("keydown",e=>{(e.metaKey||e.ctrlKey)&&e.key==="s"&&(e.preventDefault(),f())}),addEventListener("beforeunload",e=>{l.model.hasChanges()&&(e.preventDefault(),e.returnValue="")}),(e,o)=>{var g;return k(),B("div",T,[n(t(A),{placement:"left",open:e.model.hasChanges()&&!v.value&&!e.neverShowPopover,"get-popup-container":m},{content:s(()=>[D("div",U,[n(t(E),null,{default:s(()=>[r("You have unsaved changes")]),_:1}),n(t(I),{onClick:_},{default:s(()=>[r("Don't show this again")]),_:1})])]),default:s(()=>{var y;return[n(t($),{class:"save-button",loading:i.value,disabled:!((y=e.model)!=null&&y.hasChanges())||e.disabled,onClick:o[0]||(o[0]=u=>f())},{icon:s(()=>[c(e.$slots,"icon",{},()=>[n(t(V),{size:"18"})],!0)]),default:s(()=>{var u;return[(u=e.model)!=null&&u.hasChanges()?c(e.$slots,"with-changes",{key:0},()=>[r(" Save ")],!0):c(e.$slots,"without-changes",{key:1},()=>[r(" Saved ")],!0)]}),_:3},8,["loading","disabled"])]}),_:3},8,["open"]),n(P,{"has-changes":(g=e.model)==null?void 0:g.hasChanges()},null,8,["has-changes"])])}}});const O=N(z,[["__scopeId","data-v-80b2ff4e"]]);export{O as S};
//# sourceMappingURL=SaveButton.2182dde6.js.map
