import{_ as j}from"./BtEXx3og.js";import{_ as A}from"./gxHWKiUc.js";import{_ as L}from"./G7u0egV4.js";import{U as $}from"./CSyF93-1.js";import{d as F,L as q,u as z,j as u,p as G,i as J,z as b,c as W,k as E,a as h,o as c,f as l,N as X,W as Z,w as i,g as a,e as g,t as H,R as K,b as w,E as Q}from"./JQJBiNWj.js";import Y from"./D42GNhrT.js";import ee from"./CJYlvWEf.js";import{h as se}from"./CH1bAkoS.js";import{u as ae}from"./F98GHXdS.js";import{u as oe}from"./ChMy_Kon.js";const te={key:0,class:"text-center pb-2"},le={class:"max-sm:w-full"},ne={class:"flex flex-wrap gap-3 items-center justify-end max-sm:w-full ms-auto"},re=F({__name:"Modal",props:{modelValue:{type:Boolean,default:!1},modelModifiers:{}},emits:q(["update","delete"],["update:modelValue"]),setup(k,{expose:M,emit:O}){const x=O,o=z(k,"modelValue"),d=u(!1),f=G(),m=J.pleitos.cadastros.demandantes,s=u(),n=u(),P=u(se(b.object({nome:b.string().min(1).max(150)}))),{data:D,status:N,refresh:C,error:v}=ae(async()=>s.value?m.findById(s.value):null,"$JjhZe_Tr22"),I=oe(async()=>{if(!s.value)throw new Error;await m.delete(s.value)},{confirmMessage:"Tem certeza que deseja excluir este demandante?",successMessage:"Demandante excluído com sucesso.",onSuccess:()=>{o.value=!1,s.value&&x("delete",s.value)}}),R=async e=>{if(!e.valid)return;const t={...e.values},_=s.value?m.edit(s.value,t):m.save(t);d.value=!0,_.then(r=>{f.add({summary:"Sucesso",detail:s.value?"O demandante foi editado com sucesso.":"O demandante foi criado com sucesso.",severity:"success",life:5e3}),x("update",r),o.value=!1}).catch(r=>{f.add({summary:"Erro",detail:r.data.message??r.message??"Ocorreu um erro. Tente novamente mais tarde.",severity:"error",life:1e4})}).finally(()=>{d.value=!1})},p=W(()=>!s.value&&!n.value?!0:N.value!=="pending"&&n.value);return M({open:e=>{s.value=e==null?void 0:e.id,e!=null&&e.id?C():n.value=void 0,o.value=!0}}),E(D,e=>{if(!e){n.value=void 0;return}n.value={nome:e.nome}}),E(v,()=>{var e;v.value&&(o.value=!1,f.add({summary:"Erro",severity:"error",life:1e4,detail:((e=v.value.data)==null?void 0:e.message)??"Ocorreu um erro ao buscar demandante."}))}),(e,t)=>{const _=j,r=ee,B=A,T=Y,y=L,U=$,V=X;return c(),h("div",null,[l(V,{visible:o.value,"onUpdate:visible":t[1]||(t[1]=S=>o.value=S),modal:"",draggable:!1,closable:!1},Z({default:i(()=>[a(p)?(c(),w(T,{id:"form-demandante",key:a(s),"initial-values":a(n),resolver:a(P),onSubmit:R},{default:i(()=>[l(B,{name:"nome",label:"Nome:",class:"flex flex-col mb-4"},{default:i(()=>[l(r,{id:"nome",minlength:"1",maxlength:"150",autofocus:""})]),_:1})]),_:1},8,["initial-values","resolver"])):(c(),h("div",te,[l(_)]))]),_:2},[a(p)?{name:"header",fn:i(()=>[g("h2",null,H(a(s)!=null?"Editar demandante":"Adicionar demandante"),1)]),key:"0"}:void 0,a(p)?{name:"footer",fn:i(()=>[l(U,{permissions:[("PERMISSION_ROLES"in e?e.PERMISSION_ROLES:a(K)).PLT_TAB_DEMANDANTE_EXCLUIR]},{default:i(()=>[g("div",le,[a(s)?(c(),w(y,{key:0,class:"max-sm:w-full",mode:"delete",onClick:a(I)},null,8,["onClick"])):Q("",!0)])]),_:1},8,["permissions"]),g("div",ne,[l(y,{mode:"cancel",class:"max-sm:w-full",onClick:t[0]||(t[0]=S=>o.value=!1)}),l(y,{mode:"save",type:"submit",form:"form-demandante",class:"min-w-32 max-sm:w-full",loading:a(d)},null,8,["loading"])])]),key:"1"}:void 0]),1032,["visible"])])}}}),ge=Object.assign(re,{__name:"PleitosCadastrosDemandanteModal"});export{ge as P};
