import{au as S,G as V,v as C,e as k,j as g,f as h,J as q,g as x,i as N,r as i,K as b,o as B,w as r,b as d,m as j,a as l,l as e,q as p,t as v,L as z,M as D}from"./main-FAzQ_AST.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"},J={__name:"ItemUnitModal",setup(T){const t=S(),a=V(),{t:f}=C.useI18n();let s=k(!1);const $=g(()=>({name:{required:h.withMessage(f("validation.required"),x),minLength:h.withMessage(f("validation.name_min_length",{count:2}),q(2))}})),n=N($,g(()=>t.currentItemUnit));async function U(){if(n.value.$touch(),n.value.$invalid)return!0;try{const o=t.isItemUnitEdit?t.updateItemUnit:t.addItemUnit;s.value=!0,await o(t.currentItemUnit),a.refreshData&&a.refreshData(),u(),s.value=!1}catch{return s.value=!1,!0}}function u(){a.closeModal(),setTimeout(()=>{t.currentItemUnit={id:null,name:""},a.$reset(),n.value.$reset()},300)}return(o,m)=>{const I=i("BaseIcon"),w=i("BaseInput"),y=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:"XMarkIcon",class:"w-6 h-6 text-gray-500 cursor-pointer",onClick:u})])]),default:r(()=>[d("form",{action:"",onSubmit:j(U,["prevent"])},[d("div",G,[l(y,{label:o.$t("settings.customization.items.unit_name"),error:e(n).name.$error&&e(n).name.$errors[0].$message,variant:"horizontal",required:""},{default:r(()=>[l(w,{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(o.$t("general.cancel")),1)]),_:1}),l(_,{loading:e(s),disabled:e(s),variant:"primary",type:"submit"},{left:r(c=>[e(s)?z("",!0):(B(),b(I,{key:0,name:"ArrowDownOnSquareIcon",class:D(c.class)},null,8,["class"]))]),default:r(()=>[p(" "+v(e(t).isItemUnitEdit?o.$t("general.update"):o.$t("general.save")),1)]),_:1},8,["loading","disabled"])])],32)]),_:1},8,["show"])}}};export{J as _};
