1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[62909],{9192:(e,r,s)=>{"use strict";s.d(r,{S:()=>o});var a=s(95155),t=s(12115),n=s(47279),i=s(94514),l=s(40980);let o=t.forwardRef(({className:e,...r},s)=>(0,a.jsx)(n.bL,{ref:s,className:(0,l.cn)("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",e),...r,children:(0,a.jsx)(n.C1,{className:(0,l.cn)("flex items-center justify-center text-current"),children:(0,a.jsx)(i.A,{className:"h-4 w-4"})})}));o.displayName=n.bL.displayName},19865:(e,r,s)=>{"use strict";s.d(r,{IG:()=>d,db:()=>u,j2:()=>c,yA:()=>o});var a=s(97873),t=s(65140),n=s(30928),i=s(4927);let l={apiKey:"AIzaSyAO_sbTBemKD068NVqv3RYb15ckEthjtrQ",authDomain:"login.brasilmineral.com.br",projectId:"brasil-mineral-newsletter",storageBucket:"brasil-mineral-newsletter.firebasestorage.app",messagingSenderId:"145521886346",appId:"1:145521886346:web:bb9afd106c161d05031973",measurementId:"G-QCKC22MY1G"},o=0===(0,a.Dk)().length?(0,a.Wp)(l):(0,a.Sx)(),c=(0,t.xI)(o),d=(0,n.c7)(o),u=(0,i.aU)(o,"premium-us".trim()||"(default)");l.projectId||console.error("Firebase Initialization Error: Firebase config is not fully set. Check your NEXT_PUBLIC_FIREBASE_ environment variables. Firebase features may not work correctly.")},22105:(e,r,s)=>{"use strict";s.r(r),s.d(r,{default:()=>w});var a=s(95155),t=s(12115),n=s(98500),i=s.n(n),l=s(6296),o=s(80723),c=s(91958),d=s(86901),u=s(34220),m=s(50049),f=s(24538),g=s(48375),p=s(89239),h=s(81477),x=s(60529),j=s(45160),b=s(9192);function v(e){return e?[[e.logradouro,e.numero].filter(Boolean).join(", "),[e.municipio,e.uf].filter(Boolean).join("/")].filter(Boolean).join(" \xb7 "):""}function w(){let{user:e,isAdmin:r,isLoading:s}=(0,g.A)(),[n,w]=(0,t.useState)(!0),[N,y]=(0,t.useState)(null),[C,S]=(0,t.useState)(null),[k,A]=(0,t.useState)([]),[E,z]=(0,t.useState)(null),[$,I]=(0,t.useState)(!1),[P,B]=(0,t.useState)(""),[T,M]=(0,t.useState)("rename"),[F,O]=(0,t.useState)(new Set),[R,_]=(0,t.useState)([]),[L,J]=(0,t.useState)({}),[D,Z]=(0,t.useState)({}),V=(0,t.useCallback)(async()=>{if(!e)throw Error("Sem usu\xe1rio");let r=await e.getIdToken();return{Authorization:`Bearer ${r}`,"Content-Type":"application/json"}},[e]),K=(0,t.useCallback)(async()=>{if(e){w(!0),S(null);try{let e=await V(),r=await fetch("/api/admin/mineral/empresas-curtas-enrich",{headers:e}),s=await r.json();if(!r.ok)throw Error(s.error||`Erro ${r.status}`);A(s.rows||[]),z(s.summary||null),I(!!s.focusConfigured)}catch(e){S(e instanceof Error?e.message:String(e))}finally{w(!1)}}},[e,V]);(0,t.useEffect)(()=>{e&&r&&K()},[e,r,K]);let U=(0,t.useMemo)(()=>{let e=k;"rename"===T&&(e=e.filter(e=>e.precisaRename)),"cnpj"===T&&(e=e.filter(e=>e.precisaCnpj)),"completo"===T&&(e=e.filter(e=>"completo"===e.enrichmentStatus));let r=P.trim().toLowerCase();return r&&(e=e.filter(e=>e.nome.toLowerCase().includes(r)||e.slug.includes(r)||(e.cnpj||"").includes(r)||e.razoesAnm.some(e=>e.toLowerCase().includes(r)))),e},[k,T,P]),W=async e=>{y(e?"apply-rename":"suggest"),S(null);try{let r=await V(),s=F.size>0?[...F]:U.slice(0,20).map(e=>e.slug),a=await fetch("/api/admin/mineral/empresas-curtas-enrich",{method:"POST",headers:r,body:JSON.stringify({action:"rename-suggest",slugs:s,onlyProgramatico:"rename"===T,apply:e,limit:s.length})}),t=await a.json();if(!a.ok)throw Error(t.error||`Erro ${a.status}`);_(t.sugestoes||[]),e&&await K()}catch(e){S(e instanceof Error?e.message:String(e))}finally{y(null)}},q=async()=>{if(R.length){y("apply-rename"),S(null);try{let e=await V(),r=await fetch("/api/admin/mineral/empresas-curtas-enrich",{method:"POST",headers:e,body:JSON.stringify({action:"rename-apply",items:R.map(e=>({slug:e.slug,nomeSugerido:L[e.slug]||e.nomeSugerido}))})}),s=await r.json();if(!r.ok)throw Error(s.error||`Erro ${r.status}`);_([]),await K()}catch(e){S(e instanceof Error?e.message:String(e))}finally{y(null)}}},G=async()=>{y("cnpj"),S(null);try{let e=await V(),r=F.size>0?[...F]:U.slice(0,10).map(e=>e.slug),s=r.filter(e=>D[e]).map(e=>({slug:e,cnpj:D[e]})),a=await fetch("/api/admin/mineral/empresas-curtas-enrich",{method:"POST",headers:e,body:JSON.stringify({action:"enrich-cnpj",slugs:r,items:s,limit:r.length,buscarWebsite:!0})}),t=await a.json();if(!a.ok)throw Error(t.error||`Erro ${a.status}`);await K()}catch(e){S(e instanceof Error?e.message:String(e))}finally{y(null)}},Q=async e=>{let r=(L[e]||"").trim();if(r){y(`manual-${e}`);try{let s=await V(),a=await fetch("/api/admin/mineral/empresas-curtas-enrich",{method:"POST",headers:s,body:JSON.stringify({action:"rename-manual",slug:e,nome:r})}),t=await a.json();if(!a.ok)throw Error(t.error||`Erro ${a.status}`);await K()}catch(e){S(e instanceof Error?e.message:String(e))}finally{y(null)}}};return s?(0,a.jsxs)("div",{className:"flex min-h-[40vh] items-center justify-center gap-2 text-muted-foreground",children:[(0,a.jsx)(l.A,{className:"h-5 w-5 animate-spin"})," Carregandoâ¦"]}):e&&r?(0,a.jsxs)("div",{className:"mx-auto max-w-6xl space-y-6 p-4 md:p-8",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsxs)(i(),{href:"/admin/maiores",className:"mb-2 inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",children:[(0,a.jsx)(o.A,{className:"h-3.5 w-3.5"})," Hub Maiores"]}),(0,a.jsx)("h1",{className:"text-2xl font-semibold tracking-tight",children:"Enrich de empresas curtas"}),(0,a.jsxs)("p",{className:"mt-1 max-w-2xl text-sm text-muted-foreground",children:["Corrige nomes curtos com IA (sem S/A\xb7Ltda\xb7minera\xe7\xe3o) e puxa sede/contato via CNPJ (Focus NFe + BrasilAPI). A sede n\xe3o \xe9 a mina â use"," ",(0,a.jsx)(i(),{href:"/admin/mineral-minas",className:"underline",children:"Localizar minas"})," ","(OSM) para o pin."]})]}),(0,a.jsxs)(p.$,{variant:"outline",size:"sm",onClick:()=>void K(),disabled:n,children:[(0,a.jsx)(c.A,{className:`mr-1.5 h-3.5 w-3.5 ${n?"animate-spin":""}`}),"Atualizar"]})]}),E?(0,a.jsx)("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-6",children:[["Total",E.total],["Program\xe1tico",E.nomeProgramatico],["IA",E.nomeAi],["Manual",E.nomeManual],["Com CNPJ",E.comCnpj],["Completo",E.completo]].map(([e,r])=>(0,a.jsx)(h.Zp,{children:(0,a.jsxs)(h.aR,{className:"p-3 pb-1",children:[(0,a.jsx)(h.BT,{children:e}),(0,a.jsx)(h.ZB,{className:"text-xl",children:r})]})},String(e)))}):null,(0,a.jsxs)(h.Zp,{children:[(0,a.jsxs)(h.aR,{className:"pb-3",children:[(0,a.jsx)(h.ZB,{className:"text-base",children:"Batch"}
1),(0,a.jsxs)(h.BT,{children:["Focus NFe:"," ",$?(0,a.jsx)("span",{className:"text-emerald-700",children:"token OK"}):(0,a.jsx)("span",{className:"text-amber-700",children:"sem FOCUSNFE_TOKEN â usa s\xf3 BrasilAPI"})]})]}),(0,a.jsxs)(h.Wu,{className:"flex flex-wrap gap-2",children:[(0,a.jsxs)(p.$,{size:"sm",variant:"secondary",disabled:!!N,onClick:()=>void W(!1),children:["suggest"===N?(0,a.jsx)(l.A,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):(0,a.jsx)(d.A,{className:"mr-1.5 h-3.5 w-3.5"}),"Sugerir nomes (IA)"]}),(0,a.jsxs)(p.$,{size:"sm",disabled:!!N||!R.length,onClick:()=>void q(),children:["apply-rename"===N?(0,a.jsx)(l.A,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):(0,a.jsx)(u.A,{className:"mr-1.5 h-3.5 w-3.5"}),"Aplicar sugest\xf5es"]}),(0,a.jsxs)(p.$,{size:"sm",variant:"outline",disabled:!!N,onClick:()=>void G(),children:["cnpj"===N?(0,a.jsx)(l.A,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):(0,a.jsx)(m.A,{className:"mr-1.5 h-3.5 w-3.5"}),"Enrich CNPJ"]}),(0,a.jsx)(p.$,{size:"sm",variant:"ghost",onClick:()=>{O(new Set(U.slice(0,40).map(e=>e.slug)))},children:"Selecionar vis\xedveis (â¤40)"}),(0,a.jsxs)(p.$,{size:"sm",variant:"ghost",onClick:()=>O(new Set),children:["Limpar sele\xe7\xe3o (",F.size,")"]}),(0,a.jsx)(p.$,{asChild:!0,size:"sm",variant:"ghost",children:(0,a.jsxs)(i(),{href:"/admin/mineral-minas",children:[(0,a.jsx)(f.A,{className:"mr-1.5 h-3.5 w-3.5"}),"Minas (OSM)"]})})]})]}),R.length>0?(0,a.jsxs)(h.Zp,{children:[(0,a.jsxs)(h.aR,{className:"pb-2",children:[(0,a.jsxs)(h.ZB,{className:"text-base",children:["Sugest\xf5es IA (",R.length,")"]}),(0,a.jsx)(h.BT,{children:"Edite antes de aplicar, se quiser."})]}),(0,a.jsx)(h.Wu,{className:"space-y-2",children:R.map(e=>(0,a.jsxs)("div",{className:"grid gap-2 rounded-md border p-2 sm:grid-cols-[1fr_1fr_auto] sm:items-center",children:[(0,a.jsxs)("div",{className:"text-sm",children:[(0,a.jsx)("div",{className:"text-muted-foreground",children:e.nomeAtual}),(0,a.jsx)("div",{className:"truncate text-xs text-muted-foreground",children:e.razaoSocial||e.slug})]}),(0,a.jsx)(x.p,{value:L[e.slug]??e.nomeSugerido,onChange:r=>J(s=>({...s,[e.slug]:r.target.value}))}),(0,a.jsx)(j.E,{variant:"outline",children:null!=e.confianca?`${Math.round(100*e.confianca)}%`:"â"})]},e.slug))})]}):null,(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)(x.p,{placeholder:"Buscar nome, slug, CNPJ, raz\xe3oâ¦",value:P,onChange:e=>B(e.target.value),className:"max-w-sm"}),[["rename","Precisa rename"],["cnpj","Precisa CNPJ"],["completo","Completos"],["all","Todas"]].map(([e,r])=>(0,a.jsx)(p.$,{size:"sm",variant:T===e?"default":"outline",onClick:()=>M(e),children:r},e))]}),C?(0,a.jsx)("p",{className:"rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800",children:C}):null,n?(0,a.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,a.jsx)(l.A,{className:"h-4 w-4 animate-spin"})," Carregando empresasâ¦"]}):(0,a.jsxs)("div",{className:"space-y-2",children:[U.map(e=>(0,a.jsx)("div",{className:"rounded-lg border bg-card p-3 shadow-sm",children:(0,a.jsxs)("div",{className:"flex flex-wrap items-start gap-3",children:[(0,a.jsx)(b.S,{checked:F.has(e.slug),onCheckedChange:()=>{var r;return r=e.slug,void O(e=>{let s=new Set(e);return s.has(r)?s.delete(r):s.add(r),s})},className:"mt-1"}),(0,a.jsxs)("div",{className:"min-w-0 flex-1 space-y-2",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)("span",{className:"font-medium",children:e.nome}),(0,a.jsx)(j.E,{variant:"secondary",children:e.nomeCurtoFonte||"programatico"}),e.enrichmentStatus?(0,a.jsx)(j.E,{variant:"outline",children:e.enrichmentStatus}):null]}),e.razoesAnm[0]?(0,a.jsxs)("p",{className:"truncate text-xs text-muted-foreground",children:["ANM: ",e.razoesAnm[0],e.razoesAnm.length>1?` (+${e.razoesAnm.length-1})`:""]}):null,(0,a.jsxs)("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-4",children:[(0,a.jsx)(x.p,{placeholder:"Novo nome curto",value:L[e.slug]??"",onChange:r=>J(s=>({...s,[e.slug]:r.target.value}))}),(0,a.jsx)(x.p,{placeholder:"CNPJ (14 d\xedgitos)",value:D[e.slug]??e.cnpj??"",onChange:r=>Z(s=>({...s,[e.slug]:r.target.value}))}),(0,a.jsx)(p.$,{size:"sm",variant:"outline",disabled:!!N||!(L[e.slug]||"").trim(),onClick:()=>void Q(e.slug),children:"Salvar nome"}),(0,a.jsxs)("div",{className:"text-xs text-muted-foreground",children:[e.website?(0,a.jsx)("a",{href:e.website,target:"_blank",rel:"noreferrer",className:"underline",children:e.website}):"sem site",e.telefone?` \xb7 ${e.telefone}`:"",v(e.endereco)?(0,a.jsxs)("div",{className:"mt-0.5",children:["Sede: ",v(e.endereco)]}):null]})]})]})]})},e.slug)),U.length?null:(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Nenhuma empresa neste filtro."})]})]}):(0,a.jsxs)("div",{className:"mx-auto max-w-lg p-8 text-center",children:[(0,a.jsx)("p",{className:"text-muted-foreground",children:"Acesso restrito a administradores."}),(0,a.jsx)(p.$,{asChild:!0,className:"mt-4",variant:"outline",children:(0,a.jsx)(i(),{href:"/admin",children:"Voltar"})})]})}},40980:(e,r,s)=>{"use strict";s.d(r,{Y:()=>i,cn:()=>n,o:()=>l});var a=s(29722),t=s(622);function n(...e){return(0,t.QP)((0,a.$)(e))}function i(e){return e?e.toString().toLowerCase().trim().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[\s_]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+/,"").replace(/-+$/,""):`artigo-sem-titulo-${Date.now()}`}function l(e){return e&&"string"==typeof e?e.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^a-z0-9]/g,""):""}},45160:(e,r,s)=>{"use strict";s.d(r,{E:()=>l});var a=s(95155);s(12115);var t=s(18460),n=s(40980);let i=(0,t.F)("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function l({className:e,variant:r,...s}){return(0,a.jsx)("span",{className:(0,n.cn)(i({variant:r}),e),...s})}},48375:(e,r,s)=>{"use strict";s.d(r,{A:()=>c,O:()=>o});var a=s(95155),t=s(12115),n=s(65140),i=s(19865);let l=(0,t.createContext)(void 0);function o({children:e}){let[r,s]=(0,t.useState)(null),[c,d]=(0,t.useState)(null),[u,m]=(0,t.useState)(null),[f,g]=(0,t.useState)(null),[p,h]=(0,t.useState)(!0),[x,j]=(0,t.useState)(!1);(0,t.useEffect)(()=>{let e,r=!1,a=()=>{r||(e=(0,n.hg)(i.j2,async e=>{if(s(e),j(!!e?.emailVerified),e)try{let r=await e.getIdToken(),s=await fetch("/api/auth/me",{headers:{Authorization:`Bearer ${r}`}}),a=s.ok?await s.json():null;d(a?.user??null),m(a?.profile??null),g(a?.access??null)}catch(e){console.error("[AuthContext] Failed to fetch user data:",e),d(null),m(null),g(null)}else d(null),m(null),g(null);h(!1)}))},t="function"==typeof window.requestIdleCallback?window.requestIdleCallback(a,{timeout:2e3}):window.setTimeout(a,0);return()=>{r=!0,"function"==typeof window.cancelIdleCallback?window.cancelIdleCallback(t):window.clearTimeout(t),e?.()}},[]);let b=(0,t.useMemo)(()=>f?.isAdmin??c?.role==="admin",[f,c]),v=(0,t.useMemo)(()=>f?.isEditor??(c?.role==="admin"||c?.role==="editor"),[f,c]),w=(0,t.useMemo)(()=>f?.dashboardPermissions??c?.dashboardPermissions??[],[f,c]),N=(0,t.useMemo)(()=>e=>b||w.includes(e),[b,w]),y=(0,t.useMemo)(()=>!!r,[r]),C=(0,t.useMemo)(()=>u?.accountType==="premium",[u]),S=(0,t.useMemo)(()=>!!u?.isAdvertiser,[u]),k=async()=>{await i.j2.currentUser?.reload(),j(!!i.j2.currentUser?.emailVerified)},A=(0,t.useMemo)(()=>({user:r,appUser:c,userProfile:u,isLoading:p,isAdmin:b,isEditor:v,dashboardPermissions:w,hasFeature:N,isAuthenticated:y,isPremium:C,isAdvertiser:S,emailVerified:x,refreshEmailVerified:k}),[r,c,u,p,b,v,w,N,y,C,S,x]);return(0,a.jsx)(l.Provider,{value:A,children:e})}function c(){let e=(0,t.useContext)(l);if(void 0===e)throw Error("useAuth must be used within an AuthProvider");return e}},60529:(e,r,s)=>{"use strict";s.d(r,{p:()=>i});var a=s(95155),t=s(12115),n=s(40980);let i=t.forwardRef(({className:e,type:r,...s},t)=>(0,a.jsx)("input",{type:r,className:(0,n.cn)("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:t,...s}));i.displayName="Input"},60927:(e,r,s)=>{Promise.resolve().then(s.bind(s,22105))},81477:(e,r,s)=>{"use strict";s.d(r,{BT:()=>c,Wu:()=>d,ZB:()=>o,Zp:()=>i,aR:()=>l});var a=s(95155),t=s(12115),n=s(40980);let i=t.forwardRef(({className:e,...r},s)=>(0,a.jsx)("div",{ref:s,className:(0,n.cn)("rounded-lg border bg-card text-card-foreground shadow-sm",e),...r}));
1i.displayName="Card";let l=t.forwardRef(({className:e,...r},s)=>(0,a.jsx)("div",{ref:s,className:(0,n.cn)("flex flex-col space-y-1.5 p-6",e),...r}));l.displayName="CardHeader";let o=t.forwardRef(({className:e,...r},s)=>(0,a.jsx)("div",{ref:s,className:(0,n.cn)("text-2xl font-semibold leading-none tracking-tight",e),...r}));o.displayName="CardTitle";let c=t.forwardRef(({className:e,...r},s)=>(0,a.jsx)("div",{ref:s,className:(0,n.cn)("text-sm text-muted-foreground",e),...r}));c.displayName="CardDescription";let d=t.forwardRef(({className:e,...r},s)=>(0,a.jsx)("div",{ref:s,className:(0,n.cn)("p-6 pt-0",e),...r}));d.displayName="CardContent",t.forwardRef(({className:e,...r},s)=>(0,a.jsx)("div",{ref:s,className:(0,n.cn)("flex items-center p-6 pt-0",e),...r})).displayName="CardFooter"},89239:(e,r,s)=>{"use strict";s.d(r,{$:()=>c,r:()=>o});var a=s(95155),t=s(12115),n=s(42442),i=s(18460),l=s(40980);let o=(0,i.F)("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),c=t.forwardRef(({className:e,variant:r,size:s,asChild:t=!1,...i},c)=>{let d=t?n.DX:"button";return(0,a.jsx)(d,{className:(0,l.cn)(o({variant:r,size:s,className:e})),ref:c,...i})});c.displayName="Button"}},e=>{e.O(0,[62992,47416,18409,49304,16511,98500,65345,28441,93794,77358],()=>e(e.s=60927)),_N_E=e.O()}]);
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.