import{av as D,G,u as L,at as U,F as j,j as T,v as E,e as A,f as d,ah as F,g as x,aN as J,J as K,i as O,r as u,K as v,o as f,w as s,b as _,m as X,a as o,l as e,q as b,t as g,L as H,M as P}from"./main-FAzQ_AST.js";const Q={class:"flex justify-between w-full"},R={class:"p-4 sm:p-6"},W={class:"z-0 flex justify-end p-4 border-t border-solid border--200 border-modal-bg"},ae={__name:"TaxTypeModal",setup(Y){const a=D(),p=G();L(),U();const M=j(),V=T(()=>M.selectedCompanyCurrency),{t:i,tm:Z}=E.useI18n();let c=A(!1);const I=T(()=>({currentTaxType:{name:{required:d.withMessage(i("validation.required"),x),minLength:d.withMessage(i("validation.name_min_length",{count:3}),K(3))},calculation_type:{required:d.withMessage(i("validation.required"),x)},percent:{required:d.withMessage(i("validation.required"),x),between:d.withMessage(i("validation.enter_valid_tax_rate"),J(-100,100))},fixed_amount:{required:d.withMessage(i("validation.required"),x)},description:{maxLength:d.withMessage(i("validation.description_maxlength",{count:255}),F(255))}}})),l=O(I,T(()=>a));async function q(){if(l.value.currentTaxType.$touch(),l.value.currentTaxType.$invalid)return!0;try{const r=a.isEdit?a.updateTaxType:a.addTaxType;c.value=!0;let t=await r(a.currentTaxType);c.value=!1,p.refreshData&&p.refreshData(t.data.data),y()}catch{return c.value=!1,!0}}function y(){p.closeModal(),setTimeout(()=>{a.resetCurrentTaxType(),l.value.$reset()},300)}const $=T({get:()=>a.currentTaxType.fixed_amount/100,set:r=>{a.currentTaxType.fixed_amount=Math.round(r*100)}});return(r,t)=>{const h=u("BaseIcon"),S=u("BaseInput"),m=u("BaseInputGroup"),C=u("BaseSelectInput"),B=u("BaseMoney"),k=u("BaseTextarea"),z=u("BaseInputGrid"),w=u("BaseButton"),N=u("BaseModal");return f(),v(N,{show:e(p).active&&e(p).componentName==="TaxTypeModal",onClose:y},{header:s(()=>[_("div",Q,[b(g(e(p).title)+" ",1),o(h,{name:"XMarkIcon",class:"h-6 w-6 text-gray-500 cursor-pointer",onClick:y})])]),default:s(()=>[_("form",{action:"",onSubmit:X(q,["prevent"])},[_("div",R,[o(z,{layout:"one-column"},{default:s(()=>[o(m,{label:r.$t("tax_types.name"),variant:"horizontal",error:e(l).currentTaxType.name.$error&&e(l).currentTaxType.name.$errors[0].$message,required:""},{default:s(()=>[o(S,{modelValue:e(a).currentTaxType.name,"onUpdate:modelValue":t[0]||(t[0]=n=>e(a).currentTaxType.name=n),invalid:e(l).currentTaxType.name.$error,type:"text",onInput:t[1]||(t[1]=n=>e(l).currentTaxType.name.$touch())},null,8,["modelValue","invalid"])]),_:1},8,["label","error"]),o(m,{label:r.$t("tax_types.tax_type"),variant:"horizontal",required:""},{default:s(()=>[o(C,{modelValue:e(a).currentTaxType.calculation_type,"onUpdate:modelValue":t[2]||(t[2]=n=>e(a).currentTaxType.calculation_type=n),options:[{id:"percentage",label:r.$t("tax_types.percentage")},{id:"fixed",label:r.$t("tax_types.fixed_amount")}],"allow-empty":!1,"value-prop":"id","label-prop":"label","track-by":"label",searchable:!1},null,8,["modelValue","options"])]),_:1},8,["label"]),e(a).currentTaxType.calculation_type==="percentage"?(f(),v(m,{key:0,label:r.$t("tax_types.percent"),variant:"horizontal",required:""},{default:s(()=>[o(B,{modelValue:e(a).currentTaxType.percent,"onUpdate:modelValue":t[3]||(t[3]=n=>e(a).currentTaxType.percent=n),currency:{decimal:".",thousands:",",symbol:"% ",precision:2,masked:!1}},null,8,["modelValue"])]),_:1},8,["label"])):(f(),v(m,{key:1,label:r.$t("tax_types.fixed_amount"),variant:"horizontal",required:""},{default:s(()=>[o(B,{modelValue:$.value,"onUpdate:modelValue":t[4]||(t[4]=n=>$.value=n),currency:V.value},null,8,["modelValue","currency"])]),_:1},8,["label"])),o(m,{label:r.$t("tax_types.description"),error:e(l).currentTaxType.description.$error&&e(l).currentTaxType.description.$errors[0].$message,variant:"horizontal"},{default:s(()=>[o(k,{modelValue:e(a).currentTaxType.description,"onUpdate:modelValue":t[5]||(t[5]=n=>e(a).currentTaxType.description=n),invalid:e(l).currentTaxType.description.$error,rows:"4",cols:"50",onInput:t[6]||(t[6]=n=>e(l).currentTaxType.description.$touch())},null,8,["modelValue","invalid"])]),_:1},8,["label","error"])]),_:1})]),_("div",W,[o(w,{class:"mr-3 text-sm",variant:"primary-outline",type:"button",onClick:y},{default:s(()=>[b(g(r.$t("general.cancel")),1)]),_:1}),o(w,{loading:e(c),disabled:e(c),variant:"primary",type:"submit"},{left:s(n=>[e(c)?H("",!0):(f(),v(h,{key:0,name:"ArrowDownOnSquareIcon",class:P(n.class)},null,8,["class"]))]),default:s(()=>[b(" "+g(e(a).isEdit?r.$t("general.update"):r.$t("general.save")),1)]),_:1},8,["loading","disabled"])])],32)]),_:1},8,["show"])}}};export{ae as _};
