import{_ as R}from"./BaseForm.vue_vue_type_script_setup_true_lang-BnxGTisD.js";import{d as j,H as z,P as A,I as G,r as H,W as P,w as W,f as q,h as C,v as e,i as n,c as a,x as F,V as $,y as E,G as J}from"./index-C5GbdPxY.js";import{u as K}from"./stockMovement-suQ3eY2r.js";import{u as L}from"./form-B2je8iBR.js";import{a as c,V as B}from"./VAvatar-RkAR0u0e.js";import{c as O,V as Q,a as X}from"./VCard-DptrO3GI.js";import{V as b}from"./VSelect-vtfYszIh.js";import{V as Y}from"./VTextField-DxEUpn3-.js";import{V as Z}from"./VTextarea-DwarFG-O.js";const ee={class:"d-flex align-center"},de=j({__name:"Form",props:{item:{},action:{}},setup(U){var v,f,g,y,V,h,k,w;const d=U,{t:u}=z(),{user:_}=A(),{getFormMeta:S,update:T,store:M}=K(),N=G(),t=L({branch_id:_!=null&&_.assigned_to_branch?_.branch_id:(f=(v=d.item)==null?void 0:v.branch)==null?void 0:f.id,ingredient_id:(y=(g=d.item)==null?void 0:g.ingredient)==null?void 0:y.id,type:(h=(V=d.item)==null?void 0:V.type)==null?void 0:h.id,quantity:(k=d.item)==null?void 0:k.quantity,note:(w=d.item)==null?void 0:w.note}),l=H({branches:[],types:[],ingredients:[]}),D=async()=>{!t.loading.value&&await t.submit(()=>{var i;return d.action=="create"?M(t.state):T((i=d.item)==null?void 0:i.id,t.state)})&&await N.push({name:"admin.stock_movements.index"})};P(()=>{p(),t.state.branch_id&&p(t.state.branch_id)}),W(()=>t.state.branch_id,i=>{t.state.ingredient_id=null,l.value.ingredients=[],p(i)});const p=async i=>{try{const r=(await S(i)).data.body;l.value.branches=r.branches||l.value.branches,l.value.types=r.types||l.value.types,i&&(l.value.ingredients=r.ingredients)}catch{}};return(i,r)=>{const I=R;return C(),q(I,{action:i.action,loading:e(t).loading.value,resource:"stock-movements",onSubmit:D},{default:n(()=>[a(B,null,{default:n(()=>[a(c,{cols:"12"},{default:n(()=>[a(O,null,{default:n(()=>[a(Q,{class:"d-flex justify-space-between align-center mb-2"},{default:n(()=>[F("div",ee,[a($,{class:"me-2",icon:"tabler-info-circle",size:"20"}),F("span",null,E(e(u)("inventory::stock_movements.form.cards.stock_movement_information")),1)])]),_:1}),a(X,null,{default:n(()=>[a(B,null,{default:n(()=>{var x;return[i.action=="create"&&!((x=e(_))!=null&&x.assigned_to_branch)?(C(),q(c,{key:0,cols:"12",md:"6"},{default:n(()=>{var s,o;return[a(b,{modelValue:e(t).state.branch_id,"onUpdate:modelValue":r[0]||(r[0]=m=>e(t).state.branch_id=m),error:!!((s=e(t).errors.value)!=null&&s.branch_id),"error-messages":(o=e(t).errors.value)==null?void 0:o.branch_id,"item-title":"name","item-value":"id",items:e(l).branches,label:e(u)("inventory::attributes.stock_movements.branch_id")},null,8,["modelValue","error","error-messages","items","label"])]}),_:1})):J("",!0),a(c,{cols:"12",md:"6"},{default:n(()=>{var s,o;return[a(b,{modelValue:e(t).state.type,"onUpdate:modelValue":r[1]||(r[1]=m=>e(t).state.type=m),error:!!((s=e(t).errors.value)!=null&&s.type),"error-messages":(o=e(t).errors.value)==null?void 0:o.type,"item-title":"name","item-value":"id",items:e(l).types,label:e(u)("inventory::attributes.stock_movements.type")},null,8,["modelValue","error","error-messages","items","label"])]}),_:1}),a(c,{cols:"12",md:"6"},{default:n(()=>{var s,o;return[a(b,{modelValue:e(t).state.ingredient_id,"onUpdate:modelValue":r[2]||(r[2]=m=>e(t).state.ingredient_id=m),error:!!((s=e(t).errors.value)!=null&&s.ingredient_id),"error-messages":(o=e(t).errors.value)==null?void 0:o.ingredient_id,"item-title":"name","item-value":"id",items:e(l).ingredients,label:e(u)("inventory::attributes.stock_movements.ingredient_id")},null,8,["modelValue","error","error-messages","items","label"])]}),_:1}),a(c,{cols:"12",md:"6"},{default:n(()=>{var s,o;return[a(Y,{modelValue:e(t).state.quantity,"onUpdate:modelValue":r[3]||(r[3]=m=>e(t).state.quantity=m),error:!!((s=e(t).errors.value)!=null&&s.quantity),"error-messages":(o=e(t).errors.value)==null?void 0:o.quantity,label:e(u)("inventory::attributes.stock_movements.quantity")},null,8,["modelValue","error","error-messages","label"])]}),_:1}),a(c,{cols:"12"},{default:n(()=>{var s,o;return[a(Z,{modelValue:e(t).state.note,"onUpdate:modelValue":r[4]||(r[4]=m=>e(t).state.note=m),"auto-grow":"",clearable:"",counter:1e3,error:!!((s=e(t).errors.value)!=null&&s.note),"error-messages":(o=e(t).errors.value)==null?void 0:o.note,label:e(u)("inventory::attributes.stock_movements.note"),rows:"4"},null,8,["modelValue","error","error-messages","label"])]}),_:1})]}),_:1})]),_:1})]),_:1})]),_:1})]),_:1})]),_:1},8,["action","loading"])}}});export{de as _};
