var l=(d,p,r)=>new Promise((o,i)=>{var m=t=>{try{s(r.next(t))}catch(n){i(n)}},u=t=>{try{s(r.throw(t))}catch(n){i(n)}},s=t=>t.done?o(t.value):Promise.resolve(t.value).then(m,u);s((r=r.apply(d,p)).next())});import{u as M}from"./useEntityForm-CMwp7TbN.js";import{b6 as a}from"./bootstrap-Bqxdt4iG.js";import{u as k}from"./costing-sheets-CTsGgj5D.js";import{a as y,b as I}from"./storage-leases-DIh1SO1g.js";import{a1 as A,L as F,aa as _,E as v,ai as x,aj as O,a9 as E}from"../jse/index-index-BUJ_4tQs.js";const G=A({__name:"storage-lease-period-form",props:{period:{default:null},mode:{},defaultAction:{default:""}},emits:["cancel","submit"],setup(d,{expose:p,emit:r}){const o=d,i=r,m=k(),u=y.map(e=>({label:e.label,value:e.value})),s=F([]);_(()=>l(null,null,function*(){try{s.value=yield m.fetchOptions()}catch(e){s.value=[]}}));const t={action:I.NEW,startDate:"",endDate:"",duration:0,insured:!1,sumInsured:0,costingSheetId:null,remarks:""},n=()=>l(null,null,function*(){const e=yield f.getValues(),c=e==null?void 0:e.startDate,g=e==null?void 0:e.endDate;if(c&&g){const C=new Date(c),P=new Date(g).getTime()-C.getTime(),N=Math.ceil(P/(1e3*60*60*24));yield f.setValues({duration:Math.max(N,0)})}}),h=v(()=>[{component:"Select",componentProps:{placeholder:a("page.storageLeases.periodDrawer.costingSheetPlaceholder"),options:s.value,allowClear:!0,showSearch:!0,filterOption:(e,c)=>c.label.toLowerCase().includes(e.toLowerCase())},fieldName:"costingSheetId",label:a("page.storageLeases.periodDrawer.costingSheet")},{component:"Select",componentProps:{id:"period-form-action-select",placeholder:a("page.storageLeases.periodDrawer.actionPlaceholder"),options:u},fieldName:"action",label:a("page.storageLeases.periodDrawer.action"),rules:"selectRequired"},{component:"DatePicker",componentProps:{class:"w-full",format:"DD/MM/YYYY",valueFormat:"YYYY-MM-DD",onChange:n},fieldName:"startDate",label:a("page.storageLeases.periodDrawer.startDate"),rules:"required"},{component:"DatePicker",componentProps:{class:"w-full",format:"DD/MM/YYYY",valueFormat:"YYYY-MM-DD",onChange:n},fieldName:"endDate",label:a("page.storageLeases.periodDrawer.endDate"),rules:"required"},{component:"InputNumber",componentProps:{class:"w-full",min:0,disabled:!0,addonAfter:"Days"},fieldName:"duration",label:a("page.storageLeases.periodDrawer.duration")},{component:"Switch",componentProps:{checkedChildren:"Yes",unCheckedChildren:"No",class:"w-auto"},fieldName:"insured",label:a("page.storageLeases.periodDrawer.insured")},{component:"InputNumber",componentProps:{class:"w-full",min:0,precision:2,placeholder:a("page.storageLeases.periodDrawer.sumInsuredPlaceholder")},dependencies:{show:e=>!!e.insured,triggerFields:["insured"]},fieldName:"sumInsured",label:a("page.storageLeases.periodDrawer.sumInsured")},{component:"Textarea",componentProps:{placeholder:a("page.storageLeases.periodDrawer.remarksPlaceholder"),autoSize:{minRows:2}},fieldName:"remarks",label:a("page.storageLeases.periodDrawer.remarks")}]),{Form:D,formApi:f,focus:w,isDirty:b,resetForm:S,submitForm:L,watchEntity:Y}=M({emptyValues:t,firstInputId:"period-form-action-select",schema:h,wrapperClass:"grid-cols-1"});return Y(()=>o.period,()=>o.mode),o.defaultAction&&o.mode==="create"&&f.setValues({action:o.defaultAction}),p({cancel:()=>{i("cancel")},focus:w,isDirty:b,resetForm:S,submit:()=>l(null,null,function*(){const e=yield L();e&&i("submit",e)})}),(e,c)=>(O(),x(E(D)))}});export{G as _};
