import{$ as e,C as t,G as n,S as r,Wt as i,_ as a,dt as o,g as s,h as c,u as l,v as u,vt as d,z as f,zt as p}from"./vue.runtime.esm-bundler-DAWRyTnP.js";import{n as m}from"./vue-i18n-C4HYJWrq.js";import{t as h}from"./item-CFB9f8hE.js";import{J as g,W as _,Z as v,jn as y,tt as b}from"./main-Gn9UsJwa.js";var x={class:`flex justify-between w-full`},S={class:`p-8 sm:p-6`},C={class:`z-0 flex justify-end p-4 border-t border-gray-200 border-solid`},w={__name:`ItemUnitModal`,setup(w){let T=h(),E=b(),{t:D}=m(),O=o(!1),k=y(c(()=>({name:{required:_.withMessage(D(`validation.required`),v),minLength:_.withMessage(D(`validation.name_min_length`,{count:2}),g(2))}})),c(()=>T.currentItemUnit));async function A(){if(k.value.$touch(),k.value.$invalid)return!0;try{let e=T.isItemUnitEdit?T.updateItemUnit:T.addItemUnit;O.value=!0,await e(T.currentItemUnit),E.refreshData&&E.refreshData(),j(),O.value=!1}catch{return O.value=!1,!0}}function j(){E.closeModal(),setTimeout(()=>{T.currentItemUnit={id:null,name:``},E.$reset(),k.value.$reset()},300)}return(o,c)=>{let m=n(`BaseIcon`),h=n(`BaseInput`),g=n(`BaseInputGroup`),_=n(`BaseButton`),v=n(`BaseModal`);return f(),a(v,{show:d(E).active&&d(E).componentName===`ItemUnitModal`,onClose:j},{header:e(()=>[s(`div`,x,[r(i(d(E).title)+` `,1),t(m,{name:`XMarkIcon`,class:`w-6 h-6 text-gray-500 cursor-pointer`,onClick:j})])]),default:e(()=>[s(`form`,{action:``,onSubmit:l(A,[`prevent`])},[s(`div`,S,[t(g,{label:o.$t(`settings.customization.items.unit_name`),error:d(k).name.$error&&d(k).name.$errors[0].$message,variant:`horizontal`,required:``},{default:e(()=>[t(h,{modelValue:d(T).currentItemUnit.name,"onUpdate:modelValue":c[0]||=e=>d(T).currentItemUnit.name=e,invalid:d(k).name.$error,type:`text`,onInput:c[1]||=e=>d(k).name.$touch()},null,8,[`modelValue`,`invalid`])]),_:1},8,[`label`,`error`])]),s(`div`,C,[t(_,{type:`button`,variant:`primary-outline`,class:`mr-3 text-sm`,onClick:j},{default:e(()=>[r(i(o.$t(`general.cancel`)),1)]),_:1}),t(_,{loading:d(O),disabled:d(O),variant:`primary`,type:`submit`},{left:e(e=>[d(O)?u(``,!0):(f(),a(m,{key:0,name:`ArrowDownOnSquareIcon`,class:p(e.class)},null,8,[`class`]))]),default:e(()=>[r(` `+i(d(T).isItemUnitEdit?o.$t(`general.update`):o.$t(`general.save`)),1)]),_:1},8,[`loading`,`disabled`])])],32)]),_:1},8,[`show`])}}};export{w as t};