import{_ as g}from"./DUQr9DrG.js";import{_ as y}from"./BONdwzJ0.js";import{_ as T}from"./G7u0egV4.js";import{d as h,O as w,P as x,p as C,J as j,z as r,a as q,f as a,w as F,g as n,F as S,o as k,e as D,n as l,i as E}from"./JQJBiNWj.js";import A from"./D42GNhrT.js";import{h as B}from"./CH1bAkoS.js";import"./BwwR4PPN.js";import"./B6O9xiO5.js";import"./HM4z-iuB.js";import"./DqVYbxj5.js";import"./CxkaGOlL.js";import"./BgAkS4D_.js";import"./DKM0wLqG.js";import"./4FMzYxPj.js";import"./BWs0r_ue.js";import"./CeWG_dyW.js";import"./CDSORL4U.js";import"./Cr9ZZaT-.js";import"./DNRi6U01.js";import"./BYfmWBgX.js";import"./CJYlvWEf.js";import"./BBDFeM-T.js";import"./BuR5k2Xw.js";import"./ClVEEBFD.js";import"./2JTb7YQn.js";import"./Dk4pWsnS.js";import"./BSHuRY0P.js";import"./3oa0FK2h.js";import"./Dc_YXEFz.js";import"./CRodc3LN.js";import"./B-La3K3C.js";import"./F98GHXdS.js";import"./DvBDpJyt.js";const O={class:"flex gap-3 -mx-4 -mb-4 p-4 bg-white sticky bottom-0 border-t items-center flex-wrap justify-end"},be=h({__name:"adicionar",async setup(I){let s,d;const u=w(),_=([s,d]=x(()=>u.getEmpresaSelecionada()),s=await s,d(),s),p=C(),c=j({titulo:void 0,idTipo:void 0,idObjetivo:void 0,idCidade:void 0,idTrecho:void 0,kmInicial:void 0,kmFinal:void 0,faixa:void 0,status:void 0,tiposAnexos:[],responsaveis:[]}),v=B(r.object({titulo:r.string({required_error:"Título é obrigatório"}),idCidade:r.number({required_error:"Cidade é obrigatória"}),kmInicial:r.number({required_error:"KM Inicial é obrigatório"}),kmFinal:r.number({required_error:"KM Final é obrigatório"}),idTrecho:r.number({required_error:"Trecho é obrigatório"}),idTipo:r.number({required_error:"Tipo é obrigatório"}),idObjetivo:r.number({required_error:"Objetivo é obrigatório"})}));function b(t){if(!t.valid)return;const i={idEmpresa:_.id};Object.keys(t.states).forEach(o=>{const e=t.states[o].value;e!==void 0&&(typeof e=="object"&&e!==null?Array.isArray(e)?i[o]=e.map(m=>m.id):i[o]=e.id:i[o]=e)}),E.demandas.createDemanda(i).then(()=>{p.add({severity:"success",summary:"Sucesso",detail:"Demanda criada com sucesso!",life:5e3}),l("consultar")}).catch(o=>{var e;p.add({severity:"error",life:1e4,summary:"Erro",detail:((e=o.data)==null?void 0:e.message)||o.message})})}return(t,i)=>{const o=g,e=y,m=T,f=A;return k(),q(S,null,[a(o,{title:"Demandas - Adicionar"}),a(f,{class:"space-y-8","initial-values":n(c),resolver:n(v),onSubmit:b},{default:F(()=>[a(e,{demanda:n(c)},null,8,["demanda"]),D("div",O,[a(m,{mode:"cancel",class:"w-full sm:w-auto",onClick:i[0]||(i[0]=K=>("navigateTo"in t?t.navigateTo:n(l))("./consultar"))}),a(m,{mode:"save",class:"w-full sm:w-auto",type:"submit"})])]),_:1},8,["initial-values","resolver"])],64)}}});export{be as default};
