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