import{_ as g}from"./BaseForm.vue_vue_type_script_setup_true_lang-BnxGTisD.js";import{T as _,U as D,H as B,d as I,I as M,r as k,W as N,f as R,h as j,v as e,i as r,c as s,x as U,V as z,y as H}from"./index-C5GbdPxY.js";import{u as W}from"./form-B2je8iBR.js";import{a as y,V as C}from"./VAvatar-RkAR0u0e.js";import{c as q,V as A,a as E}from"./VCard-DptrO3GI.js";import{V as F}from"./VTextField-DxEUpn3-.js";import{V as G}from"./VSelect-vtfYszIh.js";function J(l,a=!1){return _.get(`/v1/units/${l}`,{params:{return_all_translations:a}})}function K(l,a){return _.put(`/v1/units/${l}`,a)}function O(l){return _.post("/v1/units",l)}function P(){return _.get("/v1/units/form/meta")}function Q(){const l=D(),{t:a}=B();return{getShowData:async(V,b=!1)=>{var p,f;try{return{status:200,data:(await J(V,b)).data.body}}catch(n){return((p=n==null?void 0:n.response)==null?void 0:p.status)!==404&&l.error(a("core::errors.an_unexpected_error_occurred")),{status:(f=n==null?void 0:n.response)==null?void 0:f.status}}},update:K,store:O,getFormMeta:P}}const X={class:"d-flex align-center"},oe=I({__name:"Form",props:{item:{},action:{}},setup(l){var v,w,h,x;const a=l,{t:d}=B(),{getFormMeta:V,update:b,store:p}=Q(),f=M(),n=k({types:[]}),t=W({name:((v=a.item)==null?void 0:v.name)||{},symbol:((w=a.item)==null?void 0:w.symbol)||{},type:(x=(h=a.item)==null?void 0:h.type)==null?void 0:x.id}),S=async()=>{!t.loading.value&&await t.submit(()=>{var u;return a.action=="create"?p(t.state):b((u=a.item)==null?void 0:u.id,t.state)})&&await f.push({name:"admin.units.index"})};return N(async()=>{try{const u=(await V()).data.body;n.value.types=u.types}catch{}}),(u,$)=>{const T=g;return j(),R(T,{action:u.action,"has-multiple-language":"",loading:e(t).loading.value,resource:"units",onSubmit:S},{default:r(({currentLanguage:o})=>[s(C,null,{default:r(()=>[s(y,{cols:"12"},{default:r(()=>[s(q,null,{default:r(()=>[s(A,{class:"d-flex justify-space-between align-center mb-2"},{default:r(()=>[U("div",X,[s(z,{class:"me-2",icon:"tabler-info-circle",size:"20"}),U("span",null,H(e(d)("inventory::units.form.cards.unit_information")),1)])]),_:1}),s(E,null,{default:r(()=>[s(C,null,{default:r(()=>[s(y,{cols:"12",md:"4"},{default:r(()=>{var i,m;return[s(F,{modelValue:e(t).state.name[o.id],"onUpdate:modelValue":c=>e(t).state.name[o.id]=c,error:!!((i=e(t).errors.value)!=null&&i[`name.${o.id}`]),"error-messages":(m=e(t).errors.value)==null?void 0:m[`name.${o.id}`],label:e(d)("inventory::attributes.units.name")+` ( ${o.name} )`},null,8,["modelValue","onUpdate:modelValue","error","error-messages","label"])]}),_:2},1024),s(y,{cols:"12",md:"4"},{default:r(()=>{var i,m;return[s(F,{modelValue:e(t).state.symbol[o.id],"onUpdate:modelValue":c=>e(t).state.symbol[o.id]=c,error:!!((i=e(t).errors.value)!=null&&i[`symbol.${o.id}`]),"error-messages":(m=e(t).errors.value)==null?void 0:m[`symbol.${o.id}`],label:e(d)("inventory::attributes.units.symbol")+` ( ${o.name} )`},null,8,["modelValue","onUpdate:modelValue","error","error-messages","label"])]}),_:2},1024),s(y,{cols:"12",md:"4"},{default:r(()=>{var i,m;return[s(G,{modelValue:e(t).state.type,"onUpdate:modelValue":$[0]||($[0]=c=>e(t).state.type=c),error:!!((i=e(t).errors.value)!=null&&i.type),"error-messages":(m=e(t).errors.value)==null?void 0:m.type,"item-title":"name","item-value":"id",items:e(n).types,label:e(d)("inventory::attributes.units.type")},null,8,["modelValue","error","error-messages","items","label"])]}),_:1})]),_:2},1024)]),_:2},1024)]),_:2},1024)]),_:2},1024)]),_:2},1024)]),_:1},8,["action","loading"])}}});export{oe as _,Q as u};
