var m=(p,d,s)=>new Promise((t,c)=>{var i=r=>{try{n(s.next(r))}catch(a){c(a)}},l=r=>{try{n(s.throw(r))}catch(a){c(a)}},n=r=>r.done?t(r.value):Promise.resolve(r.value).then(i,l);n((s=s.apply(p,d)).next())});import{u as V}from"./useEntityForm-CMwp7TbN.js";import{u as L}from"./useRoleAccess-rNIDgdat.js";import{b6 as o}from"./bootstrap-Bqxdt4iG.js";import{u as R}from"./customers-CYPE-oGV.js";import{g as T,a as x}from"./packing-orders-F5ifB4Cx.js";import{a as W,P as B}from"./packing-orders-B65yyscU.js";import{_ as $}from"./customer-create-drawer.vue_vue_type_script_setup_true_lang-BxaYQnGR.js";import{a1 as q,L as j,E as O,ap as z,aj as G,p as C,a9 as b,F as U}from"../jse/index-index-BUJ_4tQs.js";import{u as H}from"./use-drawer-CLDmRz16.js";const f="__add_new__",se=q({__name:"packing-order-form",props:{packingOrder:{default:null},mode:{}},emits:["cancel","submit"],setup(p,{expose:d,emit:s}){const t=p,c=s,i=R(),{isWarehouseScoped:l}=L(),[n,r]=H({connectedComponent:$}),a=j([]),w={label:`+ ${o("page.customers.form.addNewCustomer")}`,value:f},g=()=>m(null,null,function*(){try{const e=yield l?i.fetchOptionsByCurrentWarehouses():i.fetchOptions();a.value=e}catch(e){console.error("Failed to load customer options:",e),a.value=[]}}),y=O(()=>[w,...a.value]);g();const _=(e,u)=>m(null,null,function*(){e===f&&(yield k.setValues({customerId:void 0}),r.open())}),P=e=>m(null,null,function*(){yield g(),yield k.setValues({customerId:e.id})}),S={code:"",customerId:"",type:B.PARCEL,status:W.PENDING,remark:""},N=O(()=>{var e;return[{component:"Input",componentProps:{"data-testid":"packing-order-form-code-input",disabled:t.mode==="edit",placeholder:o("page.packingTask.form.codePlaceholder")},fieldName:"code",label:o("page.packingTask.table.orderNo"),visible:t.mode==="edit"||!!((e=t.packingOrder)!=null&&e.code)},{component:"Select",componentProps:{"data-testid":"packing-order-form-customer-select",id:"packing-order-form-customer-select",disabled:t.mode==="edit",options:y.value,onChange:_,placeholder:o("page.packingOrders.form.customerPlaceholder"),showSearch:!0,filterOption:(u,h)=>h.value===f||h.label.toLowerCase().includes(u.toLowerCase())},fieldName:"customerId",label:o("page.packingOrders.form.customer"),rules:"selectRequired"},{component:"Select",componentProps:{"data-testid":"packing-order-form-type-select",id:"packing-order-form-type-select",options:T(),placeholder:o("page.packingOrders.form.typePlaceholder")},fieldName:"type",label:o("page.packingOrders.form.type"),rules:"selectRequired"},{component:"Select",componentProps:{"data-testid":"packing-order-form-status-select",options:x(),placeholder:o("page.packingOrders.form.statusPlaceholder")},fieldName:"status",formItemClass:"hidden",label:o("page.packingOrders.form.status")},{component:"Textarea",componentProps:{"data-testid":"packing-order-form-remark-input",placeholder:o("page.packingOrders.form.remarkPlaceholder"),autoSize:{minRows:2}},fieldName:"remark",label:o("page.packingOrders.form.remark")}]}),{Form:v,formApi:k,focus:I,isDirty:E,resetForm:A,submitForm:D,watchEntity:F}=V({emptyValues:S,firstInputId:"packing-order-form-customer-select",schema:N,wrapperClass:"grid-cols-1"});return F(()=>t.packingOrder,()=>t.mode),d({cancel:()=>{c("cancel")},focus:I,isDirty:E,resetForm:A,submit:()=>m(null,null,function*(){const e=yield D();e&&c("submit",e)})}),(e,u)=>(G(),z(U,null,[C(b(v)),C(b(n),{onSuccess:P})],64))}});export{se as _};
