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