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