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