var l=(m,p,n)=>new Promise((a,s)=>{var u=i=>{try{c(n.next(i))}catch(t){s(t)}},d=i=>{try{c(n.throw(i))}catch(t){s(t)}},c=i=>i.done?a(i.value):Promise.resolve(i.value).then(u,d);c((n=n.apply(m,p)).next())});import{u as _}from"./useEntityForm-CMwp7TbN.js";import{b6 as o}from"./bootstrap-Bqxdt4iG.js";import{u as x}from"./currencies-Bq32ahPb.js";import{u as O}from"./tms-services-5gu256h7.js";import{a1 as A,L as f,E as h,aa as F,ai as R,aj as q,a9 as E}from"../jse/index-index-BUJ_4tQs.js";const G=A({__name:"invoice-detail-item-form",props:{item:{default:null},mode:{}},emits:["cancel","submit"],setup(m,{expose:p,emit:n}){const a=m,s=n,u=O(),d=x(),c=f([]),i=h(()=>c.value.map(e=>({label:e.label,value:e.value}))),t=f([]);F(()=>l(null,null,function*(){const[e,r]=yield Promise.all([u.fetchOptions(),d.fetchOptions()]);c.value=e,t.value=r}));const w=e=>l(null,null,function*(){if(!e)return;const r=c.value.find(N=>N.value===e);r&&(yield v.setValues({description:r.description,originalAmount:r.salesPrice}),r.currencyId&&(yield v.setValues({currencyId:r.currencyId})))}),g={serviceId:"",description:"",currencyId:"",originalAmount:0,exchangeRate:1},b=h(()=>[{component:"Select",componentProps:{id:"invoice-item-form-service-select",placeholder:o("page.invoices.itemDrawer.servicePlaceholder"),options:i.value,showSearch:!0,filterOption:(e,r)=>r.label.toLowerCase().includes(e.toLowerCase()),onChange:w},fieldName:"serviceId",label:o("page.invoices.itemDrawer.service"),rules:"selectRequired"},{component:"Input",componentProps:{placeholder:o("page.invoices.itemDrawer.descriptionPlaceholder")},fieldName:"description",label:o("page.invoices.itemDrawer.description"),rules:"required"},{component:"Select",componentProps:{placeholder:o("page.invoices.itemDrawer.currencyPlaceholder"),options:t.value},fieldName:"currencyId",label:o("page.invoices.itemDrawer.currency"),rules:"selectRequired"},{component:"InputNumber",componentProps:{min:0,precision:2,class:"w-full"},fieldName:"originalAmount",label:o("page.invoices.itemDrawer.originalAmount")},{component:"InputNumber",componentProps:{min:0,precision:4,step:1e-4,class:"w-full"},fieldName:"exchangeRate",label:o("page.invoices.itemDrawer.exchangeRate")}]),{Form:y,formApi:v,focus:I,isDirty:S,resetForm:P,submitForm:C,watchEntity:D}=_({emptyValues:g,firstInputId:"invoice-item-form-service-select",schema:b,wrapperClass:"grid-cols-1"});return D(()=>a.item,()=>a.mode),p({cancel:()=>{s("cancel")},focus:I,isDirty:S,resetForm:P,submit:()=>l(null,null,function*(){const e=yield C();e&&s("submit",e)})}),(e,r)=>(q(),R(E(y)))}});export{G as _};
