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