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