var p=(l,m,o)=>new Promise((f,s)=>{var n=e=>{try{u(o.next(e))}catch(a){s(a)}},c=e=>{try{u(o.throw(e))}catch(a){s(a)}},u=e=>e.done?f(e.value):Promise.resolve(e.value).then(n,c);u((o=o.apply(l,m)).next())});import{c0 as d,b6 as v}from"./bootstrap-Bqxdt4iG.js";import{c as g}from"./useDrawerCloseConfirm-Q-yISXm7.js";import{u as S}from"./use-drawer-CLDmRz16.js";import{L as D}from"../jse/index-index-BUJ_4tQs.js";function x(l){const{createApi:m,invalidateData:o,title:f,processOpenData:s,onClosed:n,onSuccess:c,placement:u="left"}=l,e=D(null),a=D(!1),[w,i]=S({onBeforeClose(){return p(this,null,function*(){return a.value||!e.value?!0:(yield e.value.isDirty())?g():!0})},onClosed:()=>{var r;(r=e.value)==null||r.resetForm(),a.value=!1,n==null||n()},onConfirm:()=>{var r;(r=e.value)==null||r.submit()},onOpenChange:r=>{if(r&&s){const t=i.getData();s(t)}},onOpened:()=>{var r;(r=e.value)==null||r.focus()},placement:u,title:f});return{Drawer:w,drawerApi:i,formRef:e,handleSubmit:r=>p(null,null,function*(){i.lock();try{const t=yield m(r);d.success(v("page.common.createSuccess")),o(),c==null||c(t),a.value=!0,i.close()}catch(t){const y=(t==null?void 0:t.message)||v("page.common.createFailed");d.error(y),console.error("Failed to create:",t)}finally{i.unlock()}})}}export{x as u};
