var n=(C,p,a)=>new Promise((d,s)=>{var u=o=>{try{t(a.next(o))}catch(l){s(l)}},f=o=>{try{t(a.throw(o))}catch(l){s(l)}},t=o=>o.done?d(o.value):Promise.resolve(o.value).then(u,f);t((a=a.apply(C,p)).next())});import{b6 as r,ct as E,c0 as v}from"./bootstrap-Bqxdt4iG.js";import{u as A}from"./customers-CYPE-oGV.js";import{u as R}from"./data-refresh-BZ1_-6mk.js";import{u as F}from"./tms-orders-Bsi6LVLz.js";import{_ as I}from"./customer-create-drawer.vue_vue_type_script_setup_true_lang-BxaYQnGR.js";import{O as h,o as L}from"./tms-orders-DrMtRe-L.js";import{a1 as T,L as N,E as S,ai as W,aj as $,ak as B,p as b,a9 as i}from"../jse/index-index-BUJ_4tQs.js";import{u as O}from"./use-drawer-CLDmRz16.js";import"./useCreateDrawer-JEzOVO6Z.js";import"./useDrawerCloseConfirm-Q-yISXm7.js";import"./index-nmF6dqm7.js";import"./customer-form.vue_vue_type_script_setup_true_lang-DG8_fA0v.js";import"./useEntityForm-CMwp7TbN.js";import"./useRoleAccess-rNIDgdat.js";import"./users-CtrZlEEf.js";import"./warehouses-BnkLPhlE.js";import"./wms-user-create-drawer.vue_vue_type_script_setup_true_lang-Dyy9Rzhv.js";import"./wms-user-form.vue_vue_type_script_setup_true_lang-BaO4QUb_.js";import"./index-BfzlM1cI.js";import"./FormItemContext-DjC4AFm9.js";import"./statusUtils-BYtfCLmZ.js";import"./BaseInput-hWv8kcd0.js";import"./css-BPcmMxJM.js";import"./index-BgJpmtO-.js";import"./SearchOutlined-D1HVVwei.js";import"./isPlainObject-DJcwgk9A.js";import"./index-BNdxtbnh.js";import"./ResizeObserver.es-CDE7jhPe.js";import"./EyeOutlined-CSPqLYav.js";import"./index-DL4Zx5Zk.js";import"./x-CmzO4AZ3.js";import"./Separator.vue_vue_type_script_setup_true_lang-V0MBJaAb.js";const g="__add_new__",ve=T({__name:"order-create-drawer copy",setup(C){const p=F(),a=A(),d=R(),s=N(!1),[u,f]=O({connectedComponent:I}),t=N([]),o={label:`+ ${r("page.tms.orders.form.addNewCustomer")}`,value:g},l=S(()=>[o,...t.value]),_=()=>n(null,null,function*(){try{const e=yield a.fetchOptions();t.value=e}catch(e){console.error("Failed to load customer options:",e),t.value=[]}});_();const k=(e,c)=>n(null,null,function*(){e===g&&(yield m.setValues({customerId:void 0}),f.open())}),x=e=>n(null,null,function*(){yield _(),yield m.setValues({customerId:e.id})}),y=S(()=>[{component:"Select",componentProps:{"data-testid":"order-form-customer-select",options:l.value,onChange:k,placeholder:r("page.tms.orders.form.customerPlaceholder"),showSearch:!0,filterOption:(e,c)=>c.value===g||c.label.toLowerCase().includes(e.toLowerCase())},fieldName:"customerId",label:r("page.tms.orders.form.customer"),rules:"selectRequired"},{component:"Input",componentProps:{"data-testid":"order-form-ref-input",placeholder:r("page.tms.orders.form.customerRefPlaceholder"),maxlength:100},fieldName:"customerRefNo",label:r("page.tms.orders.form.customerRef")},{component:"Select",componentProps:{"data-testid":"order-form-status-select",options:L,placeholder:r("page.tms.orders.form.statusPlaceholder"),defaultValue:h.NEW},fieldName:"status",label:r("page.tms.orders.form.status"),defaultValue:h.NEW},{component:"Textarea",componentProps:{"data-testid":"order-form-remarks-input",placeholder:r("page.tms.orders.form.remarksPlaceholder"),rows:3},fieldName:"remarks",label:r("page.tms.orders.form.remarks")}]),[V,m]=E({commonConfig:{componentProps:{class:"w-full"}},layout:"vertical",schema:y.value,scrollToFirstError:!0,showDefaultActions:!1,wrapperClass:"grid-cols-1"}),[P,w]=O({title:r("page.tms.orders.drawer.createTitle"),onOpenChange:e=>n(null,null,function*(){e&&(yield m.resetForm(),yield m.setValues({customerId:"",customerRefNo:"",status:h.NEW,remarks:""}))}),onConfirm:()=>n(null,null,function*(){const{valid:e}=yield m.validate();if(!e)return;const c=yield m.getValues();s.value=!0,w.lock();try{yield p.create(c),d.invalidateTmsOrders(),v.success(r("page.tms.orders.message.createSuccess")),w.close()}catch(D){console.error("Failed to create order:",D),v.error(r("page.tms.orders.message.createError"))}finally{s.value=!1,w.unlock()}})});return(e,c)=>($(),W(i(P),{class:"w-[520px]","confirm-text":i(r)("page.table.button.create"),"cancel-text":i(r)("page.table.button.cancel"),loading:s.value},{default:B(()=>[b(i(V)),b(i(u),{onSuccess:x})]),_:1},8,["confirm-text","cancel-text","loading"]))}});export{ve as default};
