import{F as k,v as q,f as N,k as g,g as y,h as j,I as D,ai as G,j as L,r as i,o as B,m as b,w as r,b as m,p as v,t as C,l as e,a as n,q as T,J as z,K as E}from"./main-B9dpPbRR.js";import{u as U}from"./category-PmZRvdLB.js";const A={class:"flex justify-between w-full"},F={class:"p-8 sm:p-6"},J={class:"z-0 flex justify-end p-4 border-t border-gray-200 border-solid border-modal-bg"},O={__name:"CategoryModal",setup(K){const t=U(),u=k(),{t:p}=q.useI18n();let c=N(!1);const h=g(()=>({currentCategory:{name:{required:y.withMessage(p("validation.required"),j),minLength:y.withMessage(p("validation.name_min_length",{count:3}),D(3))},description:{maxLength:y.withMessage(p("validation.description_maxlength",{count:255}),G(255))}}})),a=L(h,g(()=>t)),I=g(()=>u.active&&u.componentName==="CategoryModal");async function w(){if(a.value.currentCategory.$touch(),a.value.currentCategory.$invalid)return!0;const s=t.isEdit?t.updateCategory:t.addCategory;c.value=!0,await s(t.currentCategory),c.value=!1,u.refreshData&&u.refreshData(),d()}function d(){u.closeModal(),setTimeout(()=>{t.$reset(),a.value.$reset()},300)}return(s,o)=>{const f=i("BaseIcon"),x=i("BaseInput"),_=i("BaseInputGroup"),M=i("BaseTextarea"),V=i("BaseInputGrid"),$=i("BaseButton"),S=i("BaseModal");return B(),b(S,{show:I.value,onClose:d},{header:r(()=>[m("div",A,[v(C(e(u).title)+" ",1),n(f,{name:"XIcon",class:"w-6 h-6 text-gray-500 cursor-pointer",onClick:d})])]),default:r(()=>[m("form",{action:"",onSubmit:T(w,["prevent"])},[m("div",F,[n(V,{layout:"one-column"},{default:r(()=>[n(_,{label:s.$t("expenses.category"),error:e(a).currentCategory.name.$error&&e(a).currentCategory.name.$errors[0].$message,required:""},{default:r(()=>[n(x,{modelValue:e(t).currentCategory.name,"onUpdate:modelValue":o[0]||(o[0]=l=>e(t).currentCategory.name=l),invalid:e(a).currentCategory.name.$error,type:"text",onInput:o[1]||(o[1]=l=>e(a).currentCategory.name.$touch())},null,8,["modelValue","invalid"])]),_:1},8,["label","error"]),n(_,{label:s.$t("expenses.description"),error:e(a).currentCategory.description.$error&&e(a).currentCategory.description.$errors[0].$message},{default:r(()=>[n(M,{modelValue:e(t).currentCategory.description,"onUpdate:modelValue":o[2]||(o[2]=l=>e(t).currentCategory.description=l),rows:"4",cols:"50",onInput:o[3]||(o[3]=l=>e(a).currentCategory.description.$touch())},null,8,["modelValue"])]),_:1},8,["label","error"])]),_:1})]),m("div",J,[n($,{type:"button",variant:"primary-outline",class:"mr-3 text-sm",onClick:d},{default:r(()=>[v(C(s.$t("general.cancel")),1)]),_:1}),n($,{loading:e(c),disabled:e(c),variant:"primary",type:"submit"},{left:r(l=>[e(c)?E("",!0):(B(),b(f,{key:0,name:"SaveIcon",class:z(l.class)},null,8,["class"]))]),default:r(()=>[v(" "+C(e(t).isEdit?s.$t("general.update"):s.$t("general.save")),1)]),_:1},8,["loading","disabled"])])],32)]),_:1},8,["show"])}}};export{O as _};
