var l=(f,v,c)=>new Promise((r,u)=>{var h=o=>{try{m(c.next(o))}catch(p){u(p)}},w=o=>{try{m(c.throw(o))}catch(p){u(p)}},m=o=>o.done?r(o.value):Promise.resolve(o.value).then(h,w);m((c=c.apply(f,v)).next())});import{u as B}from"./useEntityForm-CMwp7TbN.js";import{b6 as t}from"./bootstrap-Bqxdt4iG.js";import{u as E}from"./currencies-Bq32ahPb.js";import{u as T}from"./quotations-CYticOiT.js";import{u as z}from"./tms-services-5gu256h7.js";import{f as j}from"./format-DSCuLcwt.js";import{a1 as M,L as b,E as P,aa as U,U as W,ap as $,aj as I,p as G,ai as H,an as J,a9 as i,ak as N,az as d,ax as D,ay as n}from"../jse/index-index-BUJ_4tQs.js";import{A as K}from"./index-Qe1tyv43.js";const ce=M({__name:"quotation-detail-item-form",props:{item:{default:null},mode:{},quotationId:{default:""},customerId:{default:""}},emits:["cancel","submit"],setup(f,{expose:v,emit:c}){const r=f,u=c,h=T(),w=z(),m=E(),o=b([]),p=P(()=>o.value.map(e=>({label:e.label,value:e.value}))),q=b([]),S=P(()=>q.value.map(e=>({label:e.label,value:e.value})));U(()=>l(null,null,function*(){const[e,a]=yield Promise.all([w.fetchOptions(),m.fetchOptionsWithRate()]);o.value=e,q.value=a}));const x=e=>l(null,null,function*(){if(!e)return;const a=o.value.find(y=>y.value===e);a&&(yield g.setValues({description:a.description,salesPrice:a.salesPrice,sst:a.sst}),a.currencyId&&(yield g.setValues({currencyId:a.currencyId})))}),C=e=>l(null,null,function*(){if(!e)return;const a=q.value.find(y=>y.value===e);a&&(yield g.setValues({exchangeRate:a.exchangeRate}))}),s=b(null),R=e=>l(null,null,function*(){if(!r.customerId||!e){s.value=null;return}try{s.value=yield h.getLastQuotedPrice(r.customerId,e,r.quotationId||void 0)}catch(a){s.value=null}}),V={serviceId:"",currencyId:"",description:"",salesPrice:0,exchangeRate:1,sst:0,qty:1,notes:""},_=P(()=>[{component:"Select",componentProps:{id:"quotation-item-form-service-select",placeholder:t("page.quotations.itemDrawer.servicePlaceholder"),options:p.value,showSearch:!0,filterOption:(e,a)=>a.label.toLowerCase().includes(e.toLowerCase()),onChange:x},fieldName:"serviceId",label:t("page.quotations.itemDrawer.service"),rules:"selectRequired"},{component:"Textarea",componentProps:{placeholder:t("page.quotations.itemDrawer.descriptionPlaceholder"),autoSize:{minRows:2}},fieldName:"description",label:t("page.quotations.itemDrawer.description"),rules:"required"},{component:"InputNumber",componentProps:{min:1,class:"w-full"},fieldName:"qty",label:t("page.quotations.itemDrawer.quantity"),rules:"required"},{component:"Select",componentProps:{placeholder:t("page.quotations.itemDrawer.currencyPlaceholder"),options:S.value,onChange:C},fieldName:"currencyId",label:t("page.quotations.itemDrawer.currency"),rules:"selectRequired"},{component:"InputNumber",componentProps:{min:0,precision:4,step:.01,class:"w-full"},fieldName:"exchangeRate",label:t("page.quotations.itemDrawer.exchangeRate")},{component:"InputNumber",componentProps:{min:0,max:100,precision:2,class:"w-full",addonAfter:"%"},fieldName:"sst",label:t("page.quotations.itemDrawer.sst")},{component:"InputNumber",componentProps:{min:0,precision:2,class:"w-full"},fieldName:"salesPrice",label:t("page.quotations.itemDrawer.unitPrice"),rules:"required"},{component:"Textarea",componentProps:{placeholder:t("page.quotations.itemDrawer.notesPlaceholder"),autoSize:{minRows:2}},fieldName:"notes",label:t("page.quotations.itemDrawer.notes")}]),{Form:F,formApi:g,focus:O,isDirty:L,resetForm:k,submitForm:Q,watchEntity:A}=B({emptyValues:V,firstInputId:"quotation-item-form-service-select",schema:_,wrapperClass:"grid-cols-1"});return A(()=>r.item,()=>r.mode),W(()=>r.item,()=>{var e;(e=r.item)!=null&&e.serviceId&&R(r.item.serviceId)},{immediate:!0}),v({cancel:()=>{u("cancel")},focus:O,isDirty:L,resetForm:k,submit:()=>l(null,null,function*(){const e=yield Q();e&&u("submit",e)})}),(e,a)=>(I(),$("div",null,[G(i(F)),s.value?(I(),H(i(K),{key:0,type:"info","show-icon":"",class:"mt-2"},{message:N(()=>[D(n(i(t)("page.quotations.itemDrawer.lastQuotedPrice")),1)]),description:N(()=>[d("div",null,[D(n(i(t)("page.quotations.itemDrawer.price"))+": ",1),d("strong",null,n(s.value.currencyCode)+" "+n(s.value.salesPrice.toFixed(2)),1)]),d("div",null,[D(n(i(t)("page.quotations.itemDrawer.quotationRef"))+": ",1),d("strong",null,n(s.value.quotationNo),1)]),d("div",null,n(i(t)("page.quotations.itemDrawer.dateLabel"))+": "+n(i(j)(s.value.date)),1)]),_:1})):J("",!0)]))}});export{ce as _};
