var f=(t,p,l)=>new Promise((i,c)=>{var d=s=>{try{n(l.next(s))}catch(r){c(r)}},m=s=>{try{n(l.throw(s))}catch(r){c(r)}},n=s=>s.done?i(s.value):Promise.resolve(s.value).then(d,m);n((l=l.apply(t,p)).next())});import{b6 as o,cI as E}from"./bootstrap-Bqxdt4iG.js";import{u as F}from"./useEntityForm-CMwp7TbN.js";import{u as _}from"./costing-sheets-CTsGgj5D.js";import{u as T}from"./customers-CYPE-oGV.js";import{u as A}from"./users-CtrZlEEf.js";import{a1 as q,L as h,aa as x,E as V,ai as j,aj as B,a9 as U}from"../jse/index-index-BUJ_4tQs.js";var w=(t=>(t.CANCELLED="cancelled",t.DRAFT="draft",t.OVERDUE="overdue",t.PAID="paid",t.SENT="sent",t.VOID="void",t))(w||{});const W=[{label:"Draft",value:"draft",color:"default"},{label:"Sent",value:"sent",color:"processing"},{label:"Paid",value:"paid",color:"success"},{label:"Overdue",value:"overdue",color:"error"},{label:"Cancelled",value:"cancelled",color:"default"},{label:"Void",value:"void",color:"default"}],ee=q({__name:"invoice-form",props:{invoice:{default:null},mode:{}},emits:["cancel","submit"],setup(t,{expose:p,emit:l}){var b;const i=t,c=l,{isWarehouseScoped:d}=useRoleAccess(),m=T(),n=A(),s=_(),r=h([]),v=h([]),D=h([]);x(()=>f(null,null,function*(){const[e,a,u]=yield Promise.all([d?m.fetchOptionsByCurrentWarehouses():m.fetchOptions(),n.fetchSalesmanOptions(),s.fetchOptions()]);r.value=e,v.value=a,D.value=u}));const C={costingSheetId:"",customerId:"",salesmanId:"",date:(b=new Date().toISOString().split("T")[0])!=null?b:"",dueDate:"",status:w.DRAFT,remarks:"",autocountInvoiceRefNo:""},O=W.map(e=>({label:e.label,value:e.value})),y=V(()=>[{component:"Select",componentProps:{placeholder:o("page.invoices.form.costingSheetPlaceholder"),options:D.value,allowClear:!0,showSearch:!0,filterOption:(e,a)=>a.label.toLowerCase().includes(e.toLowerCase())},fieldName:"costingSheetId",label:o("page.invoices.form.costingSheet")},{component:"Select",componentProps:{id:"invoice-form-customer-select",placeholder:o("page.invoices.form.customerPlaceholder"),options:r.value,showSearch:!0,filterOption:(e,a)=>a.label.toLowerCase().includes(e.toLowerCase())},fieldName:"customerId",label:o("page.invoices.form.customer"),rules:"selectRequired"},{component:"Select",componentProps:{placeholder:o("page.invoices.form.salesmanPlaceholder"),options:v.value,showSearch:!0,filterOption:(e,a)=>a.label.toLowerCase().includes(e.toLowerCase())},fieldName:"salesmanId",label:o("page.invoices.form.salesman"),rules:"selectRequired"},{component:"DatePicker",componentProps:{placeholder:o("page.invoices.form.datePlaceholder"),style:{width:"100%"},format:"DD/MM/YYYY",valueFormat:"YYYY-MM-DD"},fieldName:"date",label:o("page.invoices.form.date"),rules:E().refine(e=>!!e,{message:"Date is required"})},{component:"DatePicker",componentProps:{placeholder:o("page.invoices.form.dueDatePlaceholder"),style:{width:"100%"},format:"DD/MM/YYYY",valueFormat:"YYYY-MM-DD"},fieldName:"dueDate",label:o("page.invoices.form.dueDate")},{component:"Select",componentProps:{placeholder:o("page.invoices.form.statusPlaceholder"),options:O},fieldName:"status",label:o("page.invoices.form.status"),rules:"selectRequired"},{component:"Input",componentProps:{placeholder:o("page.invoices.form.autocountRefPlaceholder")},fieldName:"autocountInvoiceRefNo",label:o("page.invoices.form.autocountRef")},{component:"Textarea",componentProps:{placeholder:o("page.invoices.form.remarksPlaceholder"),autoSize:{minRows:2}},fieldName:"remarks",label:o("page.invoices.form.remarks")}]),{Form:M,focus:N,isDirty:R,resetForm:I,submitForm:L,watchEntity:k}=F({emptyValues:C,firstInputId:"invoice-form-customer-select",schema:y,wrapperClass:"grid-cols-1"});return k(()=>i.invoice,()=>i.mode),p({cancel:()=>{c("cancel")},focus:N,isDirty:R,resetForm:I,submit:()=>f(null,null,function*(){var a,u,g,S,Y,P;const e=yield L();e&&(e.date&&typeof e.date=="object"&&(e.date=(g=(u=(a=e.date).format)==null?void 0:u.call(a,"YYYY-MM-DD"))!=null?g:""),e.dueDate&&typeof e.dueDate=="object"&&(e.dueDate=(P=(Y=(S=e.dueDate).format)==null?void 0:Y.call(S,"YYYY-MM-DD"))!=null?P:""),e.dueDate||(e.dueDate=null),c("submit",e))})}),(e,a)=>(B(),j(U(M)))}});export{ee as _,W as i};
