var s=(h,w,n)=>new Promise((m,c)=>{var u=o=>{try{i(n.next(o))}catch(p){c(p)}},S=o=>{try{i(n.throw(o))}catch(p){c(p)}},i=o=>o.done?m(o.value):Promise.resolve(o.value).then(u,S);i((n=n.apply(h,w)).next())});import{u as ee}from"./useEntityForm-CMwp7TbN.js";import{u as ae}from"./useRoleAccess-rNIDgdat.js";import{bV as te,c9 as A,b6 as a}from"./bootstrap-Bqxdt4iG.js";import{u as oe}from"./customers-CYPE-oGV.js";import{u as se}from"./users-CtrZlEEf.js";import{Q as ne,q as re}from"./quotations-Cpe562aq.js";import{_ as le}from"./customer-create-drawer.vue_vue_type_script_setup_true_lang-BxaYQnGR.js";import{_ as me}from"./wms-user-create-drawer.vue_vue_type_script_setup_true_lang-Dyy9Rzhv.js";import{a1 as ce,L as P,aa as ue,E as q,ap as ie,aj as pe,p as y,a9 as b}from"../jse/index-index-BUJ_4tQs.js";import{u as D}from"./use-drawer-CLDmRz16.js";const l="__add_new__",Ne=ce({__name:"quotation-form",props:{quotation:{default:null},mode:{}},emits:["cancel","submit"],setup(h,{expose:w,emit:n}){var I,_,N,O,R;const m=h,c=n,u=oe(),{isWarehouseScoped:S}=ae(),i=se(),o=te(),p=(N=(_=(I=o.userInfo)==null?void 0:I.roles)==null?void 0:_[0])!=null?N:"",V=(R=(O=o.userInfo)==null?void 0:O.userId)!=null?R:"",d=p===A.SALESMAN,[E,L]=D({connectedComponent:le}),[k,T]=D({connectedComponent:me}),C=P([]),f=P([]),U={label:`+ ${a("page.quotations.form.addNewCustomer")}`,value:l},F={label:`+ ${a("page.quotations.form.addNewSalesman")}`,value:l},v=()=>s(null,null,function*(){try{C.value=yield S?u.fetchOptionsByCurrentWarehouses():u.fetchOptions()}catch(e){C.value=[]}}),g=()=>s(null,null,function*(){try{f.value=yield i.fetchSalesmanOptions()}catch(e){f.value=[]}});ue(()=>s(null,null,function*(){yield Promise.all([v(),g()]),d&&m.mode==="create"&&(yield r.setValues({salesmanId:V}))}));const W=q(()=>[U,...C.value]),$=q(()=>[F,...f.value]),x=e=>s(null,null,function*(){if(e===l){yield r.setValues({customerId:void 0}),L.open();return}if(!d&&e)try{const t=yield u.getDetail(e);t!=null&&t.salesmanId&&(yield r.setValues({salesmanId:t.salesmanId}))}catch(t){}}),B=e=>s(null,null,function*(){e===l&&(yield r.setValues({salesmanId:void 0}),T.setData({defaultRole:A.SALESMAN}).open())}),M=e=>s(null,null,function*(){yield v(),yield r.setValues({customerId:e.id})}),Q=e=>s(null,null,function*(){yield g(),yield r.setValues({salesmanId:e.id})}),j={customerId:"",salesmanId:"",status:ne.DRAFT,validity:"",paymentTerms:"",quoteRemarks:""},z=re.map(e=>({label:e.label,value:e.value})),G=q(()=>[{component:"Select",componentProps:{id:"quotation-form-customer-select",placeholder:a("page.quotations.form.customerPlaceholder"),options:W.value,showSearch:!0,onChange:x,filterOption:(e,t)=>t.value===l||t.label.toLowerCase().includes(e.toLowerCase())},fieldName:"customerId",label:a("page.quotations.form.customer"),rules:"selectRequired"},{component:"Select",componentProps:{placeholder:a("page.quotations.form.salesmanPlaceholder"),options:d?f.value:$.value,showSearch:!0,disabled:d,onChange:B,filterOption:(e,t)=>t.value===l||t.label.toLowerCase().includes(e.toLowerCase())},fieldName:"salesmanId",label:a("page.quotations.form.salesman"),rules:"selectRequired"},{component:"Select",componentProps:{placeholder:a("page.quotations.form.statusPlaceholder"),options:z},fieldName:"status",label:a("page.quotations.form.status"),rules:"selectRequired"},{component:"Input",componentProps:{placeholder:a("page.quotations.form.validityPlaceholder")},fieldName:"validity",label:a("page.quotations.form.validity")},{component:"Input",componentProps:{placeholder:a("page.quotations.form.paymentTermsPlaceholder")},fieldName:"paymentTerms",label:a("page.quotations.form.paymentTerms")},{component:"Textarea",componentProps:{placeholder:a("page.quotations.form.quoteRemarksPlaceholder"),autoSize:{minRows:2}},fieldName:"quoteRemarks",label:a("page.quotations.form.quoteRemarks")}]),{Form:H,formApi:r,focus:J,isDirty:K,resetForm:X,submitForm:Y,watchEntity:Z}=ee({emptyValues:j,firstInputId:"quotation-form-customer-select",schema:G,wrapperClass:"grid-cols-1"});return Z(()=>m.quotation,()=>m.mode),w({cancel:()=>{c("cancel")},focus:J,isDirty:K,resetForm:X,submit:()=>s(null,null,function*(){const e=yield Y();e&&c("submit",e)})}),(e,t)=>(pe(),ie("div",null,[y(b(H)),y(b(E),{onSuccess:M}),y(b(k),{onSuccess:Q})]))}});export{Ne as _};
