var u=(v,l,i)=>new Promise((r,t)=>{var s=o=>{try{a(i.next(o))}catch(f){t(f)}},m=o=>{try{a(i.throw(o))}catch(f){t(f)}},a=o=>o.done?r(o.value):Promise.resolve(o.value).then(s,m);a((i=i.apply(v,l)).next())});import{c as y}from"./useDrawerCloseConfirm-Q-yISXm7.js";import{b6 as c,c0 as _}from"./bootstrap-Bqxdt4iG.js";import{u as g}from"./data-refresh-BZ1_-6mk.js";import{u as w}from"./invoices-BFW1CUIx.js";import{_ as S}from"./invoice-detail-item-form.vue_vue_type_script_setup_true_lang-0N_0V4uI.js";import{a1 as h,L as p,ai as D,aj as x,ak as C,p as b,a9 as d}from"../jse/index-index-BUJ_4tQs.js";import{u as k}from"./use-drawer-CLDmRz16.js";const L=h({__name:"invoice-detail-item-edit-drawer",setup(v){const l=w(),i=g(),r=p(null),t=p(null),s=p(!1),[m,a]=k({title:c("page.invoices.itemDrawer.editTitle"),placement:"right",onBeforeClose(){return u(this,null,function*(){return s.value||!r.value||!t.value?!0:(yield r.value.isDirty())?y():!0})},onClosed:()=>{t.value=null,s.value=!1},onConfirm:()=>{var e;(e=r.value)==null||e.submit()},onOpenChange:e=>u(null,null,function*(){if(e){const n=a.getData();if(n!=null&&n.itemId){a.setState({loading:!0});try{t.value=yield l.getDetailById(n.itemId)}catch(I){t.value=null}finally{a.setState({loading:!1})}}}}),onOpened:()=>{var e;(e=r.value)==null||e.focus()}}),o=e=>u(null,null,function*(){if(t.value){a.lock();try{yield l.updateDetail(t.value.id,e),_.success(c("page.common.updateSuccess")),i.invalidateInvoices(),s.value=!0,a.close()}catch(n){_.error(c("page.common.updateFailed"))}finally{a.unlock()}}});return(e,n)=>(x(),D(d(m),{class:"w-[520px]","confirm-text":d(c)("page.common.save"),"cancel-text":d(c)("page.common.cancel")},{default:C(()=>[b(S,{ref_key:"formRef",ref:r,item:t.value,mode:"edit",onSubmit:o},null,8,["item"])]),_:1},8,["confirm-text","cancel-text"]))}});export{L as _};
