PageSourceSearch

https://buske.ai/assets/AdminCreci-DfNiw5kb.js

js buske.ai collected 2026-10-05 11:54:11 UTC 9,251 bytes, 1 lines download raw bytes

1import{r as t,j as e}from"./react-vendor-BXTNdvBF.js";import{cw as v,C as K,cT as D,T as Q,L as S,es as J,et as M,eu as U,ev as V,ew as C,I as $,B as Z,f as ee,S as se,h as u,G as re}from"./index-DVCmV4wM.js";import{A as ae}from"./AdminLayout-38kh7xh4.js";import{C as z,a as O,b as ne,c as oe,d as te}from"./card-BQMxlNPT.js";import{a as ie}from"./adminApi-BZHVw8LJ.js";import"./supabase-vendor-Blds1cMP.js";import"./AccountBreadcrumb-QseNSWwX.js";import"./PageBreadcrumb-DRAGFQka.js";const ce={RJ:6,SP:6,SP_STAR:6},k=r=>r.replace(/\D/g,""),G=r=>r.trim().split(/\s+/).filter(Boolean).length>=2,X=r=>r==="NOT_FOUND"?"not_found":r==="UNAVAILABLE"?"unavailable":"error";async function le(r,N){const i=r==="SP_STAR"?"SP":r,R=i==="SP"?"/api/creci/search-sp":"/api/creci/search-rj",m=`CRECI-${i}`;try{const x=await fetch(`${re}${R}`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({nome:N})}),s=await x.json().catch(()=>({}));return x.ok?{success:!!(s!=null&&s.success),reason:s==null?void 0:s.reason,error:s==null?void 0:s.error,fonte:(s==null?void 0:s.fonte)||m,results:Array.isArray(s==null?void 0:s.results)?s.results:[]}:{success:!1,reason:"UNAVAILABLE",error:(s==null?void 0:s.error)||"Serviço temporariamente indisponível.",fonte:m,results:[]}}catch{return{success:!1,reason:"UNAVAILABLE",error:"Erro ao consultar por nome.",fonte:m,results:[]}}}function ge(){const[r,N]=t.useState("RJ"),[i,R]=t.useState("numero"),[m,x]=t.useState(""),[s,w]=t.useState(""),[a,c]=t.useState("idle"),[n,h]=t.useState(null),[E,f]=t.useState([]),[I,p]=t.useState(""),[F,d]=t.useState(""),[H,b]=t.useState(!1),T=ce[r],_=t.useMemo(()=>k(m),[m]);t.useEffect(()=>{b(!1)},[n==null?void 0:n.foto_url]);const W=async o=>{o.preventDefault();try{if(c("loading"),d(""),h(null),f([]),p(""),b(!1),i==="numero"){const L=_.slice(0,T);if(!L){c("error"),d("Informe um número CRECI válido.");return}const g=await ie.validateCreci(r,L);if(h(g),p(g.fonte||""),g.success){c("success"),u.success("Consulta CRECI concluída");return}const P=X(g.reason);c(P),d(g.error||"Falha ao consultar CRECI."),P==="not_found"?u.warning("CRECI não encontrado"):P==="unavailable"?u.warning("Serviço CRECI indisponível no momento"):u.error("Falha na consulta CRECI");return}const l=s.trim();if(!G(l)){c("error"),d("Informe ao menos nome e sobrenome para buscar por nome.");return}const A=r==="SP_STAR"?"SP":r,j=await le(r,l),y=j.results||[];
1if(p(j.fonte||`CRECI-${A}`),f(y),j.success){y.length>0?(c("success"),u.success("Consulta CRECI concluída")):(c("not_found"),d("Nenhum corretor encontrado para o nome informado."),u.warning("CRECI não encontrado"));return}const B=X(j.reason);c(B),d(j.error||"Falha ao consultar CRECI por nome."),B==="unavailable"?u.warning("Serviço CRECI indisponível no momento"):u.error("Falha na consulta CRECI")}catch(l){const A=l instanceof Error?l.message:"Erro inesperado ao consultar CRECI.";c("error"),h(null),f([]),d(A),u.error("Erro ao consultar CRECI")}},Y=t.useMemo(()=>a==="success"?e.jsx(v,{className:"bg-green-600 text-white",children:"Sucesso"}):a==="not_found"?e.jsx(v,{variant:"destructive",children:"Não encontrado"}):a==="unavailable"?e.jsx(v,{variant:"secondary",children:"Indisponível"}):a==="error"?e.jsx(v,{variant:"destructive",children:"Erro"}):null,[a]),q=t.useMemo(()=>a==="success"?e.jsx(K,{className:"w-5 h-5 text-green-600"}):a==="not_found"?e.jsx(D,{className:"w-5 h-5 text-destructive"}):a==="unavailable"?e.jsx(Q,{className:"w-5 h-5 text-yellow-500"}):a==="error"?e.jsx(D,{className:"w-5 h-5 text-destructive"}):null,[a]);return e.jsx(ae,{title:"Consulta CRECI",description:"Consulta manual de CRECI RJ/SP.",children:e.jsxs("div",{className:"grid gap-6",children:[e.jsx(z,{children:e.jsxs(O,{children:[e.jsxs("form",{onSubmit:W,className:"grid gap-4 md:grid-cols-[140px_170px_1fr_auto] md:items-end",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{htmlFor:"creci-uf",children:"UF"}),e.jsxs(J,{value:r,onValueChange:o=>{N(o),x(""),w(""),c("idle"),h(null),f([]),p(""),d("")},disabled:a==="loading",children:[e.jsx(M,{id:"creci-uf",children:e.jsx(U,{})}),e.jsxs(V,{children:[e.jsx(C,{value:"RJ",children:"RJ"}),e.jsx(C,{value:"SP",children:"SP"}),e.jsx(C,{value:"SP_STAR",children:"SP* (completo)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{htmlFor:"creci-tipo-busca",children:"Tipo"}),e.jsxs(J,{value:i,onValueChange:o=>{R(o),c("idle"),h(null),f([]),p(""),d("")},disabled:a==="loading",children:[e.jsx(M,{id:"creci-tipo-busca",children:e.jsx(U,{})}),e.jsxs(V,{children:[e.jsx(C,{value:"numero",children:"Por inscrição"}),e.jsx(C,{value:"nome",children:"Por nome"})]})]})]}),e.jsx("div",{className:"space-y-2",children:i==="numero"?e.jsxs(e.Fragment,{children:[e.jsx(S,{htmlFor:"creci-numero",children:"Número CRECI"}),e.jsx($,{id:"creci-numero",value:m,inputMode:"numeric",autoComplete:"off",placeholder:r==="RJ"?"Ex: 107316":"Ex: 69353",onChange:o=>{const l=k(o.target.value);x(l.slice(0,T))},disabled:a==="loading"})]}):e.jsxs(e.Fragment,{children:[e.jsx(S,{htmlFor:"creci-nome",children:"Nome do corretor"}),e.jsx($,{id:"creci-nome",value:s,autoComplete:"off",placeholder:"Ex: Maria Izabel",onChange:o=>w(o.target.value),disabled:a==="loading"})]})}),e.jsx(Z,{type:"submit",disabled:a==="loading"||(i==="numero"?!_:!G(s)),className:"min-w-36",children:a==="loading"?e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"w-4 h-4 mr-2 animate-spin"}),"Consultando..."]}):e.jsxs(e.Fragment,{children:[e.jsx(se,{className:"w-4 h-4 mr-2"}),"Consultar"]})})]}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:i==="numero"?r==="RJ"?"RJ aceita apenas números (até 6 dígitos).":r==="SP_STAR"?"SP* usa o fluxo completo (Playwright + captcha). Pode demorar até 90 segundos e falhar em produção.":"SP usa o fluxo rápido de certidão pública (sem captcha).":"Busca por nome usa apenas fonte oficial do CRECI e pode ficar indisponível por captcha no portal."}),i==="nome"?e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Informe ao menos nome e sobrenome."}):null,i==="numero"&&r==="SP_STAR"?e.jsx("p",{className:"mt-1 text-xs text-amber-600",children:"Modo experimental para tentar obter dados completos (foto/data de inscrição)."}):null,i==="numero"&&(r==="SP"||r==="SP_STAR")?e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"SP aceita até 6 dígitos."}):null]})}),(a==="success"||a==="error"||a==="unavailable"||a==="not_found")&&e.jsxs(z,{children:[e.jsxs(ne,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[q,e.jsx(oe,{className:"text-lg",children:"Resultado da consulta"}),Y]}
1),F?e.jsx(te,{children:F}):null]}),e.jsx(O,{className:"grid gap-4",children:i==="nome"?a==="success"&&E.length>0?e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:[E.length," resultado(s)",I?` | Fonte: ${I}`:""]}),e.jsx("div",{className:"divide-y rounded-md border",children:E.map((o,l)=>e.jsxs("div",{className:"grid gap-1 px-4 py-3 md:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Nome:"})," ",o.nome||"-"]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Situação:"})," ",o.situacao||"-"]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Tipo:"})," ",o.tipo_pessoa||"-"]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Cidade:"})," ",o.cidade||"-"]})]},`${o.nome}-${l}`))})]}):null:n!=null&&n.success?e.jsxs("div",{className:"grid gap-4 md:grid-cols-[180px_1fr]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Foto"}),n.foto_url&&!H?e.jsx("img",{src:n.foto_url,alt:`Foto de ${n.nome||"corretor"}`,className:"h-56 w-full rounded-md border object-cover",loading:"lazy",onError:()=>b(!0)}):e.jsx("div",{className:"flex h-56 w-full items-center justify-center rounded-md border bg-muted/30 text-sm text-muted-foreground",children:"Foto não disponível"})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Nome:"})," ",n.nome||"-"]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Situação:"})," ",n.situacao||"-"]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Tipo:"})," ",n.tipo_pessoa||"-"]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Cidade:"})," ",n.cidade||"-"]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Inscrição:"})," ",n.inscricao||_]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Fonte:"})," ",n.fonte||I||"-"]}),n.data_inscricao?e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Data inscrição:"})," ",n.data_inscricao]}):null,n.validade_ate?e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Validade certidão:"})," ",n.validade_ate]}):null,n.codigo_autenticidade?e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Código autenticidade:"})," ",n.codigo_autenticidade]}):null]})]}):null})]})]})})}export{ge 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.