PageSourceSearch

https://freelacerto.com/assets/AdminEmpresaDetalhe-CQ0e_zMH.js

js freelacerto.com collected 2026-09-24 14:44:23 UTC 62,306 bytes, 1 lines download raw bytes

1import{u as ta,j as e,S as W,b as oe}from"./index--siChAZm.js";import{h as oa,u as Je,r as m}from"./react-vendor-B-clOVnp.js";import{I as ze}from"./TableSkeleton-vC9bujE_.js";import{I as sa}from"./ImageLightbox-Br-jnYUy.js";import{A as na,a as ra,b as ia,c as la,d as ca}from"./AdminTablePrimitives-CdK-C44a.js";import{a as da,b as xa,c as pa,d as G,e as ha,f as ma,g as K,h as fa}from"./AdminTableStyles-DDy66SUD.js";import{V as De,R as ue,al as ga,a as Ce,ap as ua,k as ja,b9 as ba,T as Xe,J as Ye,g as Le,a9 as Ne,aa as we,cf as ya,M as va,b8 as Oe,p as Sa,t as za,_ as Qe,am as de,b0 as Ze,aP as Ge,bh as Ca,a8 as wa,L as je,D as Ea,bQ as ka,O as Aa,aw as Ta}from"./icons-BCLA8W0j.js";const w="#031D44",ce="#00C4D4",D=a=>a?new Date(a).toLocaleDateString("pt-BR",{day:"2-digit",month:"short",year:"numeric"}):"—",_e=a=>a?new Date(a).toLocaleString("pt-BR",{day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}):"—",ne=a=>a==null?"—":Number(a).toLocaleString("pt-BR",{style:"currency",currency:"BRL"});function Ue(a){if(!a?.eventoId)return null;const t=encodeURIComponent(String(a.eventoId));return a.eventoTipo==="escala"?`/escalas/${t}`:`/admin/contratacoes-avulsas/${t}`}function nt(){const{bubbleId:a}=oa(),t=Je(),{token:s}=ta(),[d,c]=m.useState(!0),[p,y]=m.useState(""),[x,z]=m.useState(null),[b,C]=m.useState(!1),[k,P]=m.useState(null),[H,O]=m.useState(!1),[N,X]=m.useState(!1),[U,V]=m.useState(!1),[o,n]=m.useState("resumo"),[h,S]=m.useState(null),[R,Y]=m.useState(!1),[M,I]=m.useState({});async function T(){c(!0),y("");try{const l=await fetch(`/api/admin/empresas/${a}/full`,{headers:{Authorization:`Bearer ${s}`,"x-bubble-version":localStorage.getItem("bubble_version")||"live"}}),E=await l.json();if(!l.ok)throw new Error(E.error||"Erro ao carregar");z(E);const f=E.empresa||{},$=E.endereco,Z=$&&Object.values($).some(fe=>fe&&typeof fe=="string"&&fe.trim())?$:f.endereco||{};I({nomeDaEmpresa:f.nomeDaEmpresa||"",razaoSocial:f.razaoSocial||"",cnpj:f.cnpj||"",email:f.email||"",telefone:f.telefone||"",emailUsuarioPrincipal:E.principal?.email||"",endereco:{cep:Z.cep||"",logradouro:Z.logradouro||"",numero:Z.numero||"",complemento:Z.complemento||"",bairro:Z.bairro||"",cidade:Z.cidade||"",estado:Z.estado||""}})}catch(l){y(l.message)}finally{c(!1)}}m.useEffect(()=>{T()},[a]);async function r(){O(!0);try{const l=await fetch("/api/admin/run-as",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`,"x-bubble-version":localStorage.getItem("bubble_version")||"live"},body:JSON.stringify({tipo:"empresa",bubbleId:a})}),E=await l.json();if(!l.ok)throw new Error(E.error||"Não foi possível acessar como esta empresa");const f=`/run-as?c=${encodeURIComponent(E.code)}&v=${encodeURIComponent(E.version||"live")}`,$=window.screen.width||1280,$e=window.screen.height||860;window.open(f,"_blank",`noopener,width=${Math.min($,1280)},height=${Math.min($e,860)},resizable=yes,scrollbars=yes`)}catch(l){alert(l.message)}finally{O(!1)}}async function i(){const l=x?.empresa?.nomeDaEmpresa||a;if(await oe({titulo:"Reativar conta",mensagem:`Isso vai limpar o soft-delete de ${l} e permitir que o usuário principal acesse o app novamente.`,textoConfirmar:"Reativar conta",textoCancelar:"Cancelar"})){V(!0);try{const f=await fetch(`/api/admin/empresas/${a}/reativar-conta`,{method:"POST",headers:{Authorization:`Bearer ${s}`,"x-bubble-version":localStorage.getItem("bubble_version")||"live"}}),$=await f.json();if(!f.ok)throw new Error($.error||"Erro ao reativar conta");await T()}catch(f){alert(f.message)}finally{V(!1)}}}async function A(){const l=x?.empresa?.nomeDaEmpresa||x?.empresa?.bubbleId||a;if(await oe({titulo:"Excluir conta permanentemente",mensagem:`Esta ação vai remover ${l} e todos os dados relacionados (perfil, plano, colaboradores, vagas, saldo, eventos, etc.) do banco de dados. Esta operação é irreversível.`,textoConfirmar:"Excluir permanentemente",textoCancelar:"Cancelar",perigoso:!0,checkboxLabel:"Estou ciente que esta ação não pode ser desfeita"})){X(!0);try{const f=await fetch(`/api/admin/empresas/${a}`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`,"x-bubble-version":localStorage.getItem("bubble_version")||"live"}}),$=await f.json();if(!f.ok)throw new Error($.error||"Erro ao excluir conta");t("/admin/empresas")}catch(f){alert(f.message),X(!1)}}}async function v(){C(!0);try{const l={empresa:{nomeDaEmpresa:M.nomeDaEmpresa,razaoSocial:M.razaoSocial,cnpj:M.cnpj,email:M.email,telefone:M.telefone},endereco:M.endereco,usuario:{email:M.emailUsuarioPrincipal}},E=await fetch(`/api/admin/empresas/${a}/full`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`,"x-bubble-version":localStorage.getItem("bubble_version")||"live"},body:JSON.stringify(l)}),f=await E.json();if(!E.ok)throw new Error(f.error||"Erro ao salvar");Y(!1),await T()}catch(l){alert(l.message)}finally{C(!1)}}async function Q(l){C(!0),P(l);try{const E=!x.empresa?.[l],f=await fetch(`/api/admin/empresas/${a}/full`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`,"x-bubble-version":localStorage.getItem("bubble_version")||"live"},body:JSON.stringify({empresa:{[l]:E}})}),$=await f.json();if(!f.ok)throw new Error($.error||"Erro");await T()}catch(E){alert(E.message)}finally{C(!1),P(null)}}async function pe(l,E){C(!0),P(l);try{const f=await fetch(`/api/admin/empresas/${a}/full`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`,"x-bubble-version":localStorage.getItem("bubble_version")||"live"},body:JSON.stringify({usuario:{[l]:!!E}})}),$=await f.json();if(!f.ok)throw new Error($.error||"Erro");await T()}catch(f){alert(f.message)}finally{C(!1),P(null)}}const Ke=l=>pe("acessoTests",l),ea=l=>pe("acessoEscalas",l);async function ke(l){if(await oe(l?"Bloquear esta empresa? Ela NÃO conseguirá publicar vagas até ser desbloqueada.":"Desbloquear esta empresa? Ela voltará a poder publicar vagas.")){C(!0),P("bloqueada");try{const f=await fetch(`/api/admin/empresas/${a}/full`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`,"x-bubble-version":localStorage.getItem("bubble_version")||"live"},body:JSON.stringify({empresa:{bloqueada:l}})}
1),$=await f.json();if(!f.ok)throw new Error($.error||"Erro");await T()}catch(f){alert(f.message)}finally{C(!1),P(null)}}}if(d)return e.jsx("div",{style:{padding:24},children:e.jsx(ze,{texto:"Carregando empresa…"})});if(p)return e.jsxs("div",{style:{padding:24},children:[e.jsxs("button",{onClick:()=>t(-1),style:Me,children:[e.jsx(De,{size:14})," Voltar"]}),e.jsxs("div",{style:{marginTop:12,padding:14,background:"#fef2f2",border:"1.5px solid #fca5a5",borderRadius:12,color:"#b91c1c"},children:["Erro: ",p]})]});if(!x)return null;const{empresa:B,principal:ee,endereco:Za,colaboradores:Ae,vagasClt:Te,avaliacoesRecebidas:Be,avaliacoesFeitas:Ie,eventos:Re,escalas:Fe,tickets:Pe,estatisticas:he,pushes:We=[],pushConfig:aa=null}=x,me=(()=>{const l=B.logotipo;return l?typeof l=="string"?l.startsWith("//")?`https:${l}`:l:typeof l=="object"&&l.gridFsId?`/api/imagens/${l.gridFsId}`:"":""})();return e.jsxs("div",{style:{padding:16,maxWidth:1200,margin:"0 auto"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:16,flexWrap:"wrap"},children:[e.jsxs("button",{onClick:()=>t("/admin/empresas"),style:Me,children:[e.jsx(De,{size:14})," Lista"]}),e.jsx("button",{onClick:T,style:ae,disabled:b||d,children:d?e.jsxs(e.Fragment,{children:[e.jsx(W,{size:14})," Carregando…"]}):e.jsxs(e.Fragment,{children:[e.jsx(ue,{size:14})," Recarregar"]})}),e.jsx("button",{onClick:r,style:ae,disabled:H,title:"Abrir o app como esta empresa (nova aba)",children:H?e.jsxs(e.Fragment,{children:[e.jsx(W,{size:14})," Abrindo…"]}):e.jsxs(e.Fragment,{children:[e.jsx(ga,{size:14})," Acessar como"]})}),e.jsx("div",{style:{flex:1}}),ee?.contaExcluida&&e.jsx("button",{onClick:i,disabled:U||b,style:{...ve,fontSize:13},children:U?e.jsxs(e.Fragment,{children:[e.jsx(W,{size:14})," Reativando…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ce,{size:14})," Reativar conta"]})}),e.jsx("button",{onClick:A,disabled:N||b,style:{...Se,fontSize:13},children:N?e.jsxs(e.Fragment,{children:[e.jsx(W,{size:14})," Excluindo…"]}):e.jsxs(e.Fragment,{children:[e.jsx(ua,{size:14})," Excluir conta"]})}),B.bloqueada?e.jsx("button",{onClick:()=>ke(!1),disabled:b,style:ve,children:k==="bloqueada"?e.jsxs(e.Fragment,{children:[e.jsx(W,{size:14})," Desbloqueando…"]}):e.jsxs(e.Fragment,{children:[e.jsx(ja,{size:14})," Desbloquear"]})}):e.jsx("button",{onClick:()=>ke(!0),disabled:b,style:Se,children:k==="bloqueada"?e.jsxs(e.Fragment,{children:[e.jsx(W,{size:14})," Bloqueando…"]}):e.jsxs(e.Fragment,{children:[e.jsx(ba,{size:14})," Bloquear"]})})]}),ee?.contaExcluida&&e.jsxs("div",{style:{background:"#fef2f2",border:"1px solid #fca5a5",borderRadius:8,padding:"10px 14px",marginBottom:14,display:"flex",alignItems:"center",gap:10},children:[e.jsx(Xe,{size:16,color:"#dc2626"}),e.jsxs("span",{style:{fontSize:13,color:"#991b1b",fontWeight:600},children:["Esta conta está marcada como excluída (soft-delete) — o usuário principal não consegue acessar o app nem ser impersonado. Use o botão ",e.jsx("strong",{children:"Reativar conta"})," acima para restaurar o acesso."]})]}),e.jsxs("div",{style:F,children:[e.jsxs("div",{style:{display:"flex",gap:16,alignItems:"center",flexWrap:"wrap"},children:[me?e.jsx("button",{type:"button",onClick:()=>S({url:me,titulo:`Logotipo — ${B.nomeDaEmpresa||"empresa"}`}),title:"Ampliar logotipo",style:{padding:0,background:"transparent",border:"none",cursor:"zoom-in"},children:e.jsx("img",{src:me,alt:B.nomeDaEmpresa||"",style:{width:88,height:88,borderRadius:12,objectFit:"cover",border:"2px solid #e5e7eb",background:"#f9fafb",display:"block"}})}):e.jsx("div",{style:{width:88,height:88,borderRadius:12,background:"#f3f4f6",display:"flex",alignItems:"center",justifyContent:"center",color:"#9ca3af"},children:e.jsx(Ye,{size:32})}),e.jsxs("div",{style:{flex:1,minWidth:240},children:[e.jsx("h2",{style:{margin:0,color:w},children:B.nomeDaEmpresa||"(sem nome)"}),B.razaoSocial&&e.jsx("div",{style:{fontSize:13,color:"#6b7280",marginTop:2},children:B.razaoSocial}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:8},children:[B.premium&&e.jsx(q,{cor:"#7c3aed",icon:e.jsx(Le,{size:10}),children:"Premium"}),B.escala&&e.jsx(q,{cor:ce,txtCor:w,children:"Escala"}),B.empresaFake&&e.jsx(q,{cor:"#9ca3af",icon:e.jsx(Ne,{size:10}),children:"Teste"}),he.notaMediaRecebida!=null&&e.jsxs(q,{cor:"#fbbf24",txtCor:w,icon:e.jsx(we,{size:10}),children:[he.notaMediaRecebida.toFixed(2)," (",he.totalAvaliacoesRecebidas,")"]}
1),(B.ramos||[]).map(l=>e.jsx(q,{cor:"#eef2ff",txtCor:"#3730a3",children:l},l))]}),e.jsxs("div",{style:{fontSize:12,color:"#6b7280",marginTop:8},children:[e.jsx("strong",{children:"bubbleId:"})," ",B.bubbleId,"  · ",e.jsx("strong",{children:"userPrincipal:"})," ",B.userPrincipalBubbleId||"—"]})]})]}),e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",marginTop:14,paddingTop:14,borderTop:"1px solid #e5e7eb"},children:[e.jsx("button",{onClick:()=>Q("premium"),disabled:b,style:B.premium?se:ge,children:k==="premium"?e.jsxs(e.Fragment,{children:[e.jsx(W,{size:12})," Salvando…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Le,{size:12})," ",B.premium?"Remover Premium":"Marcar Premium"]})}),e.jsx("button",{onClick:()=>Q("escala"),disabled:b,style:B.escala?se:ge,children:k==="escala"?e.jsxs(e.Fragment,{children:[e.jsx(W,{size:12})," Salvando…"]}):B.escala?"Desativar Escala":"Ativar Escala"}),e.jsx("button",{onClick:()=>Q("empresaFake"),disabled:b,style:B.empresaFake?ge:se,children:k==="empresaFake"?e.jsxs(e.Fragment,{children:[e.jsx(W,{size:12})," Salvando…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ne,{size:12})," ",B.empresaFake?"Marcar como REAL":"Marcar como TESTE"]})})]}),e.jsx("div",{style:{marginTop:12,paddingTop:12,borderTop:"1px solid #e5e7eb"},children:e.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:8,cursor:b?"default":"pointer",fontSize:14,color:w},children:[e.jsx("input",{type:"checkbox",checked:!!ee?.acessoTests,disabled:b,onChange:l=>Ke(l.target.checked)}),e.jsx("span",{children:"Acesso à página tests"}),k==="acessoTests"&&e.jsx(W,{size:12})]})}),e.jsx("div",{style:{marginTop:8},children:e.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:8,cursor:b?"default":"pointer",fontSize:14,color:w},children:[e.jsx("input",{type:"checkbox",checked:!!ee?.acessoEscalas,disabled:b,onChange:l=>ea(l.target.checked)}),e.jsx("span",{children:"Acesso ao módulo de escalas"}),k==="acessoEscalas"&&e.jsx(W,{size:12})]})}),e.jsxs("div",{style:{marginTop:8},children:[e.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:8,cursor:b?"default":"pointer",fontSize:14,color:w},children:[e.jsx("input",{type:"checkbox",checked:!!ee?.tagAdmin,disabled:b,onChange:l=>pe("tagAdmin",l.target.checked)}),e.jsx("span",{children:"Tag de acompanhamento"}),k==="tagAdmin"&&e.jsx(W,{size:12})]}),e.jsx("div",{style:{fontSize:11,color:"#9ca3af",marginTop:2,marginLeft:24},children:"Silenciosa — invisível para o contratante"})]})]}),e.jsx("div",{style:{display:"flex",gap:4,marginTop:16,overflowX:"auto",borderBottom:"2px solid #e5e7eb"},children:[["resumo","Resumo"],["dados","Dados"],["colaboradores",`Colaboradores (${Ae.length})`],["vagas",`Vagas CLT (${Te.length})`],["eventos",`Eventos (${Re.length})`],["escalas",`Escalas (${Fe.length})`],["avaliacoes",`Avaliações (${Be.length+Ie.length})`],["tickets",`Suporte (${Pe.length})`],["pushes",`Pushs (${We.length})`],["emails","Emails"],["boletos","Boletos"],["plano","Plano"]].map(([l,E])=>e.jsx("button",{onClick:()=>n(l),style:{padding:"10px 14px",border:"none",background:"transparent",fontWeight:o===l?700:500,color:o===l?w:"#6b7280",borderBottom:o===l?`3px solid ${ce}`:"3px solid transparent",cursor:"pointer",whiteSpace:"nowrap",fontSize:13},children:E},l))}),e.jsxs("div",{style:{marginTop:16},children:[o==="resumo"&&e.jsx(Ia,{dados:x,token:s,bubbleId:a,onRecarregar:T}),o==="dados"&&e.jsx(Ra,{form:M,setForm:I,editando:R,setEditando:Y,salvar:v,salvando:b,principal:ee}),o==="colaboradores"&&e.jsx(Fa,{colaboradores:Ae}),o==="vagas"&&e.jsx(Pa,{vagas:Te}),o==="eventos"&&e.jsx(Wa,{eventos:Re}),o==="escalas"&&e.jsx($a,{escalas:Fe}),o==="avaliacoes"&&e.jsx(Da,{recebidas:Be,feitas:Ie}),o==="tickets"&&e.jsx(Oa,{tickets:Pe}),o==="pushes"&&e.jsx(na,{pushes:We,pushConfig:aa}),o==="emails"&&e.jsx(ra,{freelancerBubbleId:a,userBubbleId:x?.empresa?.userPrincipalBubbleId,email:x?.empresa?.email||x?.principal?.email,token:s}),o==="boletos"&&e.jsx(Qa,{empresaId:a,token:s}),o==="plano"&&e.jsx(Ja,{empresaId:a,token:s})]}),h&&e.jsx(sa,{url:h.url,titulo:h.titulo,onClose:()=>S(null)})]})}const Ve=a=>
1(typeof a=="number"?a:0).toLocaleString("pt-BR",{style:"currency",currency:"BRL"});function Ba({aberto:a,onFechar:t,onConfirmar:s,enviando:d,erro:c}){const[p,y]=m.useState({tipo:"credito",valor:"",descricao:""});return a?e.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.45)",zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsxs("div",{style:{background:"#fff",borderRadius:14,padding:28,width:"100%",maxWidth:400,boxShadow:"0 8px 32px rgba(0,0,0,0.18)"},children:[e.jsx("div",{style:{fontWeight:700,fontSize:16,color:"#031D44",marginBottom:18},children:"Ajustar saldo"}),e.jsx("div",{style:{display:"flex",gap:8,marginBottom:16},children:[["credito","+ Crédito","#16a34a","#dcfce7"],["debito","− Débito","#dc2626","#fee2e2"]].map(([x,z,b,C])=>e.jsx("button",{onClick:()=>y(k=>({...k,tipo:x})),style:{flex:1,padding:"8px 0",borderRadius:8,border:`2px solid ${p.tipo===x?b:"#e5e7eb"}`,background:p.tipo===x?C:"#f9fafb",color:p.tipo===x?b:"#6b7280",fontWeight:700,fontSize:13,cursor:"pointer"},children:z},x))}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("label",{style:{fontSize:12,fontWeight:600,color:"#374151",display:"block",marginBottom:4},children:"Valor (R$)"}),e.jsx("input",{type:"number",min:"0.01",step:"0.01",placeholder:"0,00",value:p.valor,onChange:x=>y(z=>({...z,valor:x.target.value})),style:{width:"100%",boxSizing:"border-box",padding:"8px 10px",borderRadius:8,border:"1.5px solid #e5e7eb",fontSize:14}})]}),e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("label",{style:{fontSize:12,fontWeight:600,color:"#374151",display:"block",marginBottom:4},children:"Descrição (opcional)"}),e.jsx("input",{type:"text",placeholder:"Motivo do ajuste...",value:p.descricao,onChange:x=>y(z=>({...z,descricao:x.target.value})),style:{width:"100%",boxSizing:"border-box",padding:"8px 10px",borderRadius:8,border:"1.5px solid #e5e7eb",fontSize:14}})]}),c&&e.jsx("div",{style:{color:"#dc2626",fontSize:12,marginBottom:12,background:"#fee2e2",padding:"8px 12px",borderRadius:8},children:c}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx("button",{onClick:t,disabled:d,style:{padding:"8px 18px",borderRadius:8,border:"1.5px solid #e5e7eb",background:"#fff",color:"#374151",fontSize:13,cursor:"pointer",fontWeight:600},children:"Cancelar"}),e.jsx("button",{onClick:()=>s(p),disabled:d||!p.valor,style:{padding:"8px 18px",borderRadius:8,border:"none",background:p.tipo==="credito"?"#16a34a":"#dc2626",color:"#fff",fontSize:13,fontWeight:700,cursor:d||!p.valor?"not-allowed":"pointer",opacity:d||!p.valor?.7:1,display:"flex",alignItems:"center",gap:6},children:d?e.jsxs(e.Fragment,{children:[e.jsx(je,{size:13,className:"animate-spin"})," Salvando…"]}):"Confirmar"})]})]})}):null}function Ia({dados:a,token:t,bubbleId:s,onRecarregar:d}){const{empresa:c,principal:p,endereco:y,estatisticas:x,saldoPlataforma:z}=a,[b,C]=m.useState(!1),[k,P]=m.useState(!1),[H,O]=m.useState(""),[N,X]=m.useState([]),[U,V]=m.useState({entradas:0,saidas:0}),[o,n]=m.useState(!1),[h,S]=m.useState(""),R=m.useCallback(async()=>{if(s){n(!0),S("");try{const i=await fetch(`/api/admin/empresas/${s}/extrato`,{headers:{Authorization:`Bearer ${t}`,"x-bubble-version":localStorage.getItem("bubble_version")||"live"}}),A=await i.json();if(!i.ok)throw new Error(A.error||"Erro ao carregar extrato");X(A.registros||[]),V(A.totais||{entradas:0,saidas:0})}catch(i){X([]),V({entradas:0,saidas:0}),S(i.message||"Erro ao carregar extrato")}finally{n(!1)}}},[t,s]);m.useEffect(()=>{R()},[R]);async function Y(i){O(""),P(!0);try{const A=globalThis.crypto?.randomUUID?.()||`${Date.now()}-${Math.random().toString(36).slice(2)}`,v=await fetch(`/api/admin/empresas/${s}/saldo-ajuste`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,"x-bubble-version":localStorage.getItem("bubble_version")||"live"},body:JSON.stringify({...i,requestId:A})}),Q=await v.json().catch(()=>({}));if(!v.ok){O(Q.error||"Erro ao ajustar saldo");return}C(!1),O(""),await Promise.all([d(),R()])}catch(A){O(A.message||"Erro de conexão ao ajustar saldo")}
1finally{P(!1)}}const I=y&&Object.values(y).some(i=>i&&typeof i=="string"&&i.trim())?y:c.endereco||{},T=[[I.logradouro,I.numero].filter(Boolean).join(", "),I.bairro,[I.cidade,I.estado].filter(Boolean).join("/")].filter(Boolean).join(" — ")||"—",r=i=>Number(i||0).toLocaleString("pt-BR",{style:"currency",currency:"BRL"});return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsxs("div",{style:{display:"grid",gap:16,gridTemplateColumns:"repeat(auto-fit, minmax(260px, 1fr))"},children:[e.jsxs("div",{style:F,children:[e.jsx(L,{children:"Identificação"}),e.jsx(j,{label:"Razão social",valor:c.razaoSocial||"—",icon:e.jsx(Ye,{size:12})}),e.jsx(j,{label:"CNPJ",valor:c.cnpj||"—",icon:e.jsx(ya,{size:12})}),e.jsx(j,{label:"E-mail",valor:e.jsxs(e.Fragment,{children:[c.email||"—",!p?.temSenha&&c.email&&e.jsxs(e.Fragment,{children:[" ",e.jsx(be,{})]})]}),icon:e.jsx(va,{size:12})}),e.jsx(j,{label:"Telefone",valor:c.telefone||"—",icon:e.jsx(Oe,{size:12})})]}),e.jsxs("div",{style:F,children:[e.jsx(L,{children:"Endereço"}),e.jsx(j,{label:"Logradouro",valor:`${I.logradouro||""} ${I.numero||""}`.trim()||"—"}),e.jsx(j,{label:"Bairro",valor:I.bairro||"—"}),e.jsx(j,{label:"Cidade/UF",valor:`${I.cidade||""}/${I.estado||""}`}),e.jsx(j,{label:"CEP",valor:I.cep||"—"}),T!=="—"&&e.jsx("div",{style:{marginTop:8},children:e.jsxs("a",{href:`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(T)}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",gap:6,padding:"6px 10px",borderRadius:6,fontSize:12,fontWeight:600,background:ce,color:w,textDecoration:"none"},children:[e.jsx(Sa,{size:12})," Ver no mapa"]})})]}),e.jsxs("div",{style:F,children:[e.jsx(L,{children:"Conta"}),e.jsx(j,{label:"Cadastrada em",valor:D(c.bubbleCreatedAt)}),e.jsx(j,{label:"Atualizada em",valor:D(c.bubbleModifiedAt)}),z&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginTop:10,display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:11,fontWeight:700,color:"#6b7280",textTransform:"uppercase"},children:"Saldo"}),e.jsx("button",{onClick:()=>C(!0),style:{fontSize:11,color:"#2563eb",background:"none",border:"none",cursor:"pointer",padding:0,fontWeight:600,textDecoration:"underline"},children:"Ajustar"})]}),e.jsx(j,{label:"Disponível",valor:e.jsx("span",{style:{color:z.saldo>0?"#16a34a":void 0,fontWeight:700},children:Ve(z.saldo)})}),z.saldoBloqueado>0&&e.jsx(j,{label:"Retido (escala)",valor:e.jsx("span",{style:{color:"#d97706",fontWeight:600},children:Ve(z.saldoBloqueado)})})]}),e.jsx(Ba,{aberto:b,onFechar:()=>{C(!1),O("")},onConfirmar:Y,enviando:k,erro:H}),p&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{marginTop:10,fontSize:11,fontWeight:700,color:"#6b7280",textTransform:"uppercase"},children:"Usuário principal"}),e.jsx(j,{label:"Nome",valor:p.primeiroNome||p.nome||"—"}),e.jsx(j,{label:"E-mail",valor:e.jsxs(e.Fragment,{children:[p.email||"—",!p.temSenha&&p.email&&e.jsxs(e.Fragment,{children:[" ",e.jsx(be,{})]})]})}),e.jsx(j,{label:"Telefone",valor:p.telefone||p.telefoneEnvios||p.telefoneVisualizacao||p.phone||"—",icon:e.jsx(Oe,{size:12})}),e.jsx(j,{label:"Último acesso",valor:_e(p.lastSeenAt||p.ultimoLogin),icon:e.jsx(za,{size:12})})]})]}),e.jsxs("div",{style:F,children:[e.jsx(L,{children:"Estatísticas"}),e.jsx(j,{label:"Nota média recebida",valor:x.notaMediaRecebida!=null?`★ ${x.notaMediaRecebida.toFixed(2)} (${x.totalAvaliacoesRecebidas})`:"—"}),e.jsx(j,{label:"Avaliações feitas",valor:x.totalAvaliacoesFeitas}),e.jsx(j,{label:"Contratações",valor:x.contratacoes}),e.jsx(j,{label:"Cancelamentos",valor:x.cancelamentos}),e.jsx(j,{label:"Eventos (total)",valor:x.eventosTotal}),e.jsx(j,{label:"Eventos realizados",valor:x.eventosRealizados}),e.jsx(j,{label:"Eventos futuros",valor:x.eventosAtivos}),e.jsx(j,{label:"Vagas CLT (total)",valor:x.vagasTotal}),e.jsx(j,{label:"Vagas ativas",valor:x.vagasAtivas}),e.jsx(j,{label:"Vagas pendentes aprovação",valor:x.vagasPendentes}),e.jsx(j,{label:"Colaboradores",valor:`${x.colaboradoresAtivos} / ${x.colaboradoresTotal}`}),e.jsx(j,{label:"Escalas criadas",valor:x.escalasTotal})]})]}),e.jsxs("div",{style:F,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:12,flexWrap:"wrap"},children:[e.jsx(L,{style:{margin:0},children:"Extrato"}),o&&e.jsx(W,{size:13}),!o&&N.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{style:{fontSize:12,color:"#6b7280"},children:[N.length," lançamento",N.length!==1?"s":""]}),e.jsxs("span",{style:{fontSize:12,color:"#059669",fontWeight:700},children:["Entradas: ",r(U.entradas)]}),e.jsxs("span",{style:{fontSize:12,color:"#dc2626",fontWeight:700},children:["Saídas: ",r(U.saidas)]})]})]}),!o&&h&&e.jsx("div",{style:{background:"#fee2e2",color:"#b91c1c",padding:"10px 12px",borderRadius:8,fontSize:12},children:h}),!o&&!h&&N.length===0&&e.jsx("div",{style:{...J,padding:14},children:"Nenhuma movimentação de saldo registrada."}),!o&&!h&&N.length>0&&e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{style:{width:"100%",minWidth:760,borderCollapse:"collapse",fontSize:13},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:"#f9fafb"},children:["Descrição","Tipo","Entrada","Saída","Saldo após","Data"].map(i=>e.jsx("th",{style:{padding:"7px 10px",fontSize:11,fontWeight:700,color:"#6b7280",textTransform:"uppercase",textAlign:["Entrada","Saída","Saldo após"].includes(i)?"right":"left",borderBottom:"1px solid #e5e7eb",whiteSpace:"nowrap"},children:i},i))})}),e.jsx("tbody",{children:N.map(i=>e.jsxs("tr",{style:{borderTop:"1px solid #f3f4f6"},children:[e.jsxs("td",{style:{padding:"9px 10px"},children:[e.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#374151"},children:i.descricao||"Movimentação de saldo"}),Ue(i)&&e.jsx("div",{children:e.jsxs("a",{href:Ue(i),target:"_blank",rel:"noopener noreferrer",title:"Abrir evento em uma nova aba",style:{display:"inline-flex",alignItems:"center",gap:5,marginTop:5,padding:"4px 8px",borderRadius:6,border:"1px solid #bae6fd",background:"#f0f9ff",color:"#0369a1",fontSize:11,fontWeight:700,textDecoration:"none",whiteSpace:"nowrap"},children:[e.jsx(Qe,{size:12})," Abrir evento"]})})]}),e.jsx("td",{style:{padding:"9px 10px"},children:e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontWeight:700,padding:"2px 8px",borderRadius:20,background:i.tipo==="debito"?"#fee2e2":"#dcfce7",color:i.tipo==="debito"?"#b91c1c":"#166534"},children:[i.tipo==="debito"?e.jsx(de,{size:11}):e.jsx(Ze,{size:11}),i.tipo==="debito"?"SAÍDA":"ENTRADA"]})}),e.jsx("td",{style:{padding:"9px 10px",textAlign:"right",fontWeight:700,color:"#059669",whiteSpace:"nowrap"},children:i.tipo==="credito"?r(i.valor):"—"}),e.jsx("td",{style:{padding:"9px 10px",textAlign:"right",fontWeight:700,color:"#dc2626",whiteSpace:"nowrap"},children:i.tipo==="debito"?r(i.valor):"—"}),e.jsx("td",{style:{padding:"9px 10px",textAlign:"right",fontWeight:700,color:w,whiteSpace:"nowrap"},children:r(i.saldoApos)}),e.jsx("td",{style:{padding:"9px 10px",fontSize:12,color:"#374151",whiteSpace:"nowrap"},children:_e(i.createdAt)})]},i._id))})]})})]})]})}function Ra({form:a,setForm:t,editando:s,setEditando:d,salvar:c,salvando:p,principal:y}){const x=b=>C=>t(k=>({...k,[b]:C.target.value})),z=b=>C=>t(k=>({...k,endereco:{...k.endereco,[b]:C.target.value}}));return e.jsxs("div",{style:F,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[e.jsx(L,{children:"Dados editáveis"}),s?e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:c,disabled:p,style:ye,children:p?e.jsxs(e.Fragment,{children:[e.jsx(W,{size:12})," Salvando…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ge,{size:12})," Salvar"]})}),e.jsx("button",{onClick:()=>d(!1),disabled:p,style:ae,children:"Cancelar"})]}):e.jsxs("button",{onClick:()=>d(!0),style:ye,children:[e.jsx(Ca,{size:12})," Editar"]})]}),e.jsxs("div",{style:{display:"grid",gap:12,gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))"},children:[e.jsx(_,{label:"Nome da empresa",valor:a.nomeDaEmpresa,onChange:x("nomeDaEmpresa"),editando:s}
1),e.jsx(_,{label:"Razão social",valor:a.razaoSocial,onChange:x("razaoSocial"),editando:s}),e.jsx(_,{label:"CNPJ",valor:a.cnpj,onChange:x("cnpj"),editando:s}),e.jsx(_,{label:"E-mail",valor:a.email,onChange:x("email"),editando:s}),e.jsx(_,{label:"Telefone",valor:a.telefone,onChange:x("telefone"),editando:s})]}),e.jsxs("div",{style:{marginTop:20},children:[e.jsx(L,{children:"Endereço"}),e.jsxs("div",{style:{display:"grid",gap:12,gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))"},children:[e.jsx(_,{label:"CEP",valor:a.endereco.cep,onChange:z("cep"),editando:s}),e.jsx(_,{label:"Logradouro",valor:a.endereco.logradouro,onChange:z("logradouro"),editando:s}),e.jsx(_,{label:"Número",valor:a.endereco.numero,onChange:z("numero"),editando:s}),e.jsx(_,{label:"Complemento",valor:a.endereco.complemento,onChange:z("complemento"),editando:s}),e.jsx(_,{label:"Bairro",valor:a.endereco.bairro,onChange:z("bairro"),editando:s}),e.jsx(_,{label:"Cidade",valor:a.endereco.cidade,onChange:z("cidade"),editando:s}),e.jsx(_,{label:"Estado (UF)",valor:a.endereco.estado,onChange:z("estado"),editando:s})]})]}),y&&e.jsxs("div",{style:{marginTop:20},children:[e.jsx(L,{children:"Usuário principal"}),e.jsxs("div",{style:{display:"grid",gap:12,gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))"},children:[e.jsx(j,{label:"Nome",valor:y.primeiroNome||y.nome||"—"}),e.jsx(_,{label:e.jsxs(e.Fragment,{children:["E-mail de login",!y.temSenha&&y.email&&e.jsxs(e.Fragment,{children:[" ",e.jsx(be,{})]})]}),valor:a.emailUsuarioPrincipal,onChange:b=>t(C=>({...C,emailUsuarioPrincipal:b.target.value})),editando:s}),e.jsx(j,{label:"Telefone",valor:y.telefone||y.telefoneEnvios||y.telefoneVisualizacao||y.phone||"—"}),e.jsx(j,{label:"bubbleId",valor:y.bubbleId||"—"})]})]})]})}function Fa({colaboradores:a}){return a.length?e.jsxs("div",{style:F,children:[e.jsxs(L,{children:["Colaboradores (",a.length,")"]}),e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{style:re,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:g,children:"Nome"}),e.jsx("th",{style:g,children:"E-mail"}),e.jsx("th",{style:g,children:"Telefone"}),e.jsx("th",{style:g,children:"Função"}),e.jsx("th",{style:g,children:"Permissões"}),e.jsx("th",{style:g,children:"Status"}),e.jsx("th",{style:g,children:"Cadastro"})]})}),e.jsx("tbody",{children:a.map(t=>e.jsxs("tr",{children:[e.jsx("td",{style:u,children:t.nome||"—"}),e.jsx("td",{style:u,children:t.email||"—"}),e.jsx("td",{style:u,children:t.telefone||"—"}),e.jsx("td",{style:u,children:t.funcao||"—"}),e.jsx("td",{style:u,children:e.jsxs("div",{style:{display:"flex",gap:4,flexWrap:"wrap"},children:[(t.permissoes||[]).map(s=>e.jsx("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:4,background:"#eef2ff",color:"#3730a3"},children:s},s)),!t.permissoes?.length&&e.jsx("span",{style:{color:"#9ca3af",fontSize:11},children:"—"})]})}),e.jsx("td",{style:u,children:t.ativo?e.jsx(q,{cor:"#16a34a",children:"Ativo"}):e.jsx(q,{cor:"#9ca3af",children:"Inativo"})}),e.jsx("td",{style:u,children:D(t.createdAt)})]},t._id))})]})})]}):e.jsx("div",{style:J,children:"Nenhum colaborador cadastrado."})}function Pa({vagas:a}){return a.length?e.jsxs("div",{style:F,children:[e.jsxs(L,{children:["Vagas CLT (",a.length,")"]}),e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{style:re,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:g,children:"Título"}),e.jsx("th",{style:g,children:"Função"}),e.jsx("th",{style:g,children:"Local"}),e.jsx("th",{style:g,children:"Salário"}),e.jsx("th",{style:g,children:"Candidatos"}),e.jsx("th",{style:g,children:"Status"}),e.jsx("th",{style:g,children:"Criada"})]})}),e.jsx("tbody",{children:a.map(t=>e.jsxs("tr",{children:[e.jsx("td",{style:u,children:t.titulo||"—"}),e.jsx("td",{style:u,children:t.funcao||"—"}),e.jsx("td",{style:u,children:[t.cidade,t.estado].filter(Boolean).join("/")||"—"}),e.jsx("td",{style:u,children:t.salario?ne(t.salario):"—"}),e.jsx("td",{style:u,children:t.totalCandidatos??(t.candidatosBubbleIds||[]).length}),e.jsx("td",{style:u,children:t.aprovada===!1?e.jsx(q,{cor:"#f59e0b",icon:e.jsx(Xe,{size:10}),children:"Pendente"}
1):t.ativa?e.jsx(q,{cor:"#16a34a",icon:e.jsx(Ce,{size:10}),children:"Ativa"}):e.jsx(q,{cor:"#9ca3af",children:"Encerrada"})}),e.jsx("td",{style:u,children:D(t.createdAt)})]},t._id))})]})})]}):e.jsx("div",{style:J,children:"Nenhuma vaga CLT criada."})}function Wa({eventos:a}){const t=Je();return a.length?e.jsxs("div",{style:da,children:[e.jsx("div",{style:{padding:"14px 14px 4px"},children:e.jsxs(L,{children:["Eventos avulsos (",a.length,")"]})}),e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{style:{...xa,minWidth:900},children:[e.jsx("thead",{children:e.jsxs("tr",{style:pa,children:[e.jsx("th",{style:G,children:"Data do evento"}),e.jsx("th",{style:G,children:"Origem"}),e.jsx("th",{style:G,children:"Título / Função"}),e.jsx("th",{style:G,children:"Valor / vaga"}),e.jsx("th",{style:G,children:"Candidatos"}),e.jsx("th",{style:G,children:"Confirmados"}),e.jsx("th",{style:G,children:"Status"}),e.jsx("th",{style:ha,children:"Ações"})]})}),e.jsx("tbody",{children:a.map(s=>e.jsxs("tr",{style:ma,children:[e.jsx("td",{style:K,children:e.jsx(ia,{date:s.dataInicio,endDate:s.dataFinal})}),e.jsx("td",{style:K,children:e.jsx(la,{children:"Avulsa"})}),e.jsx("td",{style:K,children:e.jsx("strong",{style:{color:w},children:s.titulo||s.funcao||"—"})}),e.jsx("td",{style:{...K,whiteSpace:"nowrap"},children:ne(s.valor??s.valorTotal)}),e.jsx("td",{style:K,children:s.candidatos??0}),e.jsx("td",{style:K,children:s.confirmados??0}),e.jsx("td",{style:K,children:e.jsx(ca,{children:s.status||"—"})}),e.jsx("td",{style:{...fa,textAlign:"right",whiteSpace:"nowrap"},children:s.id&&e.jsxs("button",{onClick:()=>t(`/admin/contratacoes-avulsas/${s.id}`),title:"Abrir evento no admin",style:{display:"inline-flex",alignItems:"center",gap:6,background:"#fff",color:"#031D44",border:"1px solid #cbd5e1",borderRadius:8,padding:"7px 12px",fontSize:12.5,fontWeight:600,cursor:"pointer"},children:[e.jsx(Qe,{size:14})," Abrir"]})})]},s.id))})]})})]}):e.jsx("div",{style:J,children:"Nenhum evento avulso publicado."})}function $a({escalas:a}){return a.length?e.jsxs("div",{style:F,children:[e.jsxs(L,{children:["Escalas (",a.length,")"]}),e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{style:re,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:g,children:"Início"}),e.jsx("th",{style:g,children:"Título / função"}),e.jsx("th",{style:g,children:"Dias"}),e.jsx("th",{style:g,children:"Valor"}),e.jsx("th",{style:g,children:"Status"})]})}),e.jsx("tbody",{children:a.map(t=>e.jsxs("tr",{children:[e.jsx("td",{style:u,children:D(t.dataInicio)}),e.jsx("td",{style:u,children:t.titulo}),e.jsx("td",{style:u,children:t.diasTotal}),e.jsx("td",{style:u,children:ne(t.valor)}),e.jsx("td",{style:u,children:e.jsx(q,{cor:"#6b7280",children:t.status||"—"})})]},t.id))})]})})]}):e.jsx("div",{style:J,children:"Nenhuma escala criada."})}function Da({recebidas:a,feitas:t}){const[s,d]=m.useState("recebidas"),c=[["recebidas",`Recebidas (${a.length})`],["feitas",`Feitas (${t.length})`]];return e.jsxs("div",{children:[e.jsx("div",{style:{display:"flex",gap:0,marginBottom:16,borderBottom:"2px solid #e5e7eb"},children:c.map(([p,y])=>e.jsx("button",{onClick:()=>d(p),style:{padding:"7px 16px",border:"none",background:"transparent",fontWeight:s===p?700:500,color:s===p?w:"#6b7280",borderBottom:s===p?`3px solid ${ce}`:"3px solid transparent",cursor:"pointer",whiteSpace:"nowrap",fontSize:13},children:y},p))}),s==="recebidas"&&e.jsx(La,{avaliacoes:a}),s==="feitas"&&e.jsx(Na,{avaliacoes:t})]})}function La({avaliacoes:a}){return a.length?e.jsxs("div",{style:F,children:[e.jsxs(L,{children:["Avaliações recebidas pela empresa (",a.length,")"]}),e.jsx("div",{style:{display:"grid",gap:10},children:a.map(t=>{const s=(()=>{const d=t.freelancerFoto;return d?typeof d=="string"?d.startsWith("//")?`https:${d}`:d:typeof d=="object"&&d.gridFsId?`/api/imagens/${d.gridFsId}`:"":""})();return e.jsxs("div",{style:Ee,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",flexWrap:"wrap",gap:8},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[s&&e.jsx("img",{src:s,alt:"",style:{width:26,height:26,borderRadius:"50%",objectFit:"cover"}}),e.jsxs("span",{style:{color:"#fbbf24",fontWeight:700},children:[e.jsx(we,{size:14,style:{verticalAlign:"middle"}})," ",t.nota?.toFixed?.(1)||t.nota]}),e.jsx("strong",{style:{fontSize:13,color:w},children:t.freelancerNome||t.freelancerBubbleId||"—"})]}),e.jsx("span",{style:{fontSize:11,color:"#9ca3af"},children:D(t.bubbleCreatedAt)})]}),t.comentario&&e.jsxs("div",{style:{marginTop:6,fontSize:13,color:"#374151",fontStyle:"italic"},children:['"',t.comentario,'"']})]},t.bubbleId)})})]}):e.jsx("div",{style:J,children:"Sem avaliações recebidas."})}function Na({avaliacoes:a}){return a.length?e.jsxs("div",{style:F,children:[e.jsxs(L,{children:["Avaliações feitas pela empresa (",a.length,")"]}),e.jsx("div",{style:{display:"grid",gap:10},children:a.map(t=>{const s=(()=>{const d=t.freelancerFoto;
1return d?typeof d=="string"?d.startsWith("//")?`https:${d}`:d:typeof d=="object"&&d.gridFsId?`/api/imagens/${d.gridFsId}`:"":""})();return e.jsxs("div",{style:Ee,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",flexWrap:"wrap",gap:8},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[s&&e.jsx("img",{src:s,alt:"",style:{width:26,height:26,borderRadius:"50%",objectFit:"cover"}}),e.jsxs("span",{style:{color:"#fbbf24",fontWeight:700},children:[e.jsx(we,{size:14,style:{verticalAlign:"middle"}})," ",t.nota]}),e.jsx("strong",{style:{fontSize:13,color:w},children:t.freelancerNome||t.freelancerBubbleId||"—"}),e.jsx("span",{style:{fontSize:10,padding:"2px 6px",borderRadius:4,background:"#eef2ff",color:"#3730a3"},children:t.fonte})]}),e.jsx("span",{style:{fontSize:11,color:"#9ca3af"},children:D(t.createdAt)})]}),t.comentario&&e.jsxs("div",{style:{marginTop:6,fontSize:13,color:"#374151",fontStyle:"italic"},children:['"',t.comentario,'"']})]},t.id)})})]}):e.jsx("div",{style:J,children:"A empresa ainda não avaliou freelancers."})}function Oa({tickets:a}){return a.length?e.jsxs("div",{style:F,children:[e.jsxs(L,{children:["Tickets de suporte (",a.length,")"]}),e.jsx("div",{style:{display:"grid",gap:10},children:a.map(t=>e.jsxs("div",{style:Ee,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:8},children:[e.jsxs("div",{children:[e.jsx(wa,{size:12,style:{verticalAlign:"middle",marginRight:4,color:"#6b7280"}}),e.jsx("strong",{style:{color:w},children:t.assunto||t.idTicket||"(sem assunto)"}),t.departamento&&e.jsxs("span",{style:{fontSize:11,color:"#6b7280",marginLeft:8},children:["· ",t.departamento]})]}),e.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[e.jsx(q,{cor:t.status==="Resolvido"?"#16a34a":"#f59e0b",children:t.status||"—"}),e.jsx("span",{style:{fontSize:11,color:"#9ca3af"},children:D(t.bubbleCreatedAt||t.createdAt)})]})]}),t.mensagem&&e.jsxs("div",{style:{marginTop:6,fontSize:12,color:"#374151",whiteSpace:"pre-wrap"},children:[t.mensagem.slice(0,280),t.mensagem.length>280?"…":""]})]},t.bubbleId||t._id))})]}):e.jsx("div",{style:J,children:"Sem tickets de suporte abertos pela empresa."})}function q({children:a,cor:t="#6b7280",txtCor:s="#fff",icon:d}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,padding:"2px 8px",borderRadius:999,background:t,color:s,fontSize:11,fontWeight:700},children:[d,a]})}function be(){return e.jsx("span",{title:"Usuário legado — ainda não criou senha no app",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:16,height:16,borderRadius:"50%",background:"#f59e0b",color:"#fff",fontSize:9,fontWeight:800,lineHeight:1,flexShrink:0,cursor:"default"},children:"L"})}function L({children:a}){return e.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#6b7280",textTransform:"uppercase",marginBottom:10,letterSpacing:.5},children:a})}function j({label:a,valor:t,icon:s}){return e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"4px 0",fontSize:13,gap:8},children:[e.jsxs("span",{style:{color:"#6b7280",display:"inline-flex",alignItems:"center",gap:4},children:[s,a]}),e.jsx("span",{style:{color:w,fontWeight:600,textAlign:"right",wordBreak:"break-word"},children:t??"—"})]})}function _({label:a,valor:t,onChange:s,editando:d,tipo:c="text",multiline:p}){return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#6b7280",marginBottom:4},children:a}),d?p?e.jsx("textarea",{value:t||"",onChange:s,rows:3,style:He}):e.jsx("input",{type:c,value:t||"",onChange:s,style:He}):e.jsx("div",{style:{padding:"8px 10px",background:"#f9fafb",borderRadius:8,fontSize:13,color:w,minHeight:36,whiteSpace:"pre-wrap"},children:t||e.jsx("span",{style:{color:"#9ca3af"},children:"—"})})]})}const _a={free:"#6b7280",pro:"#0ea5e9",premium:"#7c3aed"},te={free:"Free",pro:"PRO",premium:"Premium"},Ua={ativo:"#16a34a",expirado:"#d97706",cancelado:"#dc2626",pendente:"#9ca3af"},Va={ativo:"Ativo",expirado:"Expirado",cancelado:"Cancelado",pendente:"Pendente"},qa={pendente:"Pendente",pago:"Pago",expirado:"Expirado",cancelado:"Cancelado",erro:"Erro"},qe={pendente:"#9ca3af",pago:"#16a34a",expirado:"#d97706",cancelado:"#dc2626",erro:"#ef4444"};function Ma({plano:a}){const t=_a[a]||"#6b7280";return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 10px",borderRadius:999,fontSize:12,fontWeight:700,background:t+"18",color:t,border:`1px solid ${t}40`},children:[e.jsx(Aa,{size:12}),te[a]||a]})}function Ha({status:a}){const t=Ua[a]||"#9ca3af";return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,padding:"2px 8px",borderRadius:999,fontSize:11,fontWeight:700,background:t+"18",color:t},children:[a==="ativo"?e.jsx(Ze,{size:11}):a==="cancelado"?e.jsx(de,{size:11}):e.jsx(Ta,{size:11}),Va[a]||a]})}function Ja({empresaId:a,token:t}){const s=localStorage.getItem("bubble_version")||"live",d={Authorization:`Bearer ${t}`,"x-bubble-version":s},[c,p]=m.useState(null),[y,x]=m.useState([]),[z,b]=m.useState([]),[C,k]=m.useState(!0),[P,H]=m.useState(!1),[O,N]=m.useState(!1),[X,U]=m.useState(!1),[V,o]=m.useState(""),[n,h]=m.useState({plano:"free",status:"ativo",pacoteId:"",vigencia
1Inicio:"",vigenciaFim:"",valorPago:"",formaPagamento:"manual",observacoes:""});function S(){k(!0),Promise.allSettled([fetch(`/api/admin/monetizacao/empresas/${a}`,{headers:d}),fetch(`/api/admin/monetizacao/pedidos?empresaId=${encodeURIComponent(a)}&limit=20`,{headers:d}),fetch("/api/admin/monetizacao/pacotes",{headers:d})]).then(async([r,i,A])=>{if(r.status==="fulfilled"&&r.value.ok){const v=await r.value.json();p(v),h(Q=>({...Q,plano:v.plano||"free",status:v.status||"ativo",pacoteId:v.pacoteId?String(v.pacoteId):"",vigenciaInicio:v.vigenciaInicio?v.vigenciaInicio.slice(0,10):"",vigenciaFim:v.vigenciaFim?v.vigenciaFim.slice(0,10):"",valorPago:v.valorPago!=null?v.valorPago:"",formaPagamento:v.formaPagamento||"manual",observacoes:v.observacoes||""}))}if(i.status==="fulfilled"&&i.value.ok){const v=await i.value.json();x(v.pedidos||[])}if(A.status==="fulfilled"&&A.value.ok){const v=await A.value.json();b(v.pacotes||[])}k(!1)})}m.useEffect(()=>{S()},[a]);const R=z.filter(r=>r.ativo!==!1&&(n.plano==="free"?!1:r.tipo===n.plano));async function Y(){if(n.plano!=="free"&&!n.pacoteId){alert("Selecione um pacote para o plano "+(n.plano==="pro"?"PRO":"Premium")+".");return}if(await oe({titulo:"Confirmar atribuição de plano",mensagem:`Atribuir plano ${te[n.plano]||n.plano} a esta empresa? A ação é imediata.`,textoConfirmar:"Sim, atribuir",textoCancelar:"Cancelar"})){H(!0),U(!1);try{const i={plano:n.plano,status:n.status,pacoteId:n.pacoteId||null,vigenciaInicio:n.vigenciaInicio||null,vigenciaFim:n.vigenciaFim||null,valorPago:n.valorPago!==""?Number(n.valorPago):void 0,formaPagamento:n.formaPagamento,observacoes:n.observacoes},A=await fetch(`/api/admin/monetizacao/empresas/${a}`,{method:"PUT",headers:{...d,"Content-Type":"application/json"},body:JSON.stringify(i)}),v=await A.json();if(!A.ok)throw new Error(v.error||"Erro ao salvar");p(v),U(!0),setTimeout(()=>U(!1),3e3),S()}catch(i){alert(i.message)}finally{H(!1)}}}async function M(){const r=c?.empresaNome||a;if(await oe({titulo:"Encerrar plano e voltar para Free",mensagem:`O plano ${te[c?.plano]||c?.plano} de ${r} será encerrado imediatamente. A empresa voltará ao Free, sem apagar pagamentos ou o histórico. Esta ação não gera estorno automático.`,textoConfirmar:"Encerrar e voltar para Free",textoCancelar:"Cancelar",perigoso:!0,checkboxLabel:"Confirmo o encerramento imediato do plano"})){N(!0),o("");try{const A=await fetch(`/api/admin/monetizacao/empresas/${a}/encerrar`,{method:"POST",headers:d}),v=await A.json().catch(()=>({}));if(!A.ok)throw new Error(v.error||"Erro ao encerrar plano");o(v.jaFree?"A empresa já estava no plano Free.":`Plano encerrado. ${v.pedidosCancelados||0} pedido(s) pendente(s) cancelado(s).`),await S()}catch(A){o(`Erro: ${A.message}`)}finally{N(!1)}}}if(C)return e.jsx("div",{style:{padding:32,textAlign:"center",color:"#9ca3af"},children:e.jsx(ze,{})});const I=c?.vigenciaFim&&new Date(c.vigenciaFim)<new Date,T=c?.historicoCancelamentos?.at?.(-1);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[e.jsxs("div",{style:F,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:12,flexWrap:"wrap",marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#6b7280",textTransform:"uppercase"},children:"Plano atual"}),c&&c.plano!=="free"&&c.status==="ativo"&&!I&&e.jsx("button",{onClick:M,disabled:O||P,style:se,children:O?e.jsxs(e.Fragment,{children:[e.jsx(W,{size:12})," Encerrando…"]}):e.jsxs(e.Fragment,{children:[e.jsx(de,{size:12})," Encerrar e voltar para Free"]})})]}),V&&e.jsx("div",{style:{marginBottom:12,padding:"8px 10px",borderRadius:8,fontSize:13,color:V.startsWith("Erro:")?"#b91c1c":"#166534",background:V.startsWith("Erro:")?"#fef2f2":"#ecfdf5"},children:V}),c?e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:24},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,color:"#9ca3af",marginBottom:4},children:"Plano"}),e.jsx(Ma,{plano:c.plano})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,color:"#9ca3af",marginBottom:4},children:"Status"}),e.jsx(Ha,{status:c.status})]}),c.pacoteSnapshot?.nome&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,color:"#9ca3af",marginBottom:4},children:"Pacote"}),e.jsxs("span",{style:{fontSize:13,fontWeight:600,color:w,display:"inline-flex",alignItems:"center",gap:4},children:[e.jsx(ka,{size:13})," ",c.pacoteSnapshot.nome]})]}),c.pacoteSnapshot?.qtdContratacoes>0&&!c.pacoteSnapshot.cotaIlimitada&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,color:"#9ca3af",marginBottom:4},children:"Cota"}),e.jsxs("span",{style:{fontSize:13,fontWeight:600,color:w},children:[c.pacoteSnapshot.qtdContratacoes," contratações/mês"]})]}),c.pacoteSnapshot?.cotaIlimitada&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,color:"#9ca3af",marginBottom:4},children:"Cota"}),e.jsx("span",{style:{fontSize:13,fontWeight:600,color:"#7c3aed"},children:"Ilimitada"})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,color:"#9ca3af",marginBottom:4},children:"Vigência início"}),e.jsx("span",{style:{fontSize:13,fontWeight:600,color:w}
1,children:D(c.vigenciaInicio)})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,color:"#9ca3af",marginBottom:4},children:"Vencimento"}),e.jsxs("span",{style:{fontSize:13,fontWeight:600,color:I?"#dc2626":w},children:[D(c.vigenciaFim),I&&e.jsx("span",{style:{fontSize:11,color:"#dc2626",marginLeft:4},children:"(vencido)"})]})]}),c.valorPago>0&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,color:"#9ca3af",marginBottom:4},children:"Valor pago"}),e.jsx("span",{style:{fontSize:13,fontWeight:600,color:w},children:ne(c.valorPago)})]}),c.observacoes&&e.jsxs("div",{style:{width:"100%"},children:[e.jsx("div",{style:{fontSize:11,color:"#9ca3af",marginBottom:4},children:"Observações"}),e.jsx("span",{style:{fontSize:13,color:"#374151"},children:c.observacoes})]}),c.criadoPor&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,color:"#9ca3af",marginBottom:4},children:"Criado por"}),e.jsx("span",{style:{fontSize:12,color:"#6b7280"},children:c.criadoPor})]}),c.atualizadoPor&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,color:"#9ca3af",marginBottom:4},children:"Última atualização por"}),e.jsxs("span",{style:{fontSize:12,color:"#6b7280"},children:[c.atualizadoPor," · ",D(c.updatedAt)]})]}),T&&e.jsxs("div",{style:{width:"100%",paddingTop:4,borderTop:"1px solid #f3f4f6"},children:[e.jsx("div",{style:{fontSize:11,color:"#9ca3af",marginBottom:4},children:"Último plano encerrado"}),e.jsxs("span",{style:{fontSize:12,color:"#6b7280"},children:[te[T.plano]||T.plano,T.pacoteNome?` · ${T.pacoteNome}`:""," · ",D(T.em),T.autorNome?` por ${T.autorNome}`:""]})]})]}):e.jsx("div",{style:{color:"#9ca3af",fontSize:13},children:"Nenhum plano configurado para esta empresa."})]}),e.jsxs("div",{style:F,children:[e.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#6b7280",textTransform:"uppercase",marginBottom:14},children:"Atribuir plano manualmente"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(180px, 1fr))",gap:12},children:[e.jsxs("div",{children:[e.jsx("label",{style:{fontSize:11,fontWeight:700,color:"#6b7280",display:"block",marginBottom:4},children:"Plano"}),e.jsxs("select",{value:n.plano,onChange:r=>h(i=>({...i,plano:r.target.value,pacoteId:""})),style:ie,children:[e.jsx("option",{value:"free",children:"Free"}),e.jsx("option",{value:"pro",children:"PRO"}),e.jsx("option",{value:"premium",children:"Premium"})]})]}),e.jsxs("div",{children:[e.jsx("label",{style:{fontSize:11,fontWeight:700,color:"#6b7280",display:"block",marginBottom:4},children:"Status"}),e.jsxs("select",{value:n.status,onChange:r=>h(i=>({...i,status:r.target.value})),style:ie,children:[e.jsx("option",{value:"ativo",children:"Ativo"}),e.jsx("option",{value:"pendente",children:"Pendente"}),e.jsx("option",{value:"expirado",children:"Expirado"}),e.jsx("option",{value:"cancelado",children:"Cancelado"})]})]}),n.plano!=="free"&&e.jsxs("div",{style:{gridColumn:"span 2"},children:[e.jsx("label",{style:{fontSize:11,fontWeight:700,color:"#6b7280",display:"block",marginBottom:4},children:"Pacote"}),e.jsxs("select",{value:n.pacoteId,onChange:r=>h(i=>({...i,pacoteId:r.target.value})),style:ie,children:[e.jsx("option",{value:"",children:"— Selecione um pacote —"}),R.map(r=>e.jsxs("option",{value:r._id,children:[r.nome," ",r.qtdContratacoes?`(${r.qtdContratacoes} contrat./mês)`:r.cotaIlimitada?"(ilimitado)":""]},r._id))]})]}),e.jsxs("div",{children:[e.jsx("label",{style:{fontSize:11,fontWeight:700,color:"#6b7280",display:"block",marginBottom:4},children:"Vigência início"}),e.jsx("input",{type:"date",className:"native-date",value:n.vigenciaInicio,onChange:r=>h(i=>
1({...i,vigenciaInicio:r.target.value})),style:le})]}),e.jsxs("div",{children:[e.jsx("label",{style:{fontSize:11,fontWeight:700,color:"#6b7280",display:"block",marginBottom:4},children:"Vencimento"}),e.jsx("input",{type:"date",className:"native-date",value:n.vigenciaFim,onChange:r=>h(i=>({...i,vigenciaFim:r.target.value})),style:le})]}),e.jsxs("div",{children:[e.jsx("label",{style:{fontSize:11,fontWeight:700,color:"#6b7280",display:"block",marginBottom:4},children:"Valor pago (R$)"}),e.jsx("input",{type:"number",min:0,step:.01,value:n.valorPago,onChange:r=>h(i=>({...i,valorPago:r.target.value})),placeholder:"0,00",style:le})]}),e.jsxs("div",{children:[e.jsx("label",{style:{fontSize:11,fontWeight:700,color:"#6b7280",display:"block",marginBottom:4},children:"Forma de pagamento"}),e.jsxs("select",{value:n.formaPagamento,onChange:r=>h(i=>({...i,formaPagamento:r.target.value})),style:ie,children:[e.jsx("option",{value:"manual",children:"Manual (admin)"}),e.jsx("option",{value:"pix",children:"PIX"}),e.jsx("option",{value:"cartao",children:"Cartão"})]})]}),e.jsxs("div",{style:{gridColumn:"1 / -1"},children:[e.jsx("label",{style:{fontSize:11,fontWeight:700,color:"#6b7280",display:"block",marginBottom:4},children:"Observações"}),e.jsx("textarea",{value:n.observacoes,onChange:r=>h(i=>({...i,observacoes:r.target.value})),rows:2,placeholder:"Ex: cortesia, negociação especial, teste…",style:{...le,resize:"vertical"}})]})]}),e.jsxs("div",{style:{marginTop:14,display:"flex",alignItems:"center",gap:10},children:[e.jsx("button",{onClick:Y,disabled:P,style:ye,children:P?e.jsxs(e.Fragment,{children:[e.jsx(W,{size:14})," Salvando…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ge,{size:14})," Salvar plano"]})}),X&&e.jsxs("span",{style:{fontSize:13,color:"#16a34a",display:"inline-flex",alignItems:"center",gap:4},children:[e.jsx(Ce,{size:14})," Salvo com sucesso!"]})]})]}),e.jsxs("div",{style:F,children:[e.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#6b7280",textTransform:"uppercase",marginBottom:12},children:"Histórico de pedidos/pagamentos"}),y.length===0?e.jsx("div",{style:J,children:"Nenhum pedido encontrado."}):e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{style:re,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:g,children:"Data"}),e.jsx("th",{style:g,children:"Plano / Pacote"}),e.jsx("th",{style:g,children:"Tipo"}),e.jsx("th",{style:g,children:"Valor"}),e.jsx("th",{style:g,children:"Pagamento"}),e.jsx("th",{style:g,children:"Vigência"}),e.jsx("th",{style:g,children:"Status"})]})}),e.jsx("tbody",{children:y.map(r=>e.jsxs("tr",{children:[e.jsx("td",{style:u,children:e.jsx("span",{style:{fontSize:12,color:"#374151"},children:D(r.createdAt)})}),e.jsxs("td",{style:u,children:[e.jsx("div",{style:{fontWeight:600,color:w,fontSize:13},children:te[r.plano]||r.plano}),r.pacoteSnapshot?.nome&&e.jsx("div",{style:{fontSize:11,color:"#6b7280"},children:r.pacoteSnapshot.nome})]}),e.jsx("td",{style:u,children:e.jsx("span",{style:{fontSize:11,color:"#6b7280",textTransform:"capitalize"},children:r.tipo||"—"})}),e.jsx("td",{style:u,children:e.jsx("span",{style:{fontWeight:700,color:r.valorFinal>0?"#16a34a":"#9ca3af",fontSize:13},children:ne(r.valorFinal)})}),e.jsx("td",{style:u,children:e.jsx("span",{style:{fontSize:12,color:"#374151",textTransform:"capitalize"},children:r.formaPagamento||"—"})}),e.jsx("td",{style:u,children:r.vigenciaInicio||r.vigenciaFim?e.jsxs("span",{style:{fontSize:11,color:"#6b7280",whiteSpace:"nowrap"},children:[D(r.vigenciaInicio)," → ",D(r.vigenciaFim)]}):e.jsx("span",{style:{color:"#9ca3af"},children:"—"})}),e.jsx("td",{style:u,children:e.jsx("span",{style:{fontSize:11,fontWeight:700,padding:"2px 7px",borderRadius:999,background:(qe[r.status]||"#9ca3af")+"18",color:qe[r.status]||"#9ca3af"},children:qa[r.status]||r.status})})]},r._id))})]})})]})]})}const ie={width:"100%",padding:"8px 10px",borderRadius:8,border:"1.5px solid #e5e7eb",fontSize:13,background:"#fff",fontFamily:"inherit"},le={width:"100%",padding:"8px 10px",borderRadius:8,border:"1.5px solid #e5e7eb",fontSize:13,background:"#fff",fontFamily:"inherit",boxSizing:"border-box"},Xa={pendente:"#f59e0b",pago:"#16a34a",vencido:"#dc2626",cancelado:"#9ca3af"},Ya={pendente:"Pendente",pago:"Pago",vencido:"Vencido",cancelado:"Cancelado"};function Qa({empresaId:a,token:t}){const s={Authorization:`Bearer ${t}`,"x-bubble-version":localStorage.getItem("bubble_version")||"live"},[d,c]=m.useState([]),[p,y]=m.useState(!0),[x,z]=m.useState(""),[b,C]=m.useState({}),[k,P]=m.useState({});async function H(){y(!0),z("");try{const o=await fetch(`/api/admin/boleto/empresa/${a}`,{headers:s}),n=await o.json();if(!o.ok)throw new Error(n.error||"Erro ao carregar boletos");c(n.boletos||[])}catch(o){z(o.message)}finally{y(!1)}}m.useEffect(()=>{H()},[a]);async function O(o){C(n=>
1({...n,[o]:{loading:!0}}));try{const n=await fetch("/api/admin/boleto/reconciliar",{method:"POST",headers:{...s,"Content-Type":"application/json"},body:JSON.stringify({codigoSolicitacao:o})}),h=await n.json();if(!n.ok)throw new Error(h.error||"Erro ao reconciliar");C(S=>({...S,[o]:{loading:!1,ok:h.ok,msg:h.msg||(h.ok?`Reconciliado! R$ ${(h.valor||0).toLocaleString("pt-BR",{style:"currency",currency:"BRL"})}`:`Situação Inter: ${h.situacaoInter}`)}})),h.ok&&c(S=>S.map(R=>R.codigoSolicitacao===o?{...R,status:"pago"}:R))}catch(n){C(h=>({...h,[o]:{loading:!1,ok:!1,msg:n.message}}))}}async function N(o){if(window.confirm(`Cancelar boleto ${o}? Esta ação não pode ser desfeita.`)){P(n=>({...n,[o]:!0}));try{const n=await fetch(`/api/contratante/boleto/${o}`,{method:"DELETE",headers:s}),h=await n.json();if(!n.ok)throw new Error(h.error||"Erro ao cancelar");c(S=>S.map(R=>R.codigoSolicitacao===o?{...R,status:"cancelado"}:R))}catch(n){alert(n.message)}finally{P(n=>({...n,[o]:!1}))}}}function X(o){const n=`/api/contratante/boleto/pdf/${o}`;fetch(n,{headers:s}).then(h=>h.ok?h.blob():h.json().then(S=>{throw new Error(S.error||"Erro ao baixar PDF")})).then(h=>{const S=document.createElement("a");S.href=URL.createObjectURL(h),S.download=`boleto-${o}.pdf`,S.click(),URL.revokeObjectURL(S.href)}).catch(h=>alert(h.message))}const U=o=>o==null?"—":Number(o).toLocaleString("pt-BR",{style:"currency",currency:"BRL"}),V=o=>{if(!o)return"—";const n=new Date(o),h=new Date;h.setHours(0,0,0,0);const S=new Date(n);S.setHours(0,0,0,0);const R=n.toLocaleDateString("pt-BR",{day:"2-digit",month:"short",year:"numeric"}),Y=S<h;return e.jsxs("span",{style:{color:Y?"#dc2626":void 0},children:[R,Y?" ⚠":""]})};return p?e.jsx("div",{style:{padding:32,textAlign:"center"},children:e.jsx(ze,{})}):x?e.jsxs("div",{style:{padding:16,color:"#dc2626",background:"#fef2f2",borderRadius:10},children:["Erro: ",x]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:16},children:e.jsxs("div",{style:F,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:14,flexWrap:"wrap",gap:8},children:[e.jsxs("div",{style:{fontSize:12,fontWeight:700,color:"#6b7280",textTransform:"uppercase"},children:["Boletos emitidos (",d.length,")"]}),e.jsxs("button",{onClick:H,style:{...ae,fontSize:12,padding:"6px 10px"},children:[e.jsx(ue,{size:13})," Atualizar"]})]}),d.length===0?e.jsx("div",{style:J,children:"Nenhum boleto encontrado para esta empresa."}):e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{style:re,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:g,children:"Emitido em"}),e.jsx("th",{style:g,children:"Vencimento"}),e.jsx("th",{style:g,children:"Valor"}),e.jsx("th",{style:g,children:"Status"}),e.jsx("th",{style:g,children:"Código"}),e.jsx("th",{style:g,children:"Linha digitável"}),e.jsx("th",{style:g,children:"Ações"})]})}),e.jsx("tbody",{children:d.map(o=>{const n=b[o.codigoSolicitacao]||{},h=k[o.codigoSolicitacao],S=Xa[o.status]||"#9ca3af";return e.jsxs("tr",{children:[e.jsx("td",{style:u,children:e.jsx("span",{style:{fontSize:12},children:new Date(o.createdAt).toLocaleDateString("pt-BR",{day:"2-digit",month:"short",year:"numeric"})})}),e.jsx("td",{style:u,children:e.jsx("span",{style:{fontSize:12},children:V(o.vencimento)})}),e.jsxs("td",{style:u,children:[e.jsx("span",{style:{fontWeight:700,color:"#031D44",fontSize:13},children:U(o.valor)}),o.valorPago!=null&&o.valorPago!==o.valor&&e.jsxs("div",{style:{fontSize:11,color:"#16a34a"},children:["Pago: ",U(o.valorPago)]})]}),e.jsxs("td",{style:u,children:[e.jsx("span",{style:{fontSize:11,fontWeight:700,padding:"2px 8px",borderRadius:999,background:S+"18",color:S},children:Ya[o.status]||o.status}),o.simulado&&e.jsx("div",{style:{fontSize:10,color:"#9ca3af",marginTop:2},children:"simulado"})]}),e.jsx("td",{style:u,children:e.jsx("span",{style:{fontSize:11,color:"#6b7280",fontFamily:"monospace",wordBreak:"break-all"},children:o.codigoSolicitacao})}),e.jsx("td",{style:u,children:o.linhaDigitavel?e.jsx("span",{style:{fontSize:11,color:"#374151",fontFamily:"monospace",wordBreak:"break-all"},children:o.linhaDigitavel}):e.jsx("span",{style:{color:"#9ca3af",fontSize:11},children:"—"})}),e.jsx("td",{style:{...u,whiteSpace:"nowrap"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4,minWidth:120}
1,children:[o.status!=="pago"&&o.status!=="cancelado"&&!o.simulado&&e.jsx("button",{onClick:()=>O(o.codigoSolicitacao),disabled:n.loading,style:{...ae,fontSize:11,padding:"5px 8px",justifyContent:"center"},title:"Forçar reconciliação com o Inter",children:n.loading?e.jsxs(e.Fragment,{children:[e.jsx(je,{size:11,className:"animate-spin"})," Aguarde…"]}):e.jsxs(e.Fragment,{children:[e.jsx(ue,{size:11})," Reconciliar"]})}),n.msg&&e.jsx("div",{style:{fontSize:10,color:n.ok?"#16a34a":"#d97706",maxWidth:160,whiteSpace:"normal"},children:n.msg}),!o.simulado&&e.jsxs("button",{onClick:()=>X(o.codigoSolicitacao),style:{...ae,fontSize:11,padding:"5px 8px",justifyContent:"center"},title:"Baixar PDF do boleto",children:[e.jsx(Ea,{size:11})," PDF"]}),o.status==="pendente"&&e.jsx("button",{onClick:()=>N(o.codigoSolicitacao),disabled:h,style:{...se,fontSize:11,padding:"5px 8px",justifyContent:"center"},title:"Cancelar boleto",children:h?e.jsxs(e.Fragment,{children:[e.jsx(je,{size:11,className:"animate-spin"})," Cancelando…"]}):e.jsxs(e.Fragment,{children:[e.jsx(de,{size:11})," Cancelar"]})})]})})]},o.codigoSolicitacao)})})]})})]})})}const F={background:"#fff",borderRadius:12,padding:16,border:"1px solid #e5e7eb",boxShadow:"0 1px 2px rgba(0,0,0,0.04)"},Ee={padding:10,borderRadius:10,background:"#f9fafb",border:"1px solid #e5e7eb"},J={padding:24,textAlign:"center",color:"#9ca3af",background:"#f9fafb",borderRadius:12,border:"1px dashed #e5e7eb"},re={width:"100%",borderCollapse:"collapse",fontSize:13},g={textAlign:"left",padding:"8px 6px",fontSize:11,fontWeight:700,color:"#6b7280",textTransform:"uppercase",borderBottom:"2px solid #e5e7eb"},u={padding:"10px 6px",borderBottom:"1px solid #f3f4f6",verticalAlign:"top"},xe={display:"inline-flex",alignItems:"center",gap:6,padding:"8px 14px",borderRadius:8,border:"none",fontWeight:700,fontSize:12,cursor:"pointer"},ye={...xe,background:w,color:"#fff"},ae={...xe,background:"#f3f4f6",color:w,border:"1px solid #e5e7eb"},ve={...xe,background:"#16a34a",color:"#fff"},Se={...xe,background:"#dc2626",color:"#fff"},ge={...ve,padding:"6px 10px",fontSize:11},se={...Se,padding:"6px 10px",fontSize:11},Me={display:"inline-flex",alignItems:"center",gap:6,padding:"6px 10px",background:"transparent",border:"none",color:w,fontWeight:600,fontSize:13,cursor:"pointer"},He={width:"100%",padding:"8px 10px",borderRadius:8,border:"1.5px solid #e5e7eb",fontSize:13,background:"#fff",fontFamily:"inherit",boxSizing:"border-box"};export{nt 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.