import{_ as R}from"./DDV-HLQE.js";import{_ as B}from"./Brk5FU9k.js";import{_ as T}from"./C682XpkB.js";import{_ as j}from"./DW2OqR52.js";import A from"./G1F3Bacz.js";import{z as h,d as S,p as N,j as g,i as D,b as w,o as u,U as O,w as n,g as a,e as U,t as V,a as k,f as o,E as q,l as L,J as G,L as P,F as M}from"./dVzHJMF1.js";import{_ as z}from"./Cn3xUAbr.js";import{_ as J}from"./BqnRxGiA.js";import H from"./iZ-xiGRB.js";import K from"./B7Hqpkvs.js";import Q from"./C5Oc2f2M.js";import{U as W,O as X}from"./BNYh59m7.js";import{u as Y}from"./DzXlli-V.js";import{h as Z}from"./CH1bAkoS.js";import{u as ee}from"./Bpf-t_rp.js";import"./DhLu8RVk.js";import"./CWHHmK0V.js";import"./yXj_05M0.js";import"./Bhud8mbC.js";import"./tESAK1vk.js";import"./B79Hoqpc.js";import"./CX2DUt_P.js";import"./DDpCYtr5.js";import"./C9UvFovT.js";import"./FaLtR_4n.js";import"./C9L2ikqF.js";import"./B3dHCiEQ.js";import"./BZjcnCH7.js";import"./DiwqsPB4.js";import"./KcBrPYTF.js";import"./B_Kqq5Cu.js";import"./CBbadgK0.js";import"./a1m94JqE.js";import"./CM8mMzv6.js";import"./DP0doleY.js";import"./BAtzogEJ.js";import"./r1Y5hC84.js";import"./BSe03gVj.js";import"./B-6EeO4n.js";import"./BuQ9u7Je.js";import"./BW5cYMVL.js";import"./CPg0DzIm.js";import"./BphmgIhx.js";import"./ClA_a7pZ.js";import"./cMkL48JQ.js";import"./BSLzRQpY.js";import"./yHxjwlra.js";import"./KG16xCEZ.js";const oe=W.map(l=>l.sigla),ae=h.object({uf:h.enum(oe),descricao:h.string().min(1)}),te=Z(ae),se={key:0,class:"text-center"},ie={class:"max-sm:w-full"},re={class:"flex flex-wrap gap-3 items-center justify-end max-sm:w-full"},ne=S({__name:"Modal",props:{findCidades:{type:Function}},setup(l,{expose:p}){const d=N(),t=g(!1),c=g(!0),s=g(!1),e=g({}),m=D.cidades;async function _(r){c.value=!1;try{const v=await m.getById(r);e.value={...v},c.value=!0}catch(i){console.error("Erro ao buscar cidade por ID:",i),d.add({severity:"error",life:1e4,summary:"Erro!",detail:"Erro ao buscar cidade para edição."})}}const y=async r=>{if(s.value=!0,!r.valid){console.error("Erro: Formulário inválido.",r),s.value=!1;return}const i={...r.values};e.value.id&&(i.id=e.value.id),(e.value.id?m.edit(e.value.id,i):m.save(i)).then(()=>{d.add({summary:e.value.id?"A cicade foi editada com sucesso.":"A cidade foi criada com sucesso.",severity:"success",life:5e3}),l.findCidades(),t.value=!1}).catch(C=>{var f;d.add({detail:((f=C.data)==null?void 0:f.message)||C.message||"Verifique os erros no formulário.",severity:"error",life:1e4})}).finally(()=>{s.value=!1})},x=Y(async()=>{if(!e.value.id)throw new Error;await m.delete(e.value.id)},{confirmMessage:"Tem certeza que deseja excluir esta cidade?",successMessage:"Cidade excluída com sucesso.",onSuccess:()=>{t.value=!1,l.findCidades()}});return p({openModal:async r=>{r?_(r):e.value={descricao:void 0,uf:void 0},t.value=!0}}),(r,i)=>{const v=z,C=Q,f=J,E=K,I=H,b=B,$=G;return u(),w($,{visible:a(t),"onUpdate:visible":i[1]||(i[1]=F=>L(t)?t.value=F:null),modal:"",draggable:!1,closable:!1},O({footer:n(()=>[U("div",ie,[a(e).id!==void 0?(u(),w(b,{key:0,class:"max-sm:w-full",mode:"delete",onClick:a(x)},null,8,["onClick"])):q("",!0)]),U("div",re,[o(b,{mode:"cancel",class:"max-sm:w-full",onClick:i[0]||(i[0]=F=>t.value=!1)}),o(b,{mode:"save",class:"max-sm:w-full",type:"submit",form:"form-cidade",loading:a(s)},null,8,["loading"])])]),default:n(()=>[a(c)===!1?(u(),k("div",se,[o(v)])):(u(),w(I,{id:"form-cidade",key:a(e).id,"initial-values":a(e),resolver:a(te),onSubmit:y},{default:n(()=>[o(f,{name:"uf",label:"UF:"},{default:n(()=>[o(C,{id:"uf",name:"uf",options:a(X),"option-label":"label","option-value":"value",placeholder:"Selecione a UF..."},null,8,["options"])]),_:1}),o(f,{name:"descricao",label:"Descrição"},{default:n(()=>[o(E,{id:"descricao"})]),_:1})]),_:1},8,["initial-values","resolver"]))]),_:2},[a(c)!==!1?{name:"header",fn:n(()=>[U("h2",null,V(a(e).id?"Editar cidade":"Nova cidade"),1)]),key:"0"}:void 0]),1032,["visible"])}}}),de=Object.assign(ne,{__name:"ConfiguracoesCadastrosGeraisCidadeModal"}),le=S({__name:"Card",setup(l){const p=P("modalCidades"),d=ee("cidades-list",s=>D.cidades.getAll(s),{immediate:!0,initialRows:5}),t=s=>{var e;(e=p.value)==null||e.openModal(s)};function c(s){t(s.data.id)}return(s,e)=>{const m=B,_=A,y=T,x=j;return u(),k(M,null,[o(x,{title:"Cidades"},{button:n(()=>[o(m,{mode:"addIcon",onClick:e[0]||(e[0]=()=>t())})]),default:n(()=>[o(y,{value:a(d),"empty-message":"Nenhuma cidade foi encontrada.","auto-paginator":"","high-density":"",onRowClick:c},{default:n(()=>[o(_,{field:"uf",header:"UF",sortable:"","header-class":"min-column","body-class":"min-column"}),o(_,{field:"descricao",header:"Descrição",sortable:""})]),_:1},8,["value"])]),_:1}),o(de,{ref_key:"modalCidades",ref:p,"find-cidades":a(d).execute},null,8,["find-cidades"])],64)}}}),ce=Object.assign(le,{__name:"ConfiguracoesCadastrosGeraisCidadeCard"}),io=S({__name:"index",setup(l){return(p,d)=>{const t=R;return u(),k(M,null,[o(t,{title:"Cadastros gerais do sistema"}),o(ce)],64)}}});export{io as default};
