PageSourceSearch

https://www.negociobr.com/assets/Localidades-Cg9hH_hz.js

js negociobr.com collected 2026-10-09 22:02:36 UTC 10,726 bytes, 6 lines download raw bytes

1import{c as xe,bt as me,r as o,j as e,S as J,M as ue,B as i,C as je,t as ge,v as ve,w as pe,m as Ce,y as K,a4 as Q,q as h,K as Ne,O as fe,Q as ye,V as we,Y as u,D as Y,E as W,G as X,H as Z,J as ee,I as z,aq as Se}from"./index-Bw1uC_Ic.js";import{A as L,h as P,a as T,b as B,c as I,d as O,e as H,f as R,g as U}from"./alert-dialog-g6bnM3TP.js";import{C as se,a as ae,b as te}from"./collapsible-D0Eni03l.js";import{e as _e,d as ke,c as Ee,f as De,g as be,h as Ae,i as ie}from"./useLocations-CwyJ8DFp.js";import{P as F}from"./plus-DvBibh6Y.js";import{P as V}from"./pencil-BB-t_-gJ.js";import{T as q}from"./trash-2-Gm5VH7WN.js";import"./index-ClF4-9bZ.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const Me=xe("Building",[["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",ry:"2",key:"76otgf"}],["path",{d:"M9 22v-4h6v4",key:"r93iot"}],["path",{d:"M8 6h.01",key:"1dz90k"}],["path",{d:"M16 6h.01",key:"1x0f13"}],["path",{d:"M12 6h.01",key:"1vi96p"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M16 10h.01",key:"1m94wz"}],["path",{d:"M16 14h.01",key:"1gbofw"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M8 14h.01",key:"6423bh"}]]),Re=()=>{const{toast:c}=me(),[ce,j]=o.useState(!1),[l,$]=o.useState(null),[d,G]=o.useState("country"),[t,x]=o.useState({name:"",code:"",slug:"",is_active:!0}),[p,de]=o.useState(new Set),[C,ne]=o.useState(new Set),[g,N]=o.useState(),[v,f]=o.useState(),{data:n,isLoading:le}=_e(),{data:m}=ke(),{data:y}=Ee(),w=De(),S=be(),_=Ae(),re=s=>{const a=new Set(p);a.has(s)?a.delete(s):a.add(s),de(a)},oe=s=>{const a=new Set(C);a.has(s)?a.delete(s):a.add(s),ne(a)},k=(s,a)=>{G(s),$(null),x({name:"",code:"",slug:"",is_active:!0,country_id:s==="state"?a:void 0,state_id:s==="city"?a:void 0}),s==="state"&&N(a),s==="city"&&f(a),j(!0)},E=(s,a)=>{G(s),$({type:s,id:a.id}),x({name:a.name,code:a.code||"",slug:a.slug||"",is_active:a.is_active,country_id:a.country_id,state_id:a.state_id}),N(a.country_id),f(a.state_id),j(!0)},he=async()=>{try{if(d==="country")l?(await w.update.mutateAsync({id:l.id,name:t.name,code:t.code.toUpperCase(),is_active:t.is_active}),c({title:"País atualizado com sucesso!"})):(await w.create.mutateAsync({name:t.name,code:t.code.toUpperCase(),is_active:t.is_active}),c({title:"País criado com sucesso!"}));else if(d==="state"){if(!g){c({title:"Selecione um país",variant:"destructive"});return}l?(await S.update.mutateAsync({id:l.id,name:t.name,code:t.code.toUpperCase(),country_id:g,is_active:t.is_active}),c({title:"Estado atualizado com sucesso!"})):(await S.create.mutateAsync({name:t.name,code:t.code.toUpperCase(),country_id:g,is_active:t.is_active}),c({title:"Estado criado com sucesso!"}))}else if(d==="city"){if(!v){c({title:"Selecione um estado",variant:"destructive"});return}const s=t.slug||ie(t.name);l?(await _.update.mutateAsync({id:l.id,name:t.name,slug:s,state_id:v,is_active:t.is_active}),c({title:"Cidade atualizada com sucesso!"})):(await _.create.mutateAsync({name:t.name,slug:s,state_id:v,is_active:t.is_active}),c({title:"Cidade criada com sucesso!"}))}j(!1)}catch(s){c({title:"Erro ao salvar",description:s.message,variant:"destructive"})}},D=async(s,a)=>{try{s==="country"?await w.remove.mutateAsync(a):s==="state"?await S.remove.mutateAsync(a):s==="city"&&await _.remove.mutateAsync(a),c({title:"Removido com sucesso!"})}catch(r){c({title:"Erro ao remover",description:r.message,variant:"destructive"})}},b=s=>(m==null?void 0:m.filter(a=>a.country_id===s))||[],A=s=>(y==null?void 0:y.filter(a=>a.state_id===s))||[],M=()=>{switch(d){case"country":return"País";case"state":return"Estado";case"city":return"Cidade"}};return le?e.jsxs("div",{className:"space-y-6",children:[e.jsx(J,{className:"h-8 w-48"}),e.jsx(J,{className:"h-64 w-full"})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-foreground flex items-center gap-2",children:[e.jsx(ue,{className:"h-6 w-6"}),"Localidades"]}),e.jsx("p",{className:"text-muted-foreground",children:"Gerencie países, estados e cidades"})]}),e.jsxs(i,{onClick:()=>k("country"),children:[e.jsx(F,{className:"h-4 w-4 mr-2"}),"Novo País"]}
6)]}),e.jsxs(je,{children:[e.jsxs(ge,{children:[e.jsx(ve,{children:"Hierarquia de Localidades"}),e.jsx(pe,{children:"Expanda para ver e gerenciar estados e cidades"})]}),e.jsx(Ce,{className:"space-y-2",children:(n==null?void 0:n.length)===0?e.jsx("p",{className:"text-muted-foreground text-center py-8",children:"Nenhum país cadastrado"}):n==null?void 0:n.map(s=>e.jsxs(se,{open:p.has(s.id),onOpenChange:()=>re(s.id),children:[e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted/50 rounded-lg",children:[e.jsx(ae,{asChild:!0,children:e.jsx(i,{variant:"ghost",size:"icon",className:"h-6 w-6",children:p.has(s.id)?e.jsx(K,{className:"h-4 w-4"}):e.jsx(Q,{className:"h-4 w-4"})})}),e.jsx("span",{className:"font-medium flex-1",children:s.name}),e.jsx(h,{variant:"outline",children:s.code}),!s.is_active&&e.jsx(h,{variant:"secondary",children:"Inativo"}),e.jsxs(h,{variant:"secondary",children:[b(s.id).length," estados"]}),e.jsx(i,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>k("state",s.id),children:e.jsx(F,{className:"h-4 w-4"})}),e.jsx(i,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>E("country",s),children:e.jsx(V,{className:"h-4 w-4"})}),e.jsxs(L,{children:[e.jsx(P,{asChild:!0,children:e.jsx(i,{variant:"ghost",size:"icon",className:"h-7 w-7 text-destructive",children:e.jsx(q,{className:"h-4 w-4"})})}),e.jsxs(T,{children:[e.jsxs(B,{children:[e.jsx(I,{children:"Excluir país?"}),e.jsx(O,{children:"Isso excluirá todos os estados e cidades associados."})]}
6),e.jsxs(H,{children:[e.jsx(R,{children:"Cancelar"}),e.jsx(U,{onClick:()=>D("country",s.id),className:"bg-destructive text-destructive-foreground",children:"Excluir"})]})]})]})]}),e.jsxs(te,{className:"pl-8 space-y-2 mt-2",children:[b(s.id).map(a=>e.jsxs(se,{open:C.has(a.id),onOpenChange:()=>oe(a.id),children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-background rounded border",children:[e.jsx(ae,{asChild:!0,children:e.jsx(i,{variant:"ghost",size:"icon",className:"h-5 w-5",children:C.has(a.id)?e.jsx(K,{className:"h-3 w-3"}):e.jsx(Q,{className:"h-3 w-3"})})}),e.jsx("span",{className:"flex-1 text-sm",children:a.name}),e.jsx(h,{variant:"outline",className:"text-xs",children:a.code}),!a.is_active&&e.jsx(h,{variant:"secondary",className:"text-xs",children:"Inativo"}),e.jsxs(h,{variant:"secondary",className:"text-xs",children:[A(a.id).length," cidades"]}),e.jsx(i,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>k("city",a.id),children:e.jsx(F,{className:"h-3 w-3"})}),e.jsx(i,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>E("state",a),children:e.jsx(V,{className:"h-3 w-3"})}),e.jsxs(L,{children:[e.jsx(P,{asChild:!0,children:e.jsx(i,{variant:"ghost",size:"icon",className:"h-6 w-6 text-destructive",children:e.jsx(q,{className:"h-3 w-3"})})}),e.jsxs(T,{children:[e.jsxs(B,{children:[e.jsx(I,{children:"Excluir estado?"}),e.jsx(O,{children:"Isso excluirá todas as cidades associadas."})]}
6),e.jsxs(H,{children:[e.jsx(R,{children:"Cancelar"}),e.jsx(U,{onClick:()=>D("state",a.id),className:"bg-destructive text-destructive-foreground",children:"Excluir"})]})]})]})]}),e.jsxs(te,{className:"pl-8 space-y-1 mt-1",children:[A(a.id).map(r=>e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded text-sm",children:[e.jsx(Me,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:"flex-1",children:r.name}),e.jsxs("code",{className:"text-xs text-muted-foreground",children:["/",a.code.toLowerCase(),"/",r.slug]}),!r.is_active&&e.jsx(h,{variant:"secondary",className:"text-xs",children:"Inativo"}),e.jsx(i,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>E("city",{...r,state_id:a.id}),children:e.jsx(V,{className:"h-3 w-3"})}),e.jsxs(L,{children:[e.jsx(P,{asChild:!0,children:e.jsx(i,{variant:"ghost",size:"icon",className:"h-5 w-5 text-destructive",children:e.jsx(q,{className:"h-3 w-3"})})}),e.jsxs(T,{children:[e.jsxs(B,{children:[e.jsx(I,{children:"Excluir cidade?"}),e.jsx(O,{children:"Esta ação não pode ser desfeita."})]}
6),e.jsxs(H,{children:[e.jsx(R,{children:"Cancelar"}),e.jsx(U,{onClick:()=>D("city",r.id),className:"bg-destructive text-destructive-foreground",children:"Excluir"})]})]})]})]},r.id)),A(a.id).length===0&&e.jsx("p",{className:"text-xs text-muted-foreground py-2 text-center",children:"Nenhuma cidade cadastrada"})]})]},a.id)),b(s.id).length===0&&e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"Nenhum estado cadastrado"})]})]},s.id))})]}),e.jsx(Ne,{open:ce,onOpenChange:j,children:e.jsxs(fe,{children:[e.jsx(ye,{children:e.jsx(we,{children:l?`Editar ${M()}`:`Novo ${M()}`})}),e.jsxs("div",{className:"space-y-4",children:[d==="state"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"País"}),e.jsxs(Y,{value:g,onValueChange:N,children:[e.jsx(W,{children:e.jsx(X,{placeholder:"Selecione o país"})}),e.jsx(Z,{children:n==null?void 0:n.map(s=>e.jsx(ee,{value:s.id,children:s.name},s.id))})]})]}),d==="city"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Estado"}),e.jsxs(Y,{value:v,onValueChange:f,children:[e.jsx(W,{children:e.jsx(X,{placeholder:"Selecione o estado"})}),e.jsx(Z,{children:m==null?void 0:m.map(s=>e.jsxs(ee,{value:s.id,children:[s.name," (",s.code,")"]},s.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Nome"}),e.jsx(z,{value:t.name,onChange:s=>x({...t,name:s.target.value}),placeholder:`Nome do ${M().toLowerCase()}`})]}),d!=="city"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Código"}),e.jsx(z,{value:t.code,onChange:s=>x({...t,code:s.target.value}),placeholder:d==="country"?"BR":"SP",maxLength:d==="country"?2:3})]}),d==="city"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Slug (URL)"}),e.jsx(z,{value:t.slug||ie(t.name),onChange:s=>x({...t,slug:s.target.value}),placeholder:"sao-paulo"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Deixe em branco para gerar automaticamente"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{checked:t.is_active,onCheckedChange:s=>x({...t,is_active:s})}),e.jsx(u,{children:"Ativo"})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(i,{variant:"outline",onClick:()=>j(!1),children:"Cancelar"}),e.jsx(i,{onClick:he,children:l?"Salvar":"Criar"})]})]})]})})]})};export{Re as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.