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