1import{r,j as e,u as Cs}from"./react-vendor-pafHdoJx.js";import{b as me,d as j,j as Ee,a as ks,a3 as Ss,x as As,ab as Se,h as Ts,c as I,g as Xe,p as Es,m as Ps,M as De,ac as fe,u as Rs,ad as Fs,ae as Ls,L as Is}from"./index-Db0fDLGN.js";import{v as Os,d as Ms,A as Ds}from"./firebase-vendor-D3UzkAhn.js";import{P as Vs,H as $s}from"./HelpTooltip-DKugySwl.js";import{E as Bs}from"./ErrorState-B9i6eo2M.js";import{aU as ta,aK as ss,L as R,k as ts,c as la,l as Q,aT as Va,Z as H,a6 as aa,bW as _s,X as ra,ap as ia,al as te,j as qs,aC as re,D as zs,ae as Y,q as U,an as ls,b6 as le,n as $a,g as Ks,b9 as Us,B as rs,U as Ae,_ as Ce,d as sa,bt as is,aa as ns,b4 as Hs,b5 as ke,w as na,aq as Te,J as We,bN as Ba,c8 as _a,d4 as qa,a5 as Ye,bc as Ve,at as za,cu as Gs,au as Js,bL as Qs,ad as Zs,aY as Xs,cl as oa,s as Ws,am as Ka,r as Ua,c6 as $e,v as ge,o as os,bf as Ys,x as et,bB as Ha,M as at,a3 as Ga}from"./ui-vendor-DLXJn6s3.js";import"./map-vendor-Dr8zbd0c.js";function st(){const{data:s,loading:l,error:o,refetch:c}=me(()=>j.certificadoStatus(),[]),{confirmar:t}=Ee(),[n,d]=r.useState(!1),[h,p]=r.useState(""),[x,u]=r.useState(null),[y,f]=r.useState(!0),[A,F]=r.useState("homologacao"),[w,k]=r.useState(""),[i,O]=r.useState(""),[v,T]=r.useState(null),[V,g]=r.useState(null),K=r.useCallback(async()=>{var b,N;if(!x||!h){k("Selecione o arquivo .pfx e informe a senha");return}d(!0),k(""),O(""),T(null),g(null);try{const E=await x.arrayBuffer(),B=btoa(String.fromCharCode(...new Uint8Array(E))),$=await j.certificadoUpload({pfxBase64:B,password:h,enableAnttDirect:y,anttEnvironment:A});T(($==null?void 0:$.certificado)||null),g(($==null?void 0:$.divergencia)||null);const Pe=(b=$==null?void 0:$.antt)==null?void 0:b.enabled,q=(N=$==null?void 0:$.antt)==null?void 0:N.error;O(y&&q?`Certificado verificado e salvo. Mas falhou ao ativar ANTT: ${q}. Use o card abaixo pra retentar.`:Pe?`Certificado verificado e salvo · ANTT direta ativada (${A}).`:"Certificado verificado e salvo."),u(null),p(""),c()}catch(E){k(E.message||"Falha ao enviar certificado")}finally{d(!1)}},[x,h,y,A,c]),Z=async()=>{if(await t({titulo:"Remover o certificado digital?",descricao:"Sem ele a plataforma para de emitir CT-e/MDF-e, de emitir CIOT direto na ANTT e de buscar documento na SEFAZ e na Receita.",confirmar:"Remover"}))try{await j.certificadoRemove(),c()}catch{}};return e.jsxs("div",{className:"space-y-6 max-w-2xl",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg",style:{background:"var(--sidebar-active-bg)"},children:e.jsx(ta,{className:"w-6 h-6",style:{color:"var(--accent-brand)"}})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",style:{color:"var(--page-text)"},children:"Certificado Digital A1"}),e.jsx("p",{className:"text-sm",style:{color:"var(--page-text-secondary)"},children:"Necessário para CT-e/MDF-e na SEFAZ. Opcionalmente, também emite CIOT gratuito via ANTT."})]})]}),e.jsxs("div",{className:"rounded-xl p-4 flex items-start gap-3",style:{background:"#eff6ff",border:"1px solid #bfdbfe"},children:[e.jsx(ss,{className:"w-5 h-5 flex-shrink-0 mt-0.5",style:{color:"#2563eb"}}),e.jsxs("div",{className:"text-sm",style:{color:"#1e40af"},children:[e.jsx("p",{className:"font-medium",children:"O que é o Certificado A1?"}),e.jsx("p",{className:"mt-1",children:"à o certificado digital da sua empresa (arquivo .pfx ou .p12) emitido por uma Autoridade Certificadora credenciada (Certisign, Serasa, etc). Obrigatório para assinar documentos fiscais na SEFAZ. Validade de 1 ano."}),e.jsxs("p",{className:"mt-2",children:["O ",e.jsx("strong",{children:"mesmo arquivo"})," pode ser reutilizado pra emitir CIOT direto na ANTT (mTLS) â sem precisar contratar IPEF paga em parte das operações."]})]})]}),l?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(R,{className:"w-6 h-6 animate-spin text-brand-500"})}):o?e.jsx(Bs,{error:o,onRetry:c,title:"Não foi possÃvel ler o status do certificado"}):s!=null&&s.hasCertificate?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[e.jsx(ts,{className:"w-6 h-6 flex-shrink-0",style:{color:"var(--accent-emerald)"}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-semibold",style:{color:"var(--page-text)"},children:"Certificado cadastrado"}),e.jsxs("p",{className:"text-sm",style:{color:"var(--page-text-secondary)"},children:[s.razaoSocial||"Empresa"," · ",s.cnpj||"â",s.emissor?` · emitido por ${s.emissor}`:""]}),e.jsx(tt,{status:s})]}),e.jsxs("button",{onClick:Z,className:"btn-danger flex items-center gap-2 text-sm flex-shrink-0",children:[e.jsx(la,{className:"w-4 h-4"})," Remover"]})]}),s.divergenciaDeCnpj&&e.jsxs("div",{className:"rounded-lg p-3 mb-4 flex items-start gap-2 text-sm",style:{background:s.divergenciaDeCnpj.mesmaRaiz?"#fffbeb":"#fef2f2",border:`1px solid ${s.divergenciaDeCnpj.mesmaRaiz?"#fcd34d":"#fecaca"}`,color:s.divergenciaDeCnpj.mesmaRaiz?"#92400e":"#991b1b"},children:[e.jsx(Q,{className:"w-4 h-4 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:s.divergenciaDeCnpj.aviso})]}),s.titularPessoaFisica&&e.jsxs("div",{className:"rounded-lg p-3 mb-4 flex items-start gap-2 text-sm",style:{background:"#fffbeb",border:"1px solid #fcd34d",color:"#92400e"},children:[e.jsx(Q,{className:"w-4 h-4 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:"Este é um e-CPF. A busca de MDF-e e CT-e consulta por CNPJ e precisa de um e-CNPJ da empresa."})]}),s.verificado===!1&&e.jsx("div",{className:"rounded-lg p-3 mb-4 text-sm",style:{background:"var(--surface-secondary)",border:"1px solid var(--border-primary)",color:"var(--page-text-secondary)"},children:"Este certificado foi enviado antes de passarmos a abrir o arquivo no servidor â a data de validade acima pode ser uma estimativa. Reenvie o mesmo arquivo para confirmá-la."}),e.jsx(lt,{}),e.jsx("p",{className:"text-xs mt-4",style:{color:"var(--page-text-muted)"},children:"Para substituir o certificado (renovação ou troca), remova o atual e envie o novo."})]}),e.jsx(rt,{status:s==null?void 0:s.antt,onChange:c})]}):e.jsxs("div",{className:"card space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Q,{className:"w-5 h-5",style:{color:"var(--accent-amber)"}}),e.jsx("h3",{className:"font-semibold",style:{color:"var(--page-text)"},children:"Nenhum certificado cadastrado"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label text-sm block mb-1.5",children:"Arquivo do Certificado (.pfx ou .p12)"}),e.jsxs("label",{className:"flex items-center gap-3 p-4 rounded-xl cursor-pointer transition-colors",style:{border:"2px dashed var(--border-secondary)",background:"var(--surface-secondary)"},children:[e.jsx(Va,{className:"w-6 h-6",style:{color:"var(--accent-brand)"}}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:x?x.name:"Clique para selecionar o arquivo"}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"Formatos aceitos: .pfx, .p12"})]}),e.jsx("input",{type:"file",accept:".pfx,.p12",className:"hidden",onChange:b=>{var N;return u(((N=b.target.files)==null?void 0:N[0])||null)}})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label text-sm block mb-1.5",children:"Senha do Certificado *"}),e.jsx("input",{type:"password",className:"input",style:{textTransform:"none"},placeholder:"Senha fornecida pela certificadora",value:h,onChange:b=>p(b.target.value)})]}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"Não precisamos do CNPJ nem da razão social: lemos os dois do próprio certificado e mostramos aqui para você conferir antes de seguir."}),e.jsx("div",{className:"rounded-xl p-4",style:{background:"var(--surface-secondary)",border:"1px solid var(--border-primary)"},children:e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",className:"mt-0.5",checked:y,onChange:b=>f(b.target.checked)}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{className:"w-4 h-4",style:{color:"#10B981"}}),e.jsx("span",{className:"font-medium text-sm",style:{color:"var(--page-text)"},children:"Também usar pra emissão CIOT gratuita via ANTT direta"})]}),e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--page-text-muted)"},children:"O mesmo PFX será espelhado no GCP Secret Manager pra mTLS com a ANTT. Permite emitir CIOT sem custo Extratta em viagens elegÃveis (ETC frota própria CLT ou ETC-ETC subcontratação)."}),y&&e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx("label",{className:"text-xs",style:{color:"var(--page-text-secondary)"},children:"Ambiente ANTT:"}),e.jsxs("select",{className:"input text-xs",style:{padding:"4px 8px",width:"auto"},value:A,onChange:b=>F(b.target.value),children:[e.jsx("option",{value:"homologacao",children:"Homologação (testes)"}),e.jsx("option",{value:"producao",children:"Produção"})]})]})]})]})}),w&&e.jsx("div",{className:"p-3 rounded-xl text-sm",style:{background:"#fef2f2",color:"#dc2626",border:"1px solid #fecaca"},children:w}),i&&e.jsx("div",{className:"p-3 rounded-xl text-sm",style:{background:"#ecfdf5",color:"#059669",border:"1px solid #a7f3d0"},children:i}),v&&e.jsxs("div",{className:"rounded-xl p-4 text-sm",style:{background:"#ecfdf5",border:"1px solid #a7f3d0",color:"#065f46"},children:[e.jsx("p",{className:"font-medium",children:"Conferimos o arquivo:"}),e.jsxs("ul",{className:"mt-2 space-y-1",children:[e.jsxs("li",{children:["Titular: ",e.jsx("strong",{children:v.titular||"â"}),v.cnpj?` · ${v.cnpj}`:""]}),v.emissor&&e.jsxs("li",{children:["Emitido por: ",v.emissor]}),e.jsxs("li",{children:["Vence em ",e.jsx("strong",{children:new Date(v.validoAte).toLocaleDateString("pt-BR")}),typeof v.diasAteVencer=="number"?` · faltam ${v.diasAteVencer} dias`:""]})]})]}),V&&e.jsxs("div",{className:"rounded-xl p-3 flex items-start gap-2 text-sm",style:{background:V.mesmaRaiz?"#fffbeb":"#fef2f2",border:`1px solid ${V.mesmaRaiz?"#fcd34d":"#fecaca"}`,color:V.mesmaRaiz?"#92400e":"#991b1b"},children:[e.jsx(Q,{className:"w-4 h-4 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:V.aviso})]}),e.jsxs("button",{onClick:K,disabled:n||!x||!h,className:"btn-primary w-full flex items-center justify-center gap-2",children:[n?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx(Va,{className:"w-4 h-4"}),n?"Abrindo e conferindo o certificadoâ¦":"Enviar Certificado"]}
1)]})]})}function tt({status:s}){if(!(s!=null&&s.validUntil))return null;const l=typeof s.diasAteVencer=="number"?s.diasAteVencer:null,o=new Date(s.validUntil).toLocaleDateString("pt-BR"),c=l==null?"var(--page-text-muted)":l<0?"#DC2626":l<=7||l<=30?"#D97706":"var(--page-text-muted)",t=l==null?`Validade: ${o}`:l<0?`Venceu em ${o} â há ${Math.abs(l)} dia${Math.abs(l)===1?"":"s"}`:l===0?`Vence hoje (${o})`:`Vence em ${l} dia${l===1?"":"s"} · ${o}`;return e.jsxs("p",{className:"text-xs mt-1 font-medium",style:{color:c},children:[t,l!=null&&l<=30&&e.jsxs("span",{className:"font-normal",children:[" ","â sem ele, a busca automática de MDF-e e CT-e para de trazer documento."]})]})}function lt(){const[s,l]=r.useState(!1),[o,c]=r.useState(null);async function t(){l(!0),c(null);try{const n=await j.certificadoTestar();c({ok:!0,mensagem:n.mensagem||"A SEFAZ aceitou o certificado."})}catch(n){const d=(n==null?void 0:n.body)||(n==null?void 0:n.data)||{};c({ok:!1,mensagem:d.provavel||(n==null?void 0:n.message)||"A SEFAZ não aceitou o certificado.",detalhe:d.error&&d.error!==d.provavel?d.error:void 0})}finally{l(!1)}}return e.jsxs("div",{children:[e.jsxs("button",{onClick:t,disabled:s,className:"btn-secondary flex items-center gap-2 text-sm",children:[s?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx(aa,{className:"w-4 h-4"}),s?"Consultando a SEFAZâ¦":"Testar na SEFAZ agora"]}),o&&e.jsxs("div",{className:"mt-3 rounded-lg p-3 flex items-start gap-2 text-sm",style:{background:o.ok?"#ecfdf5":"#fef2f2",border:`1px solid ${o.ok?"#a7f3d0":"#fecaca"}`,color:o.ok?"#065f46":"#991b1b"},children:[o.ok?e.jsx(ts,{className:"w-4 h-4 flex-shrink-0 mt-0.5"}):e.jsx(Q,{className:"w-4 h-4 flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{children:o.mensagem}),o.detalhe&&e.jsxs("p",{className:"mt-1 text-xs opacity-80",children:["Resposta da SEFAZ: ",o.detalhe]})]})]})]})}function rt({status:s,onChange:l}){const[o,c]=r.useState(!1),[t,n]=r.useState((s==null?void 0:s.environment)||"homologacao"),[d,h]=r.useState(null),[p,x]=r.useState(!1),[u,y]=r.useState(null),f=!!(s!=null&&s.enabled),A=async()=>{c(!0),y(null);try{await j.certificadoEnableAntt({anttEnvironment:t}),y({kind:"ok",msg:`ANTT direta ativada em ${t}.`}),l()}catch(k){y({kind:"err",msg:(k==null?void 0:k.message)||"Falha ao ativar ANTT"})}finally{c(!1)}},F=async()=>{if(confirm("Desativar emissão ANTT direta? O cert SEFAZ continua válido. Todos os CIOTs voltam a sair via Extratta.")){c(!0),y(null);try{await j.certificadoDisableAntt(),y({kind:"ok",msg:"ANTT direta desativada. Cert SEFAZ mantido."}),l()}catch(k){y({kind:"err",msg:(k==null?void 0:k.message)||"Falha ao desativar"})}finally{c(!1)}}},w=async()=>{x(!0),h(null);try{const k=await j.anttDirectTest();h(k)}catch(k){h({ok:!1,error:(k==null?void 0:k.message)||"Falha ao testar"})}finally{x(!1)}};return e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[e.jsx("div",{className:"p-2 rounded-lg",style:{background:f?"#ecfdf5":"var(--surface-secondary)"},children:e.jsx(H,{className:"w-5 h-5",style:{color:f?"#10B981":"var(--page-text-muted)"}})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--page-text)"},children:"Integração ANTT Direta (CIOT gratuito)"}),e.jsx("p",{className:"text-xs mt-0.5",style:{color:"var(--page-text-muted)"},children:"mTLS com appservices.antt.gov.br usando o mesmo A1 ICP-Brasil."})]}),f?e.jsxs("span",{className:"text-xs font-medium px-2 py-1 rounded",style:{background:"#ecfdf5",color:"#059669"},children:["Ativada · ",(s==null?void 0:s.environment)||"hml"]}):e.jsx("span",{className:"text-xs font-medium px-2 py-1 rounded",style:{background:"var(--surface-secondary)",color:"var(--page-text-muted)"},children:"Inativa"})]}),!f&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm",style:{color:"var(--page-text-secondary)"},children:"Use o cert A1 que já está cadastrado pra emitir CIOT gratuito direto na ANTT em viagens elegÃveis. Fallback Extratta continua ativo."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs",style:{color:"var(--page-text-secondary)"},children:"Ambiente:"}),e.jsxs("select",{className:"input text-xs",style:{padding:"4px 8px",width:"auto"},value:t,onChange:k=>n(k.target.value),children:[e.jsx("option",{value:"homologacao",children:"Homologação (testes)"}),e.jsx("option",{value:"producao",children:"Produção"})]})]}),e.jsxs("button",{onClick:A,disabled:o,className:"btn-primary flex items-center gap-2 text-sm",children:[o?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx(H,{className:"w-4 h-4"}),"Ativar ANTT direta"]})]}),f&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"text-xs space-y-1",style:{color:"var(--page-text-secondary)"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_s,{className:"w-3.5 h-3.5"}),"Ambiente: ",e.jsx("strong",{children:(s==null?void 0:s.environment)||"â"})]}),(s==null?void 0:s.certValidUntil)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(aa,{className:"w-3.5 h-3.5"}),"Cert válido até: ",e.jsx("strong",{children:new Date(s.certValidUntil).toLocaleDateString("pt-BR")}),(s==null?void 0:s.expirado)&&e.jsx("span",{className:"ml-1 px-1.5 py-0.5 text-[10px] rounded",style:{background:"#fef2f2",color:"#dc2626"},children:"EXPIRADO"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{onClick:w,disabled:p,className:"btn-secondary text-xs flex items-center gap-1.5",children:[p?e.jsx(R,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(aa,{className:"w-3.5 h-3.5"}),"Testar conexão mTLS"]}),e.jsx("button",{onClick:F,disabled:o,className:"btn-secondary text-xs",children:"Desativar ANTT"})]}),d&&e.jsxs("div",{className:"p-3 rounded-lg text-xs",style:{background:d.ok?"#ecfdf5":"#fef2f2",color:d.ok?"#059669":"#dc2626",border:`1px solid ${d.ok?"#a7f3d0":"#fecaca"}`},children:[e.jsx("p",{className:"font-medium",children:d.ok?"â Conexão mTLS OK":`â Falha: ${d.error||d.stage}`}),d.hint&&e.jsx("p",{className:"mt-1",children:d.hint}),d.certFingerprint&&e.jsxs("p",{className:"mt-1 font-mono opacity-70",children:["fingerprint: ",d.certFingerprint]})]})]}),u&&e.jsx("div",{className:"mt-3 p-2 rounded text-xs",style:{background:u.kind==="ok"?"#ecfdf5":"#fef2f2",color:u.kind==="ok"?"#059669":"#dc2626"},children:u.msg})]})}const Ja=[{family:"faisca",label:"FaÃsca",monthlyBRL:279,annualBRL:2678.4,tagline:"TMS de entrada para microtransportadoras",bullets:"50 docs · 100 IA · 20 consultas"},{family:"ignicao",label:"Ignição",monthlyBRL:697,annualBRL:6696,tagline:"Para frotas pequenas que querem TMS completo",bullets:"150 docs · 500 IA · 50 consultas"},{family:"estrada",label:"Estrada",monthlyBRL:1397,annualBRL:13404,tagline:"Para operação estruturada de médio porte",bullets:"600 docs · 1.500 IA · 200 consultas"},{family:"rota",label:"Rota",monthlyBRL:2997,annualBRL:28764,tagline:"Para frotas grandes, alto volume fiscal",bullets:"2.000 docs · 5.000 IA · 500 consultas"}];function Qa(s){return(s||"central.ignicao.monthly").split(".")[1]||"ignicao"}
1function Be(s){return s.toLocaleString("pt-BR",{style:"currency",currency:"BRL"})}function it({open:s,onClose:l,current:o,organizationId:c,hasActiveSubscription:t,onToast:n}){var b;const d=Qa(o.planLookupKey),h=((b=o.planLookupKey)==null?void 0:b.endsWith(".annual"))??!1,[p,x]=r.useState({planLookupKey:o.planLookupKey||"central.ignicao.monthly",appTier:o.appTier??null,appVehicles:o.appVehicles||0,annual:h}),[u,y]=r.useState(!1),[f,A]=r.useState(null);if(!s)return null;const F=Qa(p.planLookupKey),w=F==="comando",k=p.planLookupKey===o.planLookupKey&&p.appTier===(o.appTier||null)&&p.appVehicles===(o.appVehicles||0);function i(N){if(N==="comando"){x(B=>({...B,planLookupKey:"central.comando.quote"}));return}const E=p.annual?"annual":"monthly";x(B=>({...B,planLookupKey:`central.${N}.${E}`}))}function O(N){if(F==="comando"){x(E=>({...E,annual:N}));return}x(E=>({...E,annual:N,planLookupKey:`central.${F}.${N?"annual":"monthly"}`}))}const v=Ja.find(N=>N.family===F),T=w?0:p.annual&&(v!=null&&v.annualBRL)?Math.round(v.annualBRL/12*100)/100:(v==null?void 0:v.monthlyBRL)||0,V=p.appTier==="essencial"?29.9:p.appTier==="avancado"?39.9:p.appTier==="completo"?49.9:0,g=p.appTier&&p.appVehicles>0?V*p.appVehicles:0,K=T+g;async function Z(){var N;if(k){l();return}A(null),y(!0);try{if(w){n==null||n("Comercial vai entrar em contato em até 24h pra dimensionar o plano Comando.","success"),l();return}if(t){const{url:B}=await j.stripePortal(window.location.href);window.location.href=B;return}const{url:E}=await j.checkoutFromBillingIntent({organizationId:c,planLookupKey:p.planLookupKey,appTier:p.appTier,appVehicles:p.appVehicles,successUrl:`${window.location.origin}/configuracoes?tab=plano&status=success`,cancelUrl:`${window.location.origin}/configuracoes?tab=plano&status=cancelled`});if(E){window.location.href=E;return}throw new Error("Stripe não retornou URL de checkout")}catch(E){const B=((N=E==null?void 0:E.body)==null?void 0:N.message)||(E==null?void 0:E.message)||"Falha ao iniciar troca de plano";A(B),n==null||n(B,"error")}finally{y(!1)}}return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm",onClick:l,role:"dialog","aria-modal":"true","aria-labelledby":"plan-switcher-title",children:e.jsxs("div",{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto rounded-2xl bg-slate-900 border border-slate-800 shadow-2xl",onClick:N=>N.stopPropagation(),children:[e.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between p-5 border-b border-slate-800 bg-slate-900/95 backdrop-blur",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"plan-switcher-title",className:"text-lg font-bold text-white",children:"Trocar plano"}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:t?"Após confirmar, você vai pro portal Stripe pra concluir a mudança com proration automática.":"Cliente em trial â confirmar abre o Stripe Checkout pra ativar a assinatura."})]}),e.jsx("button",{type:"button",onClick:l,className:"p-2 rounded-lg text-slate-400 hover:text-white hover:bg-slate-800","aria-label":"Fechar",children:e.jsx(ra,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"inline-flex items-center gap-1 bg-slate-800 rounded-md p-0.5",children:[e.jsx("button",{type:"button",onClick:()=>O(!1),className:`px-3 py-1.5 rounded text-xs font-semibold transition-colors ${p.annual?"text-slate-400 hover:text-slate-200":"bg-indigo-600 text-white"}`,children:"Mensal"}),e.jsx("button",{type:"button",onClick:()=>O(!0),className:`px-3 py-1.5 rounded text-xs font-semibold transition-colors ${p.annual?"bg-indigo-600 text-white":"text-slate-400 hover:text-slate-200"}`,children:"Anual · econ. ~20%"})]}),e.jsxs("div",{className:"space-y-2",children:[Ja.map(N=>{const E=F===N.family,B=d===N.family,$=p.annual?Math.round(N.annualBRL/12*100)/100:N.monthlyBRL;return e.jsxs("button",{type:"button",onClick:()=>i(N.family),className:`w-full flex items-start justify-between gap-3 p-3 rounded-lg border text-left transition-colors ${E?"border-indigo-400 bg-indigo-500/10":"border-slate-700/50 bg-slate-800/40 hover:border-slate-600"}`,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-white",children:N.label}),B&&e.jsx("span",{className:"text-[9px] font-bold uppercase tracking-wide px-1.5 py-0.5 rounded bg-emerald-500/20 text-emerald-300",children:"Atual"}),E&&!B&&e.jsx(ia,{className:"w-3.5 h-3.5 text-indigo-300"})]}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-0.5",children:N.tagline}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:N.bullets})]}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsx("p",{className:"text-sm font-bold text-white",children:Be($)}),e.jsxs("p",{className:"text-[10px] text-slate-500",children:["/mês",p.annual?" · anual"
1:""]})]})]},N.family)}),e.jsxs("button",{type:"button",onClick:()=>i("comando"),className:`w-full flex items-start justify-between gap-3 p-3 rounded-lg border text-left transition-colors ${w?"border-indigo-400 bg-indigo-500/10":"border-slate-700/50 bg-slate-800/40 hover:border-slate-600"}`,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-semibold text-white",children:"Comando"}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-0.5",children:"Volumetria sob medida para grandes operações"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"Documentos · IA · consultas ilimitados"})]}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsx("p",{className:"text-sm font-bold text-white",children:"Sob cotação"}),e.jsx("p",{className:"text-[10px] text-slate-500",children:"comercial em 24h"})]})]})]}),!w&&e.jsxs("div",{className:"rounded-lg p-3 border border-slate-700/50 bg-slate-800/30 space-y-2",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-bold uppercase tracking-wider text-indigo-300",children:["Sentinel 365 App ",e.jsx("span",{className:"text-slate-500 font-normal lowercase tracking-normal",children:"(opcional)"})]}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-0.5",children:"Telemetria + jornada de motorista pelo celular · cobrança per-veÃculo via Stripe"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("select",{value:p.appTier||"",onChange:N=>x(E=>({...E,appTier:N.target.value||null})),className:"px-3 py-1.5 rounded-md text-xs bg-slate-900 border border-slate-700 text-slate-200",children:[e.jsx("option",{value:"",children:"Sem telemetria"}),e.jsx("option",{value:"essencial",children:"Essencial · R$ 29,90/veÃc"}),e.jsx("option",{value:"avancado",children:"Avançado · R$ 39,90/veÃc"}),e.jsx("option",{value:"completo",children:"Completo · R$ 49,90/veÃc"})]}),e.jsx("label",{className:"text-[11px] text-slate-400",children:"VeÃculos:"}),e.jsx("input",{type:"number",min:0,max:500,disabled:!p.appTier,value:p.appVehicles||"",onChange:N=>x(E=>({...E,appVehicles:Math.min(500,Math.max(0,parseInt(N.target.value)||0))})),className:"w-20 px-2 py-1.5 rounded-md text-xs bg-slate-900 border border-slate-700 text-slate-200 disabled:opacity-50",placeholder:"0"})]})]}),!w&&e.jsxs("div",{className:"rounded-lg p-3 border border-indigo-500/30 bg-indigo-500/5 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("span",{className:"text-slate-400",children:["Plano ",(v==null?void 0:v.label)||""]}),e.jsxs("span",{className:"text-slate-200 font-semibold",children:[Be(T),"/mês"]})]}),g>0&&e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("span",{className:"text-slate-400",children:["Sentinel 365 App à ",p.appVehicles]}),e.jsxs("span",{className:"text-slate-200 font-semibold",children:[Be(g),"/mês"]})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm pt-1.5 border-t border-indigo-500/10",children:[e.jsx("span",{className:"text-white font-semibold",children:"Total Stripe"}),e.jsxs("span",{className:"text-white font-bold",children:[Be(K),"/mês"]})]}),e.jsx("p",{className:"text-[10px] text-amber-300 pt-1",children:"ð¡ CIOT e VPO continuam faturados separadamente pela Extratta."}),e.jsx("p",{className:"text-[10px] text-slate-400",children:t?"Stripe calcula proration automática proporcional ao perÃodo restante.":"Após confirmar, você escolhe entre cartão, Pix ou boleto no checkout."})]}),f&&e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-red-500/10 border border-red-500/30",children:[e.jsx(te,{className:"w-4 h-4 text-red-400 shrink-0 mt-0.5"}),e.jsx("p",{className:"text-xs text-red-300",children:f})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:l,className:"flex-1 px-4 py-2.5 rounded-lg border border-slate-700 text-sm font-medium text-slate-300 hover:bg-slate-800",disabled:u,children:"Cancelar"}),e.jsx("button",{type:"button",onClick:Z,disabled:u||k,className:"flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg bg-indigo-600 hover:bg-indigo-500 disabled:opacity-50 disabled:cursor-not-allowed text-sm font-semibold text-white",children:u?e.jsxs(e.Fragment,{children:[e.jsx(R,{className:"w-4 h-4 animate-spin"})," Processandoâ¦"]}):k?"Sem alterações":w?e.jsxs(e.Fragment,{children:[e.jsx(qs,{className:"w-4 h-4"})," Solicitar contato comercial"]}):t?e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"w-4 h-4"})," Ir pro portal Stripe"]}):"Confirmar e ir pro checkout"})]})]})]})})}
1const nt=[{id:"ate100",label:"Até 100 CIOTs/mês",maxVolume:100,unitPrice:1.8,monthlyMin:180},{id:"ate300",label:"Até 300 CIOTs/mês",maxVolume:300,unitPrice:1.7,monthlyMin:510},{id:"ate500",label:"Até 500 CIOTs/mês",maxVolume:500,unitPrice:1.6,monthlyMin:800},{id:"ate1000",label:"Até 1.000 CIOTs/mês",maxVolume:1e3,unitPrice:1.5,monthlyMin:1500},{id:"acima1000",label:"Acima de 1.000 CIOTs/mês",maxVolume:1/0,unitPrice:1,monthlyMin:0}];function ot(s){return s<=0?null:s<=100?"ate100":s<=300?"ate300":s<=500?"ate500":s<=1e3?"ate1000":"acima1000"}function ct(s){if(!s)return"â";try{return new Date(s).toLocaleDateString("pt-BR",{day:"2-digit",month:"2-digit",year:"numeric"})}catch{return s}}function dt({status:s}){return s==="accepted"?e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wide px-2 py-0.5 rounded-full bg-emerald-500/15 text-emerald-300 border border-emerald-500/30",children:"Aceito"}):s==="outdated"?e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wide px-2 py-0.5 rounded-full bg-amber-500/15 text-amber-300 border border-amber-500/30",children:"Nova versão"}):e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wide px-2 py-0.5 rounded-full bg-red-500/15 text-red-300 border border-red-500/30",children:"Pendente"})}const Za={ciot:{title:"Termos do CIOT â Extratta",body:`A Extratta é o broker oficial responsável pela emissão do CIOT (Código Identificador da Operação de Transporte) conforme Lei 11.442/2007, Res. ANTT 6.078/2026 e MP 1.343/2026. 2 3Ao aceitar: 4 5⢠Pacote mÃnimo mensal: cobrado direto pela Extratta no e-mail do responsável financeiro cadastrado nesta conta. Valor por contrato em separado. 6⢠Cobrança não passa pela Stripe â você recebe boleto/Pix Extratta independente da fatura Sentinel 365. 7⢠O Sentinel 365 dispara emissão CIOT automaticamente quando ativado, mas a relação comercial é entre transportador (você) e Extratta. 8⢠Encerramento Lotação/Fracionada ⥠5 dias e TAC Agregado ⥠20/25/30 dias seguem regras MP 1.343/2026 (R3) â alertas são exibidos no Sentinel mas as ações são executadas pela Extratta. 9⢠Cancelamento do CIOT segue Lei 11.442 art 5º (janela 24h livre, 5d com motivo). 10 11Em caso de dúvida sobre cobrança CIOT, contato direto: [email protected].`},vpo:{title:"Termos do VPO â Extratta",body:`O VPO (Vale-Pedágio Obrigatório) é serviço regulado pela Lei 10.209/2001. A Extratta intermedia a compra junto aos fornecedores credenciados (Sem Parar, Veloe, Move Mais, ConectCar, Taggy Edenred). 12 13Ao aceitar: 14 15⢠Cobrança proporcional ao uso: % sobre o volume movimentado em vale-pedágio no mês. Fatura emitida pela Extratta direto no e-mail do responsável financeiro. 16⢠Cobrança não passa pela Stripe â independente da fatura Sentinel 365. 17⢠Reconciliação automática entre Sentinel e Extratta a cada 4 horas (vpoReconciliationCron). Divergências geram alertas, mas resolução financeira é entre transportador e Extratta. 18⢠Solicitações VPO pendentes > 1 hora em "CompraSolicitada" disparam alerta (resolução manual via portal Extratta). 19⢠Tags de novos fornecedores podem ser cadastradas livremente â cobrança proporcional ao uso real. 20 21Em caso de dúvida sobre cobrança VPO, contato direto: [email protected].`}};function mt({isAdmin:s,onToast:l,prefillCiotVolume:o=0,prefillVpoMovimentacao:c=0,prefillVpoTags:t=0}){const[n,d]=r.useState(!0),[h,p]=r.useState(null),[x,u]=r.useState(null),[y,f]=r.useState(!1),[A,F]=r.useState(ot(o)),[w,k]=r.useState(c),[i,O]=r.useState(t);async function v(){d(!0);try{const g=await j.brokerAcceptance();p(g)}catch{p(null)}finally{d(!1)}}r.useEffect(()=>{v()},[]);async function T(g){if(h){if(g==="ciot"&&!A){l==null||l("Escolha a faixa de CIOT antes de aceitar os termos.","error");return}if(g==="vpo"&&w<=0){l==null||l("Informe o volume estimado de pedágio antes de aceitar.","error");return}f(!0);try{await j.brokerAccept({service:g,version:h[g].currentVersion,...g==="ciot"?{ciotTier:A}:{},...g==="vpo"?{vpoEstimatedVolume:w,vpoTags:i}:{}}),l==null||l(`Termos ${g.toUpperCase()}
21 aceitos. Extratta enviará confirmação por email.`,"success"),u(null),await v()}catch(K){l==null||l((K==null?void 0:K.message)||"Falha ao registrar aceite","error")}finally{f(!1)}}}if(n)return e.jsx("div",{className:"card",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-500",children:[e.jsx(R,{className:"w-4 h-4 animate-spin"}),"Carregando termos do brokerâ¦"]})});if(!h)return null;const V=[{key:"ciot",label:"CIOT",sub:"Código Identificador da Operação de Transporte · Res. ANTT 6.078/2026"},{key:"vpo",label:"VPO",sub:"Vale-Pedágio Obrigatório · Lei 10.209/2001"}];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(zs,{className:"w-5 h-5 text-amber-400"}),e.jsx("h2",{className:"text-lg font-semibold text-white",children:"Aceites do broker · Extratta"}),e.jsx("span",{className:"ml-auto text-[10px] text-slate-500 uppercase tracking-wide",children:"faturado separado"})]}),e.jsx("div",{className:"space-y-3",children:V.map(({key:g,label:K,sub:Z})=>{const b=h[g];return e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg border border-slate-700/50 bg-slate-800/30",children:[e.jsx("div",{className:"mt-0.5 flex-shrink-0",children:b.status==="accepted"?e.jsx(Y,{className:"w-5 h-5 text-emerald-400"}):b.status==="outdated"?e.jsx(Q,{className:"w-5 h-5 text-amber-400"}):e.jsx(Q,{className:"w-5 h-5 text-red-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("p",{className:"text-sm font-semibold text-white",children:K}),e.jsx(dt,{status:b.status})]}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-0.5",children:Z}),b.status==="accepted"&&e.jsxs("p",{className:"text-[10px] text-slate-500 mt-1",children:["Aceito em ",ct(b.acceptedAt)," · versão ",b.acceptedVersion]}),b.status==="outdated"&&e.jsxs("p",{className:"text-[10px] text-amber-400 mt-1",children:["Versão ",b.acceptedVersion," aceita â termos foram atualizados pra ",b.currentVersion,". Re-aceite necessário."]}),b.status==="missing"&&e.jsxs("p",{className:"text-[10px] text-red-400 mt-1",children:["Aceite pendente â sem isso, operações ",K," podem ser bloqueadas pelo compliance."]})]}),s&&e.jsx("button",{type:"button",onClick:()=>u(g),className:"flex-shrink-0 inline-flex items-center gap-1 px-3 py-1.5 rounded-md text-xs font-semibold transition-colors "+(b.status==="accepted"?"border border-slate-700 text-slate-400 hover:text-slate-200 hover:border-slate-600":b.status==="outdated"?"bg-amber-600 hover:bg-amber-500 text-white":"bg-red-600 hover:bg-red-500 text-white"),children:b.status==="accepted"?"Ver termos":b.status==="outdated"?"Atualizar":"Aceitar termos"})]},g)})}),e.jsxs("div",{className:"mt-4 pt-3 border-t border-slate-700/30 flex items-start gap-2 text-[11px] text-slate-500",children:[e.jsx(re,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),e.jsxs("p",{children:["Cobranças de CIOT e VPO chegam direto no e-mail do responsável financeiro pela ",e.jsx("strong",{children:"Extratta"}),", independente da fatura Sentinel 365 (Stripe). Suporte comercial: ",e.jsx("span",{className:"text-brand-400",children:"[email protected]"}),"."]})]})]}),x&&h&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm",onClick:()=>u(null),role:"dialog","aria-modal":"true",children:e.jsxs("div",{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto rounded-2xl bg-slate-900 border border-slate-800 shadow-2xl",onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{className:"sticky top-0 z-10 p-5 border-b border-slate-800 bg-slate-900/95 backdrop-blur",children:[e.jsx("h2",{className:"text-lg font-bold text-white",children:Za[x].title}),e.jsxs("p",{className:"text-[11px] text-slate-500 mt-0.5",children:["Versão ",h[x].currentVersion," · efetiva nesta data"]})]}),e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx("div",{className:"text-xs text-slate-300 leading-relaxed whitespace-pre-line",children:Za[x].body}),x==="ciot"&&h[x].status!=="accepted"&&e.jsxs("div",{className:"rounded-xl border border-amber-500/30 bg-amber-500/5 p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-amber-300 mb-1",children:"Qual faixa CIOT você quer contratar?"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Você paga o pacote da faixa direto à Extratta. Se ultrapassar o volume da faixa, sobe pra próxima automaticamente â sem multa."}),o>0&&e.jsxs("p",{className:"text-[11px] text-emerald-300 mt-1",children:["Você indicou ",o," CIOTs/mês no simulador â pré-selecionamos a faixa recomendada."]})]}),e.jsx("div",{className:"space-y-2",children:nt.map(g=>e.jsxs("label",{className:"flex items-start gap-3 p-3 rounded-lg border cursor-pointer transition-colors "+(A===g.id?"border-amber-400 bg-amber-500/10":"border-slate-700 hover:border-slate-600"),children:[e.jsx("input",{type:"radio",name:"ciot-tier",checked:A===g.id,onChange:()=>F(g.id),className:"mt-1"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-white",children:g.label}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-0.5",children:["R$ ",g.unitPrice.toFixed(2).replace(".",",")," por CIOT",g.monthlyMin>0&&e.jsxs(e.Fragment,{children:[" · pacote mÃnimo R$ ",g.monthlyMin.toLocaleStr
21ing("pt-BR"),"/mês"]})]})]})]},g.id))})]}),x==="vpo"&&h[x].status!=="accepted"&&e.jsxs("div",{className:"rounded-xl border border-amber-500/30 bg-amber-500/5 p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-amber-300 mb-1",children:"Quanto você estima movimentar em pedágio?"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Cobrança é % proporcional ao valor movimentado â você só paga o que usou. Esse valor define a faixa de % aplicada."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-slate-400 mb-1",children:"Movimentação estimada/mês (R$)"}),e.jsx("input",{type:"number",min:0,step:1e3,value:w||"",onChange:g=>k(parseInt(g.target.value)||0),placeholder:"ex: 25000",className:"w-full px-3 py-2 rounded-lg bg-slate-800 border border-slate-700 text-sm text-white focus:border-amber-400 focus:outline-none"}),w>0&&e.jsxs("p",{className:"text-[11px] text-emerald-300 mt-2",children:["Faixa estimada: ",w<=1e4?"até R$ 10 mil (2,00%)":w<=5e4?"até R$ 50 mil (1,80%)":w<=1e5?"até R$ 100 mil (1,60%)":w<=5e5?"até R$ 500 mil (1,40%)":"acima de R$ 500 mil (1,20%)"," · ~R$ ",(w*(w<=1e4?.02:w<=5e4?.018:w<=1e5?.016:w<=5e5?.014:.012)).toLocaleString("pt-BR",{style:"currency",currency:"BRL"})," por mês (estimativa)"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-slate-400 mb-1",children:"Quantas tags de gaveta novas precisará?"}),e.jsx("input",{type:"number",min:0,value:i||"",onChange:g=>O(parseInt(g.target.value)||0),placeholder:"0",className:"w-full px-3 py-2 rounded-lg bg-slate-800 border border-slate-700 text-sm text-white focus:border-amber-400 focus:outline-none"}),i>0&&e.jsxs("p",{className:"text-[11px] text-slate-400 mt-1",children:["Setup único: ",i," à R$ 20 = R$ ",(i*20).toLocaleString("pt-BR")," (cobrança Extratta na ativação)"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2 border-t border-slate-800",children:[e.jsx("button",{type:"button",onClick:()=>u(null),className:"flex-1 px-4 py-2.5 rounded-lg border border-slate-700 text-sm font-medium text-slate-300 hover:bg-slate-800",disabled:y,children:"Fechar"}),h[x].status!=="accepted"&&s&&e.jsx("button",{type:"button",onClick:()=>T(x),disabled:y,className:"flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg bg-emerald-600 hover:bg-emerald-500 disabled:opacity-50 disabled:cursor-not-allowed text-sm font-semibold text-white",children:y?e.jsxs(e.Fragment,{children:[e.jsx(R,{className:"w-4 h-4 animate-spin"})," Registrandoâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"w-4 h-4"})," Aceito os termos · versão ",h[x].currentVersion]})})]})]})]})})]})}function z(s){return s.toLocaleString("pt-BR",{style:"currency",currency:"BRL"})}function de(s){if(!s)return"â";const l=typeof s=="string"?new Date(s):s!=null&&s.toDate?s.toDate():null;return l?l.toLocaleDateString("pt-BR",{day:"2-digit",month:"short",year:"numeric"}):"â"}function xt({message:s,type:l,onClose:o}){return r.useEffect(()=>{const c=setTimeout(o,4e3);return()=>clearTimeout(c)},[o]),e.jsxs("div",{className:I("fixed bottom-6 right-6 z-[100] flex items-center gap-3 px-5 py-3 rounded-xl shadow-2xl border animate-in slide-in-from-bottom-4 transition-all",l==="success"?"bg-emerald-500/15 border-emerald-500/30 text-emerald-300":"bg-red-500/15 border-red-500/30 text-red-300"),children:[l==="success"?e.jsx(Y,{className:"w-5 h-5"}):e.jsx(te,{className:"w-5 h-5"}),e.jsx("span",{className:"text-sm font-medium",children:s}),e.jsx("button",{onClick:o,className:"ml-2 opacity-60 hover:opacity-100",children:e.jsx(ra,{className:"w-4 h-4"})})]})}const pt=[{id:"org",label:"Empresa",icon:rs},{id:"antt",label:"ANTT 2026",icon:U},{id:"certificado",label:"Certificado Digital",icon:ta},{id:"team",label:"Equipe",icon:Ae},{id:"billing",label:"Plano e Uso",icon:Ce},{id:"audit",label:"Auditoria",icon:sa},{id:"help",label:"Ajuda",icon:is},{id:"account",label:"Minha Conta",icon:ns}],Xa={faisca:{label:"FaÃsca",color:"from-slate-500/20 to-slate-600/10 border-slate-500/30",icon:H},ignicao:{label:"Ignição",color:"from-emerald-500/20 to-emerald-600/10 border-emerald-500/30",icon:H},estrada:{label:"Estrada",color:"from-brand-500/20 to-brand-600/10 border-brand-500/30",icon:$a},rota:{label:"Rota",color:"from-violet-500/20 to-violet-600/10 border-violet-500/30",icon:le},comando:{label:"Comando",color:"from-red-500/20 to-red-600/10 border-red-500/30",icon:le},frota:{label:"Rota",color:"from-violet-500/20 to-violet-600/10 border-violet-500/30",icon:le},conecta:{label:"Ignição",color:"from-emerald-500/20 to-emerald-600/10 border-emerald-500/30",icon:H},gestao:{label:"Estrada",color:"from-brand-500/20 to-brand-600/10 border-brand-500/30",icon:$a},inteligencia:{label:"Rota",color:"from-violet-500/20 to-violet-600/10 border-violet-500/30",icon:le},starter:{label:"FaÃsca",color:"from-slate-500/20 to-slate-600/10 border-slate-500/30",icon:H},free:{label:"FaÃsca",color:"from-slate-500/20 to-slate-600/10 border-slate-500/30",icon:H}},Wa={faisca:{monthly:279,annual:2678.4,lookupKey:"central.faisca.monthly"},ignicao:{monthly:697,annual:6696,lookupKey:"central.ignicao.monthly"},estrada:{monthly:1397,annual:13404,lookupKey:"central.estrada.monthly"},rota:{monthly:2997,annual:28764,lookupKey:"central.rota.monthly"},comando:{monthly:0,annual:0,lookupKey:"central.comando.quote"},frota:{monthly:2997,annual:28764,lookupKey:"central.rota.monthly"},conecta:{monthly:697,annual:6696,lookupKey:"central.ignicao.monthly"},gestao:{monthly:1397,annual:13404,lookupKey:"central.estrada.monthly"},inteligencia:{monthly:2997,annual:28764,lookupKey:"central.rota.monthly"},starter:{monthly:279,annual:2678.4,lookupKey:"central.faisca.monthly"},free:{monthly:279,annual:2678.4,lookupKey:"central.faisca.monthly"}},ut={essencial:{label:"Essencial",perVehicle:29.9,lookupKey:"app.essencial.monthly"},avancado:{label:"Avançado",perVehicle:39.9,lookupKey:"app.avancado.monthly"},completo:{label:"Completo",perVehicle:49.9,lookupKey:"app.completo.monthly"}},Ya={faisca:{docsFiscais:50,aiActions:100},ignicao:{docsFiscais:150,aiActions:500},estrada:{docsFiscais:600,aiActions:1500},rota:{docsFiscais:2e3,aiActions:5e3},comando:{docsFiscais:999999,aiActions:999999},frota:{docsFiscais:2e3,aiActions:5e3},conecta:{docsFiscais:150,aiActions:500},gestao:{docsFiscais:600,aiActions:1500},inteligencia:{docsFiscais:2e3,aiActions:5e3},starter:{docsFiscais:50,aiActions:100},free:{docsFiscais:50,aiActions:100}},ht=["Transporte de carga","Transporte de passageiros","LogÃstica urbana","Agronegócio","Locação de veÃculos","Concessionária","Governamental","Outro"],ea=["none","view","edit"];function es({permissions:s,onChange:l,enabledModules:o}){const c=fe(s),t=d=>
21{l({...Se(d)})},n=d=>{const h=s[d]||"none",p=ea.indexOf(h),x=ea[(p+1)%ea.length];l({...s,[d]:x})};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(oa,{className:"w-4 h-4 text-brand-400"}),e.jsx("span",{className:"text-sm font-semibold",style:{color:"var(--page-text)"},children:"Permissões por módulo"}),e.jsx("span",{className:I("ml-auto text-[10px] px-2 py-0.5 rounded-full font-medium",c==="fleet_admin"?"bg-amber-500/15 text-amber-400":c==="fleet_manager"?"bg-brand-500/15 text-brand-400":"bg-purple-500/15 text-purple-400"),children:c==="fleet_admin"?"Administrador":c==="fleet_manager"?"Gestor":"Personalizado"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>t("fleet_admin"),className:I("flex-1 text-xs px-3 py-1.5 rounded-lg border font-medium transition-colors",c==="fleet_admin"?"border-amber-500/40 bg-amber-500/10 text-amber-400":"border-slate-700 text-slate-400 hover:border-slate-600"),children:"Administrador"}),e.jsx("button",{type:"button",onClick:()=>t("fleet_manager"),className:I("flex-1 text-xs px-3 py-1.5 rounded-lg border font-medium transition-colors",c==="fleet_manager"?"border-brand-500/40 bg-brand-500/10 text-brand-400":"border-slate-700 text-slate-400 hover:border-slate-600"),children:"Gestor"})]}),e.jsx("div",{className:"rounded-lg border border-slate-700/50 overflow-hidden",children:Fs.map((d,h)=>{const p=s[d.id]||"none",x=Ls[p],u=o&&o.length>0&&!o.includes(d.id);return e.jsxs("button",{type:"button",onClick:()=>!u&&n(d.id),disabled:!!u,className:I("w-full flex items-center justify-between px-3 py-2 text-left transition-colors",h>0&&"border-t border-slate-800/50",u?"opacity-40 cursor-not-allowed":"hover:bg-slate-800/30 cursor-pointer"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-xs font-medium text-slate-200",children:d.label}),u&&e.jsx("span",{className:"text-[10px] text-slate-600 ml-1.5",children:"(não licenciado)"})]}),e.jsx("span",{className:I("text-[10px] font-medium px-2 py-0.5 rounded-full",x.bgColor,x.color),children:x.label})]},d.id)})}),e.jsx("p",{className:"text-[10px] text-slate-600",children:"Clique em cada módulo para alternar: Sem acesso â Leitura â Escrita"})]})}function as({permissions:s,onChange:l}){const c=fe(s)==="fleet_admin",t=[{key:"fleet_admin",titulo:"Administrador",desc:"Acesso total: equipe, faturamento, fiscal, canais e configurações.",icon:le},{key:"fleet_manager",titulo:"Membro",desc:"Operação do dia a dia: pedidos, estoque, catálogo e conexões.",icon:Te}];return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(oa,{className:"w-4 h-4 text-brand-400"}),e.jsx("span",{className:"text-sm font-semibold",style:{color:"var(--page-text)"},children:"Papel do membro"})]}),t.map(n=>{const d=n.key==="fleet_admin"?c:!c,h=n.icon;return e.jsxs("button",{type:"button",onClick:()=>l({...Se(n.key)}),className:I("w-full flex items-start gap-3 px-3 py-2.5 rounded-lg border text-left transition-colors",d?"border-brand-500/50 bg-brand-500/10":"border-slate-700 hover:border-slate-600"),children:[e.jsx(h,{className:I("w-4 h-4 mt-0.5 flex-shrink-0",d?"text-brand-400":"text-slate-500")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:n.titulo}),e.jsx("p",{className:"text-[11px] mt-0.5",style:{color:"var(--page-text-muted)"},children:n.desc})]}),d&&e.jsx(ia,{className:"w-4 h-4 text-brand-400 ml-auto flex-shrink-0"})]},n.key)})]})}function bt({orgId:s,isAdmin:l}){const{confirmar:o}=Ee(),{toast:c}=Rs(),[t,n]=r.useState([]),[d,h]=r.useState(!0),[p,x]=r.useState(!1),[u,y]=r.useState({name:"",code:"",city:"",state:""}),[f,A]=r.useState(!1),F=async()=>{try{const i=await j.branches();n((i==null?void 0:i.branches)||[])}catch{}h(!1)};r.useState(()=>{F()});const w=async()=>{if(u.name.trim()){A(!0);try{await j.createBranch(u),x(!1),y({name:"",code:"",city:"",state:""}),F()}catch(i){c({title:"Não consegui criar a filial",description:(i==null?void 0:i.message)||"Erro desconhecido.",kind:"error"})}finally{A(!1)}}},k=async(i,O)=>{if(await o({titulo:`Excluir a filial "${O}"?`,descricao:"Reatribua os veÃculos antes.",confirmar:"Excluir"}))try{await j.deleteBranch(i),F()}catch{}};
21return d?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(R,{className:"w-6 h-6 animate-spin",style:{color:"var(--accent-brand)"}})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold",style:{color:"var(--page-text)"},children:"Filiais e Garagens"}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"Segmente a frota por localidade. Supervisores veem apenas seus dados."})]}),l&&e.jsxs("button",{onClick:()=>x(!p),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold",style:{background:"var(--accent-brand)",color:"#fff"},children:[e.jsx(et,{className:"w-3.5 h-3.5"})," Nova Filial"]})]}),p&&e.jsxs("div",{className:"card p-4 space-y-3",style:{borderColor:"var(--accent-brand)"},children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("input",{value:u.name,onChange:i=>y({...u,name:i.target.value}),placeholder:"Nome da filial",className:"input col-span-2"}),e.jsx("input",{value:u.code,onChange:i=>y({...u,code:i.target.value}),placeholder:"Código (ex: CPN)",className:"input"}),e.jsx("input",{value:u.city,onChange:i=>y({...u,city:i.target.value}),placeholder:"Cidade",className:"input"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:w,disabled:f||!u.name.trim(),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold",style:{background:"var(--accent-brand)",color:"#fff"},children:[f?e.jsx(R,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(ia,{className:"w-3.5 h-3.5"})," Criar"]}),e.jsx("button",{onClick:()=>x(!1),className:"px-3 py-1.5 rounded-lg text-xs",style:{color:"var(--page-text-muted)"},children:"Cancelar"})]})]}),e.jsx("div",{className:"space-y-2",children:t.map(i=>e.jsxs("div",{className:"card p-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center ${i.isHQ?"bg-blue-500/15":"bg-slate-500/10"}`,children:e.jsx(Ha,{className:`w-4 h-4 ${i.isHQ?"text-blue-500":""}`,style:i.isHQ?{}:{color:"var(--page-text-muted)"}})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",style:{color:"var(--page-text)"},children:i.name}),i.code&&!i.isHQ&&e.jsxs("p",{className:"text-[10px]",style:{color:"var(--page-text-muted)"},children:[i.code," ",i.city&&`· ${i.city}`," ",i.state&&`- ${i.state}`]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs",style:{color:"var(--page-text-muted)"},children:[e.jsx(na,{className:"w-3.5 h-3.5"})," ",i.vehicleCount||0]}),e.jsxs("div",{className:"flex items-center gap-1 text-xs",style:{color:"var(--page-text-muted)"},children:[e.jsx(Ae,{className:"w-3.5 h-3.5"})," ",i.driverCount||0]}),!i.isHQ&&l&&e.jsx("button",{onClick:()=>k(i.id,i.name),className:"p-1 rounded hover:bg-red-500/10 text-red-400",children:e.jsx(la,{className:"w-3.5 h-3.5"})})]})]},i.id))}),t.length<=1&&!p&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx(Ha,{className:"w-10 h-10 mx-auto mb-2",style:{color:"var(--page-text-muted)"}}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"Nenhuma filial criada. Crie filiais para segmentar sua frota."})]})]})}function It({embedded:s=!1,tab:l}={}){var ba,ga,fa,ja,va,Na,ya,wa,Ca,ka,Sa,Aa,Ta,Ea,Pa,Ra,Fa,La,Ia,Oa,Ma;const{confirmar:o}=Ee(),{role:c,user:t,orgId:n,impersonatedOrgId:d}=ks(),{data:h,loading:p,error:x,refetch:u}=me(()=>j.org(),[]),[y,f]=r.useState(null),[A,F]=r.useState([]),[w,k]=r.useState(!1),[i,O]=r.useState(null),[v,T]=r.useState(l||"org");r.useEffect(()=>{s&&l&&l!==v&&T(l)},[l,s]);const{modules:V}=Ss(),g=!!V&&As(V),[K,Z]=r.useState(!1),[b,N]=r.useState({email:"",name:"",role:"fleet_manager",permissions:{...Se("fleet_manager")}}),[E,B]=r.useState(!1),[$,Pe]=r.useState(""),[q,_e]=r.useState(null),[qe,cs]=r.useState(!1),[ze,ds]=r.useState(!1),[ca,xe]=r.useState(null),[X,pe]=r.useState(null),[P,ue]=r.useState(null),[Re,Fe]=r.useState(!1),[Ke,da]=r.useState(null),[Nt,ms]=r.useState("road_speed"),[yt,xs]=r.useState({motorway:80,trunk:70,primary:70,secondary:50,residential:30,service:10}),[wt,ps]=r.useState(80),[Ct,us]=r.useState(8),[kt,St]=r.useState(!1);r.useEffect(()=>{if(!(t!=null&&t.uid)||v!=="telematics")return;const a=d||n;a&&Os(Ms(Ts,"FleetConfig",a)).then(C=>{if(C.exists()){const L=C.data();ms(L.speedLimitMode||"road_speed"),L.fixedSpeedLimits&&xs(L.fixedSpeedLimits),L.singleSpeedLimit&&ps(L.singleSpeedLimit),L.speedTolerancePercent!=null&&us(L.speedTolerancePercent)}}).catch(()=>{})},[t==null?void 0:t.uid,v]);const[Ue,hs]=r.useState(!1),[ma,xa]=r.useState(!1),[he,ee]=r.useState(!1),[bs,pa]=r.useState(!1),[M,He]=r.useState(null),_=c==="fleet_admin"||c==="super_admin",D=r.useCallback((a,C="success")=>{da({message:a,type:C})},[]);if(r.useEffect(()=>{v==="billing"&&(j.billing().then(f).catch(()=>{}),j.invoices().then(F).catch(()=>{}),j.stripeSubscriptionStatus().then(He).catch(()=>{}))},[v]),p)return e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(R,{className:"w-8 h-8 text-brand-500 animate-spin"})});if(x)return e.jsxs("div",{className:"text-center py-20",children:[e.jsx(Q,{className:"w-10 h-10 text-amber-400 mx-auto mb-3"}),e.jsx("p",{className:"text-slate-300",children:x})]});if(!h)return null;const S=i||h,je=h.members||[],Ge=je.filter(a=>a.status==="active"||!a.status),ve=h.summary||{},ie=Xa[S.plan||S.planSlug||"ignicao"]||Xa.ignicao,m=y,Je=S.plan||S.planSlug||"ignicao",Le=Wa[Je]||Wa.ignicao,G=Ya[Je]||Ya.ignicao,gs=(m==null?void 0:m.vehicleCount)??ve.vehicles??0,ne=(m==null?void 0:m.billingCycle)==="annual"||((ba=S==null?void 0:S.billingIntent)==null?void 0:ba.annual)===!0,Ie=ne&&Le.annual>0?Math.round(Le.annual/12*100)/100:Le.monthly,Oe=(ga=S==null?void 0:S.billingIntent)==null?void 0:ga.appTier,Qe=Oe==="essencial"||Oe==="avancado"||Oe==="completo"?Oe:null,ae=((fa=S==null?void 0:S.billingIntent)==null?void 0:fa.appVehicles)||0,W=Qe?ut[Qe]:null,Me=W&&ae>0?W.perVehicle*ae:0,fs=Ie+Me;W==null||W.perVehicle;const be=Je==="comando",ua=((ja=S==null?void 0:S.billing)==null?void 0:ja.status)==="trialing"||((va=S==null?void 0:S.billing)==null?void 0:va.status)==="demo"||(S==null?void 0:S.isDemo)===!0,oe=((Na=m==null?void 0:m.ai)==null?void 0:Na.overageCost)??0,ha=fs+oe,js=async()=>
21{if(i){k(!0);try{await j.updateOrg(i),u(),O(null),D("Dados da organização salvos com sucesso")}catch(a){D(a.message,"error")}finally{k(!1)}}},ce=(a,C)=>{O({...i||h,[a]:C})},vs=async(a,C,L)=>{Fe(!0);try{const se={role:C};L&&(se.permissions=L),await j.updateTeamMemberRole(a,C,L),pe(null),u(),D("Permissões atualizadas com sucesso")}catch(se){D(se.message,"error")}finally{Fe(!1)}},Ns=async()=>{if(P){Fe(!0);try{P.type==="remove"?await j.removeTeamMember(P.uid):P.type==="deactivate"?await j.deactivateTeamMember(P.uid):P.type==="reactivate"&&await j.reactivateTeamMember(P.uid),ue(null),u(),D(`Membro ${{remove:"removido",deactivate:"desativado",reactivate:"reativado"}[P.type]} com sucesso`)}catch(a){D(a.message,"error")}finally{Fe(!1)}}},ys=async()=>{if(b.email){B(!0),Pe("");try{const a=fe(b.permissions),C={email:b.email,name:b.name,role:a==="custom"?"fleet_manager":a};a==="custom"&&(C.permissions=b.permissions);const L=await j.inviteTeamMember(C);Z(!1),N({email:"",name:"",role:"fleet_manager",permissions:{...Se("fleet_manager")}}),_e({email:b.email,resetLink:(L==null?void 0:L.resetLink)||void 0,emailSent:(L==null?void 0:L.emailSent)||!1}),D(`Membro ${b.email} adicionado`),u()}catch(a){Pe(a.message),D(a.message||"Não foi possÃvel adicionar o membro","error")}finally{B(!1)}}},ws=async()=>{if(t!=null&&t.email){xa(!0);try{await Ds(Is,t.email),hs(!0),D(`E-mail de redefinição enviado para ${t.email}`)}catch(a){D(a.message,"error")}finally{xa(!1)}}};return e.jsxs("div",{className:s?"space-y-6":"space-y-6 max-w-5xl",children:[Ke&&e.jsx(xt,{message:Ke.message,type:Ke.type,onClose:()=>da(null)}),!s&&e.jsx(Vs,{tips:["Configure dados da organização, gerencie membros da equipe e acompanhe o faturamento.","Apenas administradores podem adicionar ou remover membros da equipe."],storageKey:"settings"}),!s&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-brand-600/15 flex items-center justify-center",children:e.jsx(Ks,{className:"w-5 h-5 text-brand-400"})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold",style:{color:"var(--page-text)"},children:["Configurações ",e.jsx($s,{content:"Gerencie dados organizacionais, membros da equipe e acompanhe faturas.",position:"bottom"})]}),e.jsx("p",{className:"text-slate-400 text-sm",children:"Gerencie sua organização, equipe e faturamento"})]})]}),i&&e.jsxs("button",{onClick:js,disabled:w,className:"btn-primary flex items-center gap-2",children:[w?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx(Us,{className:"w-4 h-4"}),"Salvar Alterações"]})]}),!s&&e.jsx("div",{className:"flex gap-1 p-1 bg-slate-800/50 rounded-xl",children:pt.map(a=>e.jsxs("button",{onClick:()=>T(a.id),className:I("flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg text-sm font-medium transition-all",v===a.id?"bg-slate-700 text-white shadow-sm":"text-slate-400 hover:text-slate-200"),children:[e.jsx(a.icon,{className:"w-4 h-4"}),a.label]},a.id))}),v==="org"&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:I("card bg-gradient-to-br border",ie.color),children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-white/5 flex items-center justify-center",children:e.jsx(ie.icon,{className:"w-6 h-6 text-white"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-slate-400 uppercase tracking-wider",children:"Plano Atual"}),e.jsx("p",{className:"text-xl font-bold",style:{color:"var(--page-text)"},children:ie.label})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-secondary)"},children:"Ativo desde"}),e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:de(h.createdAt)})]})]})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(rs,{className:"w-5 h-5 text-brand-400"}),e.jsx("h2",{className:"text-lg font-semibold text-white",children:"Dados da Organização"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-slate-300 mb-1.5 block",children:"Nome"}),e.jsx("input",{type:"text",value:S.name||"",onChange:a=>ce("name",Xe(a.target.value)),className:"input",disabled:!_})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-slate-300 mb-1.5 block",children:"CNPJ"}),e.jsx("input",{type:"text",value:S.cnpj||"",onChange:a=>ce("cnpj",Es(a.target.value)),className:"input",disabled:!_})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-slate-300 mb-1.5 block",children:"Segmento"}),e.jsxs("select",{value:S.segment||"",onChange:a=>ce("segment",a.target.value),className:"input",disabled:!_,children:[e.jsx("option",{value:"",children:"Selecione..."}),ht.map(a=>e.jsx("option",{value:a,children:a},a))]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-slate-300 mb-1.5 block",children:"Cidade"}),e.jsx("input",{type:"text",value:S.city||"",onChange:a=>ce("city",Xe(a.target.value)),className:"input",disabled:!_})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-slate-300 mb-1.5 block",children:"UF"}),e.jsx("input",{type:"text",value:S.state||"",onChange:a=>ce("state",Xe(a.target.value)),className:"input",maxLength:2,disabled:!_})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"text-sm font-medium text-slate-300 mb-1.5 block flex items-center gap-1.5",children:[e.jsx(Hs,{className:"w-3.5 h-3.5"})," Telefone"]}),e.jsx("input",{type:"text",value:S.phone||"",onChange:a=>ce("phone",Ps(a.target.value)),placeholder:"(11) 99999-9999",className:"input",disabled:!_})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-sm font-medium text-slate-300 mb-1.5 block flex items-center gap-1.5",children:[e.jsx(ke,{className:"w-3.5 h-3.5"})," E-mail de contato"]}),e.jsx("input",{type:"email",value:S.contactEmail||"",onChange:a=>ce("contactEmail",a.target.value),placeholder:"[email protected]",className:"input",disabled:!_})]})]})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[g?e.jsx(Ae,{className:"w-5 h-5 text-brand-400"}):e.jsx(na,{className:"w-5 h-5 text-brand-400"}),e.jsx("h2",{className:"text-lg font-semibold text-white",children:g?"Resumo da Equipe":"Resumo da Frota"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"p-3 rounded-xl bg-slate-800/40 border border-slate-700/50 text-center",children:[e.jsx(Ae,{className:"w-5 h-5 text-amber-400 mx-auto mb-1.5"}),e.jsx("p",{className:"text-xl font-bold",style:{color:"var(--page-text)"},children:ve.activeMembers??Ge.length}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-secondary)"},children:g?"Membros ativos":"Gestores ativos"})]}),!g&&e.jsxs("div",{className:"p-3 rounded-xl bg-slate-800/40 border border-slate-700/50 text-center",children:[e.jsx(Te,{className:"w-5 h-5 text-emerald-400 mx-auto mb-1.5"}),e.jsx("p",{className:"text-xl font-bold",style:{color:"var(--page-text)"},children:ve.approvedDrivers??0}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-secondary)"},children:"Motoristas vinculados"})]}),!g&&e.jsxs("div",{className:"p-3 rounded-xl bg-slate-800/40 border border-slate-700/50 text-center",children:[e.jsx(We,{className:"w-5 h-5 text-blue-400 mx-auto mb-1.5"}),e.jsx("p",{className:"text-xl font-bold",style:{color:"var(--page-text)"},children:ve.vehicles??0}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-secondary)"},children:"VeÃculos cadastrados"})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-slate-800/40 border border-slate-700/50 text-center",children:[e.jsx(Ba,{className:"w-5 h-5 text-slate-500 mx-auto mb-1.5"}),e.jsx("p",{className:"text-xl font-bold",style:{color:"var(--page-text)"},children:ve.inactiveMembers??0}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-secondary)"},children:"Membros inativos"})]})]})]}),e.jsxs("div",{className:"card",children:[e.jsx("h2",{className:"text-lg font-semibold",style:{color:"var(--page-text)"},children:"Identificadores"}),e.jsxs("div",{className:"space-y-2.5 mt-3",children:[e.jsxs("div",{className:"flex items-center justify-between p-2.5 rounded-lg bg-slate-800/40",children:[e.jsxs("span",{className:"text-xs text-slate-400 flex items-center gap-1.5",children:[e.jsx(_a,{className:"w-3 h-3"})," Org ID"]}),e.jsx("span",{className:"text-xs text-slate-300 font-mono select-all",children:h.id})]}),e.jsxs("div",{className:"flex items-center justify-between p-2.5 rounded-lg bg-slate-800/40",children:[e.jsxs("span",{className:"text-xs text-slate-400 flex items-center gap-1.5",children:[e.jsx(qa,{className:"w-3 h-3"})," Criado em"]}),e.jsx("span",{className:"text-xs",style:{color:"var(--page-text)"},children:de(h.createdAt)})]}),e.jsxs("div",{className:"flex items-center justify-between p-2.5 rounded-lg bg-slate-800/40",children:[e.jsxs("span",{className:"text-xs text-slate-400 flex items-center gap-1.5",children:[e.jsx(U,{className:"w-3 h-3"})," Seu papel"]}),e.jsx("span",{className:"text-xs",style:{color:"var(--page-text)"},children:c==="fleet_admin"?"Administrador":c==="super_admin"?"Super Admin":"Gestor"})]})]})]})]})]}),e.jsxs("div",{className:"mt-6",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("h3",{className:"text-base font-bold",style:{color:"var(--page-text)"},children:"Filiais"}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"Sub-unidades da sua operação. Empresas com uma única filial podem ignorar esta seção."})]}),e.jsx(bt,{orgId:n||"",isAdmin:_})]})]}),v==="antt"&&e.jsx(vt,{}),v==="certificado"&&e.jsx(st,{}),v==="team"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-3 p-4 rounded-xl bg-amber-500/5 border border-amber-500/15",children:[e.jsx(Ye,{className:"w-5 h-5 text-amber-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-amber-300",children:"Informação de custo"}),e.jsx("p",{className:"text-xs text-slate-400 mt-1",children:"O plano da organização é
21cobrado por veÃculo/mês. Gestores e administradores estão incluÃdos no plano sem custo adicional por membro."})]})]}),e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ae,{className:"w-5 h-5 text-brand-400"}),e.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Membros (",Ge.length,je.length!==Ge.length?` / ${je.length} total`:"",")"]})]}),_&&e.jsxs("button",{onClick:()=>Z(!0),className:"flex items-center gap-2 px-3 py-2 bg-brand-600 hover:bg-brand-500 rounded-xl text-xs font-semibold transition-all",children:[e.jsx(Ve,{className:"w-3.5 h-3.5"}),"Adicionar"]})]}),e.jsxs("div",{className:"space-y-2",children:[je.map(a=>{var Ne,ye,we;const C=a.uid===(t==null?void 0:t.uid),L=a.role==="fleet_admin"?"Administrador":a.role==="super_admin"?"Super Admin":"Gestor",se=a.role==="fleet_admin"?le:a.role==="super_admin"?U:za,J=a.status==="inactive",Ze=J?"bg-slate-500/15 text-slate-500 border-slate-500/20":a.role==="fleet_admin"?"bg-amber-500/15 text-amber-400 border-amber-500/20":a.role==="super_admin"?"bg-purple-500/15 text-purple-400 border-purple-500/20":"bg-brand-500/15 text-brand-400 border-brand-500/20";return e.jsxs("div",{className:I("flex items-center gap-3 p-3 rounded-xl transition-colors",J?"opacity-60 bg-slate-800/20":"hover:bg-slate-800/40"),children:[e.jsx("div",{className:I("w-9 h-9 rounded-full flex items-center justify-center text-sm font-bold flex-shrink-0",J?"bg-slate-600/15 text-slate-500":"bg-brand-600/15 text-brand-400"),children:(((Ne=a.name)==null?void 0:Ne[0])||((ye=a.email)==null?void 0:ye[0])||"?").toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:I("text-sm font-medium truncate",J?"text-slate-500":"text-slate-200"),children:a.name||((we=a.email)==null?void 0:we.split("@")[0])}),C&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-slate-700 text-slate-400",children:"Você"}),J&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-red-500/15 text-red-400",children:"Inativo"})]}),e.jsx("p",{className:"text-xs text-slate-500 truncate",children:a.email})]}),e.jsxs("span",{className:I("text-xs font-medium px-2.5 py-1 rounded-lg border flex items-center gap-1",Ze),children:[e.jsx(se,{className:"w-3 h-3"}),L]}),_&&!C&&e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:()=>xe(ca===a.uid?null:a.uid),className:"p-1.5 rounded-lg hover:bg-slate-700 transition-colors text-slate-400 hover:text-slate-200",children:e.jsx(Gs,{className:"w-4 h-4"})}),ca===a.uid&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>xe(null)}),e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-52 bg-slate-800 border border-slate-700 rounded-xl shadow-xl z-50 py-1.5 overflow-hidden",children:[e.jsxs("button",{onClick:()=>{xe(null),pe({uid:a.uid,currentRole:a.role,permissions:a.permissions||Se(a.role)})},className:"w-full flex items-center gap-2.5 px-3.5 py-2.5 text-sm text-slate-300 hover:bg-slate-700/50 transition-colors",children:[e.jsx(Js,{className:"w-3.5 h-3.5"}),"Editar permissões"]}),J?e.jsxs("button",{onClick:()=>{xe(null),ue({type:"reactivate",uid:a.uid,name:a.name||a.email})},className:"w-full flex items-center gap-2.5 px-3.5 py-2.5 text-sm text-emerald-400 hover:bg-slate-700/50 transition-colors",children:[e.jsx(Qs,{className:"w-3.5 h-3.5"}),"Reativar"]}):e.jsxs("button",{onClick:()=>{xe(null),ue({type:"deactivate",uid:a.uid,name:a.name||a.email})},className:"w-full flex items-center gap-2.5 px-3.5 py-2.5 text-sm text-amber-400 hover:bg-slate-700/50 transition-colors",children:[e.jsx(Ba,{className:"w-3.5 h-3.5"}),"Desativar"]}),e.jsx("div",{className:"border-t border-slate-700 my-1"}),e.jsxs("button",{onClick:()=>{xe(null),ue({type:"remove",uid:a.uid,name:a.name||a.email})},className:"w-full flex items-center gap-2.5 px-3.5 py-2.5 text-sm text-red-400 hover:bg-red-500/10 transition-colors",children:[e.jsx(la,{className:"w-3.5 h-3.5"}),"Remover permanentemente"]})]})]})]})]},a.uid)}),je.length===0&&e.jsx("p",{className:"text-sm text-slate-500 py-4 text-center",children:"Apenas você neste momento."})]})]}),e.jsx(De,{open:!!q,onClose:()=>_e(null),title:"Membro adicionado",description:q==null?void 0:q.email,size:"md",icon:e.jsx(Ve,{className:"w-5 h-5"}),intent:"success",children:q&&e.jsxs(e.Fragment,{children:[q.resetLink?e.jsxs("div",{className:"space-y-3",children:[q.emailSent?e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-emerald-500/10 border border-emerald-500/20",children:[e.jsx(ke,{className:"w-4 h-4 text-emerald-400 mt-0.5 flex-shrink-0"}),e.jsxs("p",{className:"text-sm text-emerald-200",children:["Um e-mail foi enviado para ",e.jsx("strong",{children:q.email})," com instruções para definir a senha e acessar a plataforma."]})]}):e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-amber-500/10 border border-amber-500/20",children:[e.jsx(te,{className:"w-4 h-4 text-amber-400 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-sm text-amber-200",children:"Não foi possÃvel enviar o e-mail automaticamente. Envie o link abaixo ao novo membro."})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-slate-800 border border-slate-700",children:[e.jsx(Zs,{className:"w-4 h-4 text-brand-400 flex-shrink-0"}),e.jsx("p",{className:"text-xs text-slate-300 break-all flex-1 select-all font-mono",children:q.resetLink})]}),e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(q.resetLink),D("Link copiado")},className:"absolute top-2 right-2 p-1.5 rounded-lg bg-slate-700 hover:bg-slate-600 transition-colors",title:"Copiar link",children:e.jsx(Xs,{className:"w-3.5 h-3.5 text-slate-300"})})]}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:q.emailSent?'Caso o e-mail não chegue, o membro pode usar "Esqueci minha senha" na tela de login. O link acima também pode ser compartilhado como alternativa.':'Este link expira em 1 hora. Caso expire, o membro pode usar "Esqueci minha senha" na tela de login.'})]}):e.jsx("p",{className:"text-sm",style:{color:"var(--page-text-secondary)"},children:"O usuário já possuÃa conta no Firebase. Ele pode acessar a plataforma com as credenciais existentes."}),e.jsx("button",{onClick:()=>_e(null),className:"w-full mt-5 px-4 py-2.5 rounded-xl bg-brand-600 hover:bg-brand-500 text-sm font-semibold transition-all",children:"Entendido"})]})}),e.jsx(De,{open:!!X,onClose:()=>pe(null),title:"Editar Permissões",size:"md",icon:e.jsx(U,{className:"w-5 h-5"}),intent:"default",children:X&&e.jsxs(e.Fragment,{children:[g?e.jsx(as,{permissions:X.permissions,onChange:a=>pe({...X,permissions:a})}):e.jsx(es,{permissions:X.permissions,onChange:a=>pe({...X,permissions:a})}),e.jsxs("div",{className:"flex gap-3 mt-6",children:[e.jsx("button",{onClick:()=>pe(null),className:"flex-1 px-4 py-2.5 rounded-xl border border-slate-700 text-sm text-slate-300 hover:bg-slate-800 transition-colors",children:"Cancelar"}),e.jsxs("button",{disabled:Re,onClick:()=>{const a=fe(X.permissions),C=a==="custom"?X.currentRole:a;vs(X.uid,C,X.permissions)},className:"flex-1 px-4 py-2.5 rounded-xl bg-brand-600 hover:bg-brand-500 text-sm font-semibold transition-all disabled:opacity-50 flex items-center justify-center gap-2",children:[Re&&e.jsx(R,{className:"w-4 h-4 animate-spin"}),"Salvar Permissões"]})]})]})}),e.jsx(De,{open:!!P,onClose:()=>ue(null),title:P?P.type==="remove"?"Remover Membro":P.type==="deactivate"?"Desativar Membro":"Reativar Membro":"",description:P==null?void 0:P.name,size:"sm",icon:e.jsx(Q,{className:"w-5 h-5"}),intent:(P==null?void 0:P.type)==="reactivate"?"success":(P==null?void 0:P.type)==="deactivate"?"warning":"danger",children:P&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-slate-300 mb-5",children:P.type==="remove"?"Esta ação é irreversÃvel. O membro será permanentemente removido da organização e perderá acesso à plataforma.":P.type==="deactivate"?"O membro será desativado e perderá acesso à plataforma. Você poderá reativá-lo depois.":"O membro será reativado e poderá acessar a plataforma novamente."}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>ue(null),className:"flex-1 px-4 py-2.5 rounded-xl border border-slate-700 text-sm text-slate-300 hover:bg-slate-800 transition-colors",children:"Cancelar"}),e.jsxs("button",{onClick:Ns,disabled:Re,className:I("flex-1 px-4 py-2.5 rounded-xl text-sm font-semibold transition-all disabled:opacity-50 flex items-center justify-center gap-2",P.type==="remove"?"bg-red-600 hover:bg-red-500 text-white":P.type==="deactivate"?"bg-amber-600 hover:bg-amber-500 text-white":"bg-emerald-600 hover:bg-emerald-500 text-white"),children:[Re&&e.jsx(R,{className:"w-4 h-4 animate-spin"}),P.type==="remove"?"Remover":P.type==="deactivate"?"Desativar":"Reativar"]})]})]})}),e.jsxs("div",{className:"card",children:[e.jsxs("h3",{className:"text-sm font-semibold text-white mb-3 flex items-center gap-2",children:[e.jsx(U,{className:"w-4 h-4 text-brand-400"}),g?"Papéis":"Presets de Permissão"]}),g?e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"p-3 rounded-xl bg-slate-800/40 border border-slate-700/50",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(le,{className:"w-4 h-4 text-amber-400"}),e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:"Administrador"})]}),e.jsx("p",{className:"text-xs text-slate-400 leading-relaxed",children:"Acesso total: equipe, faturamento, fiscal, canais e configurações."})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-slate-800/40 border border-slate-700/50",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(Te,{className:"w-4 h-4 text-brand-400"}),e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:"Membro"})]}),e.jsx("p",{className:"text-xs text-slate-400 leading-relaxed",children:"Operação do dia a dia: pedidos, estoque, catálogo e conexões."})]})]}):e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"p-3 rounded-xl bg-slate-800/40 border border-slate-700/50",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(le,{className:"w-4 h-4 text-amber-400"}),e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:"Administrador"})]}),e.jsx("p",{className:"text-xs text-slate-400 leading-relaxed",children:"Leitura e escrita em todos os módulos, incluindo equipe, faturamento e configurações."})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-slate-800/40 border border-slate-700/50",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(za,{className:"w-4 h-4 text-brand-400"}),e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:"Gestor"})]}),e.jsx("p",{className:"text-xs text-slate-400 leading-relaxed",children:"Somente leitura nos módulos operacionais. Sem acesso a configurações e vinculações."})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-slate-800/40 border border-slate-700/50",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(oa,{className:"w-4 h-4 text-purple-400"}),e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:"Personalizado"})]}),e.jsx("p",{className:"text-xs text-slate-400 leading-relaxed",children:"Permissões ajustáveis por módulo: sem acesso, leitura ou leitura e escrita."})]})]})]}),e.jsx(De,{open:K,onClose:()=>Z(!1),title:"Adicionar Membro",description:"Membros da equipe estão inclusos no plano da organização. A cobrança é por veÃculo/mês.",size:"md",icon:e.jsx(Ve,{className:"w-5 h-5"}),intent:"default",children:e.jsxs(e.Fragment,{children:[$&&e.jsxs("div",{className:"flex items-center gap-2 p-3 mb-4 rounded-lg bg-red-500/10 border border-red-500/20",children:[e.jsx(te,{className:"w-4 h-4 text-red-400 flex-shrink-0"}),e.jsx("p",{className:"text-sm text-red-300",children:$})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-slate-300 mb-1.5 block",children:"E-mail *"}),e.jsxs("div",{className:"relative",children:[e.jsx(ke,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-500"}),e.jsx("input",{type:"email",value:b.email,onChange:a=>N({...b,email:a.target.value}),placeholder:"[email protected]",className:"input pl-10"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-slate-300 mb-1.5 block",children:"Nome"}),e.jsx("input",{type:"text",value:b.name,onChange:a=>N({...b,name:a.target.value}),placeholder:"Nome do membro",className:"input"})]}),g?e.jsx(as,{permissions:b.permissions,onChange:a=>{const C=fe(a);N({...b,permissions:a,role:C==="custom"?"fleet_manager":C})}}):e.jsx(es,{permissions:b.permissions,onChange:a=>{const C=fe(a);N({...b,permissions:a,role:C==="custom"?"fleet_manager":C})}})]}),e.jsxs("div",{className:"flex gap-3 mt-6",children:[e.jsx("button",{onClick:()=>Z(!1),className:"flex-1 px-4 py-2.5 rounded-xl border border-slate-700 text-sm text-slate-300 hover:bg-slate-800 transition-colors",children:"Cancelar"}),e.jsxs("button",{onClick:ys,disabled:E||!b.email,className:"flex-1 px-4 py-2.5 rounded-xl bg-brand-600 hover:bg-brand-500 text-sm font-semibold transition-all disabled:opacity-50 flex items-center justify-center gap-2",children:[E?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx(Ve,{className:"w-4 h-4"}),"Adicionar membro"]})]})]})})]}),v==="billing"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:I("card bg-gradient-to-br border",ie.color),children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-white/10 flex items-center justify-center",children:e.jsx(ie.icon,{className:"w-5 h-5 text-white"})}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-lg font-bold",style:{color:"var(--page-text)"},children:["Plano ",ie.label]}),e.jsxs("p",{className:"text-xs",style:{color:"var(--page-text-secondary)"},children:[ne?"Anual":"Mensal",ua&&e.jsx("span",{className:"ml-1.5 px-1.5 py-0.5 rounded-md bg-amber-500/15 text-amber-300 text-[10px] font-semibold uppercase tracking-wide",children:"Trial"})," · ",G.docsFiscais===999999?"docs ilimitados":`${G.docsFiscais} docs/mês`," · ",G.aiActions===999999?"IA ilimitada":`${G.aiActions} ações IA`]}
21)]})]}),e.jsx("div",{className:"text-right",children:be?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-2xl font-bold",style:{color:"var(--page-text)"},children:"Sob cotação"}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-secondary)"},children:"comercial responde em 24h"})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-2xl font-bold",style:{color:"var(--page-text)"},children:z(Ie)}),e.jsxs("p",{className:"text-xs",style:{color:"var(--page-text-secondary)"},children:["/mês",ne?" · fatura anual":""]})]})})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mt-3 pt-3 border-t border-white/10",children:[ne&&!be?e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-emerald-500/15 text-emerald-400 border border-emerald-500/20",children:"Economia ~20% vs mensal"}):e.jsx("span",{}),_&&e.jsxs("button",{type:"button",onClick:()=>pa(!0),className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold bg-white/10 hover:bg-white/15 text-white transition-colors",children:["Trocar plano",e.jsx(Ws,{className:"w-3.5 h-3.5"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs font-medium text-slate-400 uppercase tracking-wider",children:"Plano Sentinel"}),e.jsx(Ye,{className:"w-4 h-4 text-brand-400"})]}),e.jsx("p",{className:"text-xl font-bold",style:{color:"var(--page-text)"},children:be?"â":z(Ie)}),e.jsxs("p",{className:"text-xs text-slate-500 mt-1",children:["flat · ",ne?"fatura anual":"mensal"]})]}),e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs font-medium text-slate-400 uppercase tracking-wider",children:"Sentinel 365 App"}),e.jsx(We,{className:"w-4 h-4 text-emerald-400"})]}),e.jsx("p",{className:"text-xl font-bold",style:{color:"var(--page-text)"},children:Me>0?z(Me):"R$ 0,00"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:W&&ae>0?`${W.label} à ${ae} veÃc.`:"sem telemetria"})]}),e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs font-medium text-slate-400 uppercase tracking-wider",children:"Excedente IA"}),e.jsx(H,{className:"w-4 h-4 text-violet-400"})]}),e.jsx("p",{className:I("text-xl font-bold",oe>0?"text-amber-400":"text-white"),children:oe>0?`+${z(oe)}`:"R$ 0,00"}),e.jsxs("p",{className:"text-xs text-slate-500 mt-1",children:[((ya=m==null?void 0:m.ai)==null?void 0:ya.overageActions)??0," ações excedentes"]})]}),e.jsxs("div",{className:"card bg-gradient-to-br from-brand-600/10 to-brand-800/5 border-brand-500/20",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs font-medium text-slate-400 uppercase tracking-wider",children:"Total Estimado"}),e.jsx(Ce,{className:"w-4 h-4 text-brand-400"})]}),e.jsx("p",{className:"text-xl font-bold text-brand-400",children:be?"â":z(ha)}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:ua?"em trial · sem cobrança":(m==null?void 0:m.paymentMethod)==="credit_card"?"Cartão":(m==null?void 0:m.paymentMethod)==="pix"?"Pix":(m==null?void 0:m.paymentMethod)==="boleto"?"Boleto":"método pendente"})]})]}),e.jsx("div",{className:"card bg-amber-500/5 border border-amber-500/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(te,{className:"w-5 h-5 text-amber-400 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs space-y-1.5",style:{color:"var(--page-text-secondary)"},children:[e.jsx("p",{className:"font-semibold text-amber-300",children:"Sobre a sua fatura"}),e.jsxs("p",{children:[e.jsx("strong",{children:"Fatura Stripe (esta tela):"})," Plano Sentinel 365 Web + Sentinel 365 App + excedente de documentos fiscais (Focus NFE) + excedente IA."]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Faturado separadamente pela Extratta:"})," CIOT (pacote mÃnimo mensal) e VPO (% do uso de vale-pedágio). Esses valores chegam direto no seu e-mail pela Extratta e ",e.jsx("em",{children:"não aparecem"})," nas faturas Stripe abaixo."]})]})]})}),e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(H,{className:"w-5 h-5 text-violet-400"}),e.jsx("h2",{className:"text-lg font-semibold text-white",children:"Consumo de IA"})]}),(()=>{var Ne,ye,we,Da;
21const a=((Ne=m==null?void 0:m.ai)==null?void 0:Ne.used)??0,C=G.aiActions||((ye=m==null?void 0:m.ai)==null?void 0:ye.quota)||0,L=Math.max(0,C-a),se=C>0?Math.min(a/C*100,100):0,J=a>C,Ze=J||se>80?"bg-amber-500":"bg-violet-500";return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-end justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-3xl font-bold",style:{color:"var(--page-text)"},children:a}),e.jsxs("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:["ações usadas de ",C===999999?"â":C," incluÃdas"]})]}),e.jsx("div",{className:"text-right",children:e.jsx("p",{className:I("text-lg font-semibold",J?"text-amber-400":"text-emerald-400"),children:J?`+${a-C} excedente`:`${L} restantes`})})]}),e.jsx("div",{className:"w-full h-3 rounded-full bg-slate-800 overflow-hidden",children:e.jsx("div",{className:I("h-full rounded-full transition-all duration-500",Ze),style:{width:`${Math.min(se,100)}%`}})}),e.jsxs("div",{className:"flex items-center justify-between text-xs",style:{color:"var(--page-text-muted)"},children:[e.jsx("span",{children:"0"}),e.jsx("span",{children:C===999999?"Ilimitado":C})]}),J&&e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-amber-500/5 border border-amber-500/15",children:[e.jsx(Q,{className:"w-4 h-4 text-amber-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-amber-300",children:"Cota de IA excedida"}),e.jsxs("p",{className:"text-xs text-slate-400 mt-0.5",children:[((we=m==null?void 0:m.ai)==null?void 0:we.overageActions)??0," ação(ões) excedente(s) geraram ",z(oe)," em custos adicionais.",((Da=m==null?void 0:m.ai)==null?void 0:Da.overageEnabled)===!1&&" O excedente está desativado â novas ações serão bloqueadas."]})]})]})]})})()]}),e.jsxs("div",{className:"card",children:[e.jsxs("button",{onClick:()=>cs(!qe),className:"w-full flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{className:"w-5 h-5 text-brand-400"}),e.jsx("h2",{className:"text-lg font-semibold text-white",children:"Detalhamento de Custos"})]}),qe?e.jsx(Ka,{className:"w-5 h-5 text-slate-400"}):e.jsx(Ua,{className:"w-5 h-5 text-slate-400"})]}),qe&&e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsx($e,{className:"w-3.5 h-3.5 text-brand-400"}),e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-brand-300",children:"Fatura Stripe"}),e.jsx("div",{className:"flex-1 h-px bg-brand-500/20"})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-slate-800/40",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ye,{className:"w-5 h-5 text-brand-400"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:["Plano ",ie.label,ne?" Anual":" Mensal"]}),e.jsxs("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:[G.docsFiscais===999999?"Docs fiscais ilimitados":`${G.docsFiscais} docs fiscais/mês`," · ",G.aiActions===999999?"Ações IA ilimitadas":`${G.aiActions} ações IA/mês`]})]})]}),e.jsx("div",{className:"text-right",children:e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:be?"Sob cotação":z(Ie)})})]}),W&&ae>0&&e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-slate-800/40",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(We,{className:"w-5 h-5 text-emerald-400"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:["Sentinel 365 App · ",W.label]}),e.jsxs("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:[z(W.perVehicle),"/veÃculo à ",ae," ",ae===1?"veÃculo":"veÃculos"]})]})]}),e.jsx("div",{className:"text-right",children:e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:z(Me)})})]}),oe>0&&e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-slate-800/40",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(H,{className:"w-5 h-5 text-violet-400"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:["Ações de IA excedentes (",((wa=m==null?void 0:m.ai)==null?void 0:wa.overageActions)??0,")"]}),e.jsxs("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:["Cota: ",G.aiActions===999999?"â":G.aiActions," incluÃdas/mês"]})]})]}),e.jsx("div",{className:"text-right",children:e.jsxs("p",{className:"text-sm font-medium text-amber-400",children:["+",z(oe)]})})]}),((Ca=m==null?void 0:m.focusNfe)==null?void 0:Ca.overageCost)>0&&e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-slate-800/40",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ge,{className:"w-5 h-5 text-blue-400"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"}
21,children:["Documentos fiscais excedentes (",((ka=m==null?void 0:m.focusNfe)==null?void 0:ka.overageCount)??0,")"]}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"CT-e, MDF-e, NF-e via Focus NFE acima do plano"})]})]}),e.jsx("div",{className:"text-right",children:e.jsxs("p",{className:"text-sm font-medium text-amber-400",children:["+",z(((Sa=m==null?void 0:m.focusNfe)==null?void 0:Sa.overageCost)??0)]})})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-brand-500/5 border border-brand-500/15",children:[e.jsx("p",{className:"text-sm font-semibold",style:{color:"var(--page-text)"},children:"Subtotal Stripe (mensal)"}),e.jsx("p",{className:"text-lg font-bold text-brand-400",children:be?"â":z(ha)})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-4",children:[e.jsx(re,{className:"w-3.5 h-3.5 text-amber-400"}),e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-amber-300",children:"Cobranças separadas · Extratta"}),e.jsx("div",{className:"flex-1 h-px bg-amber-500/20"})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-amber-500/5 border border-amber-500/15",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ce,{className:"w-5 h-5 text-amber-400"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:"CIOT · pacote mÃnimo mensal"}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"Faturado direto pela Extratta · valor por contrato"})]})]}),e.jsx("div",{className:"text-right",children:e.jsx("p",{className:"text-xs italic text-slate-500",children:"fora desta fatura"})})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-amber-500/5 border border-amber-500/15",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ce,{className:"w-5 h-5 text-amber-400"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:"VPO · % sobre uso de vale-pedágio"}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"Faturado direto pela Extratta · proporcional ao consumo"})]})]}),e.jsx("div",{className:"text-right",children:e.jsx("p",{className:"text-xs italic text-slate-500",children:"fora desta fatura"})})]})]})]}),e.jsxs("div",{className:"card",children:[e.jsxs("button",{onClick:()=>ds(!ze),className:"w-full flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ge,{className:"w-5 h-5 text-brand-400"}),e.jsx("h2",{className:"text-lg font-semibold text-white",children:"Histórico de Faturas"}),A.length>0&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-slate-700 text-slate-300",children:A.length})]}),ze?e.jsx(Ka,{className:"w-5 h-5 text-slate-400"}):e.jsx(Ua,{className:"w-5 h-5 text-slate-400"})]}),ze&&e.jsx("div",{className:"mt-4",children:A.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(ge,{className:"w-10 h-10 text-slate-600 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-slate-500",children:"Nenhuma fatura emitida ainda."})]}):e.jsx("div",{className:"space-y-2",children:A.map(a=>{const C={paid:{label:"Paga",color:"bg-emerald-500/15 text-emerald-400 border-emerald-500/20"},pending:{label:"Pendente",color:"bg-amber-500/15 text-amber-400 border-amber-500/20"},overdue:{label:"Vencida",color:"bg-red-500/15 text-red-400 border-red-500/20"},cancelled:{label:"Cancelada",color:"bg-slate-500/15 text-slate-400 border-slate-500/20"}},L=C[a.status]||C.pending;return e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl bg-slate-800/30 hover:bg-slate-800/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-slate-700/50 flex items-center justify-center",children:e.jsx(ge,{className:"w-4 h-4 text-slate-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:a.period||"â"}),e.jsxs("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:["Venc. ",de(a.dueDate),a.paidAt&&` · Pago em ${de(a.paidAt)}`]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:I("text-xs font-medium px-2.5 py-1 rounded-lg border",L.color),children:L.label}),e.jsx("p",{className:"text-sm font-semibold text-white w-28 text-right",children:z(a.amount||0)}),a.boletoUrl&&e.jsx("a",{href:a.boletoUrl,target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded-lg hover:bg-slate-700 transition-colors text-slate-400 hover:text-white",title:"Abrir boleto",children:e.jsx(re,{className:"w-4 h-4"})})]})]},a.id)})})})]}),e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx($e,{className:"w-5 h-5 text-brand-400"}),e.jsx("h2",{className:"text-lg font-semibold text-white",children:"Pagamento e Assinatura"})]}),M!=null&&M.hasSubscription?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4 p-4 rounded-xl bg-slate-800/40 border border-slate-700/50",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-emerald-500/10 flex items-center justify-center",children:e.jsx($e,{className:"w-6 h-6 text-emerald-400"})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:"Assinatura Stripe Ativa"}),e.jsx("span",{className:I("text-[10px] font-medium px-2 py-0.5 rounded-full",M.cancelAtPeriodEnd?"bg-amber-500/15 text-amber-400 border border-amber-500/20":M.status==="active"?"bg-emerald-500/15 text-emerald-400 border border-emerald-500/20":"bg-red-500/15 text-red-400 border border-red-500/20"),children:M.cancelAtPeriodEnd?"Cancelamento agendado":M.status==="active"?"Ativa":M.status==="past_due"?"Pagamento pendente":M.status})]}),e.jsxs("p",{className:"text-xs text-slate-500 mt-0.5",children:[M.currentPeriodEnd&&`Próxima renovação: ${de(M.currentPeriodEnd)}`,M.cancelAtPeriodEnd&&M.cancelAt&&` · Cancela em ${de(M.cancelAt)}`]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[_&&e.jsxs("button",{onClick:async()=>{ee(!0);try{const{url:a}=await j.stripePortal(window.location.href);window.location.href=a}catch(a){D(a.message,"error")}finally{ee(!1)}},disabled:he,className:"flex items-center gap-2 px-4 py-2.5 rounded-xl bg-slate-700 hover:bg-slate-600 text-sm font-medium text-white transition-all disabled:opacity-50",children:[he?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx(re,{className:"w-4 h-4"}),"Gerenciar no Stripe"]}),_&&M.cancelAtPeriodEnd&&e.jsxs("button",{onClick:async()=>{ee(!0);try{await j.stripeReactivateSubscription(),D("Assinatura reativada com sucesso"),j.stripeSubscriptionStatus().then(He).catch(()=>{})}catch(a){D(a.message,"error")}finally{ee(!1)}},disabled:he,className:"flex items-center gap-2 px-4 py-2.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-sm font-medium text-white transition-all disabled:opacity-50",children:[e.jsx(Y,{className:"w-4 h-4"}),"Reativar Assinatura"]}),_&&!M.cancelAtPeriodEnd&&M.status==="active"&&e.jsxs("button",{onClick:async()=>
21{if(await o({titulo:"Cancelar a assinatura?",descricao:"Ela permanece ativa até o final do perÃodo atual.",confirmar:"Cancelar assinatura",cancelar:"Manter",tom:"neutro"})){ee(!0);try{await j.stripeCancelSubscription(),D("Cancelamento agendado para o final do perÃodo"),j.stripeSubscriptionStatus().then(He).catch(()=>{})}catch(a){D(a.message,"error")}finally{ee(!1)}}},disabled:he,className:"flex items-center gap-2 px-4 py-2.5 rounded-xl border border-red-500/30 text-sm font-medium text-red-400 hover:bg-red-500/10 transition-all disabled:opacity-50",children:[e.jsx(ra,{className:"w-4 h-4"}),"Cancelar Assinatura"]})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4 p-4 rounded-xl bg-slate-800/40 border border-slate-700/50",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-blue-500/10 flex items-center justify-center",children:e.jsx(ge,{className:"w-6 h-6 text-blue-400"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:(m==null?void 0:m.paymentMethod)==="credit_card"?"Cartão de Crédito":(m==null?void 0:m.paymentMethod)==="pix"?"Pix":"Boleto Bancário"}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:m!=null&&m.nextInvoiceDate?`Próxima fatura: ${de(m.nextInvoiceDate)}`:"Vencimento dia 10 de cada mês"})]})]}),_&&e.jsxs("button",{onClick:async()=>{ee(!0);try{const{url:a}=await j.stripeCreateCheckout({plan:S.plan||"conecta",vehicleCount:gs||1,billingCycle:(m==null?void 0:m.billingCycle)||"monthly"});window.location.href=a}catch(a){D(a.message,"error")}finally{ee(!1)}},disabled:he,className:"flex items-center gap-2 px-5 py-3 rounded-xl bg-gradient-to-r from-brand-600 to-violet-600 hover:from-brand-500 hover:to-violet-500 text-sm font-semibold text-white transition-all disabled:opacity-50 shadow-lg shadow-brand-600/20",children:[he?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx($e,{className:"w-4 h-4"}),"Ativar Pagamento com Cartão de Crédito"]})]})]}),e.jsxs("div",{className:"flex items-start gap-3 p-4 rounded-xl bg-slate-800/40 border border-slate-700/50",children:[e.jsx(te,{className:"w-5 h-5 text-slate-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-slate-300",children:"Dúvidas sobre faturamento?"}),e.jsxs("p",{className:"text-xs text-slate-500 mt-1",children:["Entre em contato com a Sentinel AI pelo e-mail ",e.jsx("span",{className:"text-brand-400",children:"[email protected]"}),"."]})]})]}),e.jsx(mt,{isAdmin:_,onToast:D}),e.jsx(it,{open:bs,onClose:()=>pa(!1),current:{planLookupKey:((Aa=S==null?void 0:S.billingIntent)==null?void 0:Aa.planLookupKey)||Le.lookupKey,appTier:Qe??null,appVehicles:ae,annual:ne},organizationId:n||"",hasActiveSubscription:!!(M!=null&&M.hasSubscription),onToast:D})]}),v==="audit"&&e.jsx(ft,{orgId:n||""}),v==="help"&&e.jsx(jt,{}),v==="account"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(Te,{className:"w-5 h-5 text-brand-400"}),e.jsx("h2",{className:"text-lg font-semibold text-white",children:"Dados da Conta"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4 p-4 rounded-xl bg-slate-800/40 border border-slate-700/50",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-brand-600/15 flex items-center justify-center text-xl font-bold text-brand-400",children:(((Ta=t==null?void 0:t.displayName)==null?void 0:Ta[0])||((Ea=t==null?void 0:t.email)==null?void 0:Ea[0])||"?").toUpperCase()}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-base font-semibold",style:{color:"var(--page-text)"},children:(t==null?void 0:t.displayName)||((Pa=t==null?void 0:t.email)==null?void 0:Pa.split("@")[0])}),e.jsx("p",{className:"text-sm",style:{color:"var(--page-text-secondary)"},children:t==null?void 0:t.email}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[e.jsx("span",{className:I("text-xs font-medium px-2.5 py-1 rounded-lg border",c==="fleet_admin"?"bg-amber-500/15 text-amber-400 border-amber-500/20":c==="super_admin"?"bg-purple-500/15 text-purple-400 border-purple-500/20":"bg-brand-500/15 text-brand-400 border-brand-500/20"),children:c==="fleet_admin"?"Administrador":c==="super_admin"?"Super Admin":"Gestor"}),(t==null?void 0:t.emailVerified)&&e.jsxs("span",{className:"text-xs text-emerald-400 flex items-center gap-1",children:[e.jsx(Y,{className:"w-3 h-3"})," E-mail verificado"]}
21)]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"p-3 rounded-xl bg-slate-800/30 border border-slate-700/50",children:[e.jsxs("p",{className:"text-xs text-slate-500 mb-1 flex items-center gap-1.5",children:[e.jsx(_a,{className:"w-3 h-3"})," User ID"]}),e.jsx("p",{className:"text-xs text-slate-300 font-mono select-all truncate",children:t==null?void 0:t.uid})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-slate-800/30 border border-slate-700/50",children:[e.jsxs("p",{className:"text-xs text-slate-500 mb-1 flex items-center gap-1.5",children:[e.jsx(qa,{className:"w-3 h-3"})," Conta criada em"]}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text)"},children:(Ra=t==null?void 0:t.metadata)!=null&&Ra.creationTime?new Date(t.metadata.creationTime).toLocaleDateString("pt-BR",{day:"2-digit",month:"short",year:"numeric"}):"â"})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-slate-800/30 border border-slate-700/50",children:[e.jsxs("p",{className:"text-xs text-slate-500 mb-1 flex items-center gap-1.5",children:[e.jsx(os,{className:"w-3 h-3"})," Ãltimo login"]}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text)"},children:(Fa=t==null?void 0:t.metadata)!=null&&Fa.lastSignInTime?new Date(t.metadata.lastSignInTime).toLocaleDateString("pt-BR",{day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}):"â"})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-slate-800/30 border border-slate-700/50",children:[e.jsxs("p",{className:"text-xs text-slate-500 mb-1 flex items-center gap-1.5",children:[e.jsx(U,{className:"w-3 h-3"})," Provedor"]}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text)"},children:((Ia=(La=t==null?void 0:t.providerData)==null?void 0:La[0])==null?void 0:Ia.providerId)==="password"?"E-mail e Senha":((Ma=(Oa=t==null?void 0:t.providerData)==null?void 0:Oa[0])==null?void 0:Ma.providerId)||"Firebase Auth"})]})]})]})]}),e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(ns,{className:"w-5 h-5 text-brand-400"}),e.jsx("h2",{className:"text-lg font-semibold text-white",children:"Segurança"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-xl bg-slate-800/40 border border-slate-700/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:"Redefinir senha"}),e.jsxs("p",{className:"text-xs text-slate-500 mt-0.5",children:["Enviaremos um link de redefinição para ",t==null?void 0:t.email]})]}),e.jsx("button",{onClick:ws,disabled:ma||Ue,className:I("flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all",Ue?"bg-emerald-500/15 text-emerald-400 border border-emerald-500/20":"bg-brand-600 hover:bg-brand-500 text-white"),children:ma?e.jsx(R,{className:"w-4 h-4 animate-spin"}):Ue?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"w-4 h-4"})," Enviado"]}):e.jsxs(e.Fragment,{children:[e.jsx(ke,{className:"w-4 h-4"})," Enviar link"]})})]}),e.jsxs("div",{className:"flex items-start gap-3 p-4 rounded-xl bg-slate-800/40 border border-slate-700/50",children:[e.jsx(U,{className:"w-5 h-5 text-slate-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:"Autenticação"}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:"Sua conta é protegida pelo Firebase Authentication com criptografia end-to-end. As credenciais nunca são armazenadas na plataforma Sentinel 365."})]})]})]})]}),e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(Ys,{className:"w-5 h-5 text-brand-400"}),e.jsx("h2",{className:"text-lg font-semibold text-white",children:"Sessão"})]}),e.jsxs("div",{className:"flex items-start gap-3 p-4 rounded-xl bg-red-500/5 border border-red-500/15",children:[e.jsx(Q,{className:"w-5 h-5 text-red-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-red-300",children:"Encerrar sessão"}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:"Você será desconectado da plataforma e precisará fazer login novamente."})]})]})]})]})]})}function Ot({orgId:s}){const{confirmar:l}=Ee(),{data:o,loading:c,refetch:t}=me(()=>j.serproConfig(),[]),[n,d]=r.useState({consumerKey:"",consumerSecret:"",environment:"hom"}),[h,p]=r.useState(!1),[x,u]=r.useState(""),[y,f]=r.useState(""),[A,F]=r.useState(null),[w,k]=r.useState(!1),i=async()=>{p(!0),u("");try{const T=await j.serproSaveConfig(n);u(T.hasCertificate?"Configurado com sucesso! Certificado A1 detectado.":"Configurado! Atenção: cadastre o Certificado A1 na aba anterior para autenticação mTLS."),d({consumerKey:"",consumerSecret:"",environment:"hom"}),t()}catch(T){u(T.message||"Erro")}finally{p(!1)}},O=async()=>
21{if(y.trim()){k(!0),F(null);try{const T=await j.serproVeiculo(y.trim().toUpperCase());F({success:!0,data:T})}catch(T){F({success:!1,error:T.message})}finally{k(!1)}}},v=async()=>{if(await l({titulo:"Remover a configuração SERPRO?",descricao:"As consultas param até reconfigurar.",confirmar:"Remover"}))try{await j.serproDeleteConfig(),t()}catch{}};return c?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(R,{className:"w-6 h-6 animate-spin text-brand-500"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-xl p-4 flex items-start gap-3",style:{background:"#eff6ff",border:"1px solid #bfdbfe"},children:[e.jsx(U,{className:"w-5 h-5 flex-shrink-0 mt-0.5",style:{color:"#2563eb"}}),e.jsxs("div",{className:"text-sm",style:{color:"#1e40af"},children:[e.jsx("p",{className:"font-medium",children:"Integração SERPRO / SENATRAN"}),e.jsx("p",{className:"mt-1",children:"Conecta a plataforma aos sistemas oficiais de trânsito: RENAVAM (veÃculos), RENACH (condutores) e RENAINF (infrações). Requer Termo de Autorização do SENATRAN + contrato com SERPRO."})]})]}),o!=null&&o.configured?e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx(Y,{className:"w-6 h-6",style:{color:"#059669"}}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-semibold",style:{color:"var(--page-text)"},children:"SERPRO configurado"}),e.jsxs("p",{className:"text-sm",style:{color:"var(--page-text-secondary)"},children:["Ambiente: ",o.environment==="prod"?"Produção":"Homologação"," · Consumer Key: ",o.consumerKeyPartial," · Certificado: ",o.hasCertificate?"â
":"â"]})]}),e.jsx("button",{onClick:v,className:"btn-danger text-sm",children:"Remover"})]}),e.jsxs("div",{className:"pt-4",style:{borderTop:"1px solid var(--border-primary)"},children:[e.jsx("h4",{className:"text-sm font-semibold mb-2",style:{color:"var(--page-text)"},children:"Testar consulta RENAVAM"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{className:"input flex-1",placeholder:"Placa do veÃculo (ex: ABC1D23)",value:y,onChange:T=>f(T.target.value.toUpperCase()),style:{textTransform:"uppercase"}}),e.jsxs("button",{onClick:O,disabled:w||!y.trim(),className:"btn-primary flex items-center gap-2",children:[w?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx(ls,{className:"w-4 h-4"})," Consultar"]})]}),A&&e.jsx("div",{className:"mt-3 p-3 rounded-lg text-xs font-mono overflow-auto max-h-48",style:{background:"var(--surface-tertiary)",color:"var(--page-text)"},children:A.success?JSON.stringify(A.data,null,2):e.jsxs("span",{style:{color:"#dc2626"},children:["Erro: ",A.error]})})]})]}):e.jsxs("div",{className:"card space-y-4",children:[e.jsx("h3",{className:"font-semibold",style:{color:"var(--page-text)"},children:"Configurar credenciais SERPRO"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"label text-sm block mb-1.5",children:"Consumer Key *"}),e.jsx("input",{className:"input",style:{textTransform:"none"},placeholder:"Fornecido pelo SERPRO",value:n.consumerKey,onChange:T=>d(V=>({...V,consumerKey:T.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label text-sm block mb-1.5",children:"Consumer Secret *"}),e.jsx("input",{className:"input",type:"password",style:{textTransform:"none"},placeholder:"Fornecido pelo SERPRO",value:n.consumerSecret,onChange:T=>d(V=>({...V,consumerSecret:T.target.value}))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label text-sm block mb-1.5",children:"Ambiente"}),e.jsxs("select",{className:"input",value:n.environment,onChange:T=>d(V=>({...V,environment:T.target.value})),children:[e.jsx("option",{value:"hom",children:"Homologação (teste)"}),e.jsx("option",{value:"prod",children:"Produção"})]})]}),x&&e.jsx("p",{className:"text-sm p-3 rounded-lg",style:{background:x.includes("sucesso")?"#ecfdf5":"#fef2f2",color:x.includes("sucesso")?"#059669":"#dc2626"},children:x}),e.jsxs("button",{onClick:i,disabled:h||!n.consumerKey||!n.consumerSecret,className:"btn-primary w-full flex items-center justify-center gap-2",children:[h?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx(U,{className:"w-4 h-4"})," Salvar Configuração"]})]}),e.jsxs("div",{className:"card",children:[e.jsx("h3",{className:"text-sm font-semibold mb-3",style:{color:"var(--page-text)"},children:"O que esta integração habilita"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[{title:"Auto-fill de VeÃculos",desc:"Ao cadastrar um veÃculo pela placa, o sistema preenche automaticamente marca, modelo, ano, cor e combustÃvel via RENAVAM."},{title:"Validação de CNH",desc:"Verifica validade, categoria, pontuação e bloqueios da CNH de cada motorista via RENACH."},{title:"Monitoramento de Multas",desc:"Consulta e monitora infrações de trânsito dos veÃculos da frota via RENAINF e e-Frotas."},{title:"Alertas de Restrições",desc:"Detecta restrições judiciais, furto/roubo, financiamento e bloqueios nos veÃculos."}].map(T=>e.jsxs("div",{className:"p-3 rounded-lg",style:{background:"var(--surface-secondary)"},children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:T.title}),e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--page-text-muted)"},children:T.desc})]},T.title))})]})]})}function Mt(){const{confirmar:s}=Ee(),{data:l,loading:o,refetch:c}
21=me(()=>j.extrattaConfig(),[]),[t,n]=r.useState({token:"",cnpjAplicacao:"",environment:"hom"}),[d,h]=r.useState(!1),[p,x]=r.useState(""),[u,y]=r.useState(null),[f,A]=r.useState(!1),F=async()=>{h(!0),x("");try{await j.extrattaSaveConfig(t),x("Configurado com sucesso!"),n({token:"",cnpjAplicacao:"",environment:"hom"}),c()}catch(i){x(i.message||"Erro ao salvar")}finally{h(!1)}},w=async()=>{A(!0),y(null);try{const i=await j.extrattaTest();y({success:!!(i!=null&&i.ok),data:i})}catch(i){y({success:!1,error:i.message})}finally{A(!1)}},k=async()=>{if(await s({titulo:"Remover a configuração Extratta?",descricao:"A emissão de CIOT fica desabilitada para toda a plataforma.",confirmar:"Remover"}))try{await j.extrattaDeleteConfig(),c()}catch{}};return o?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(R,{className:"w-6 h-6 animate-spin text-brand-500"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-xl p-4 flex items-start gap-3",style:{background:"#eff6ff",border:"1px solid #bfdbfe"},children:[e.jsx(U,{className:"w-5 h-5 flex-shrink-0 mt-0.5",style:{color:"#2563eb"}}),e.jsxs("div",{className:"text-sm",style:{color:"#1e40af"},children:[e.jsx("p",{className:"font-medium",children:"Integração Extratta â CIOT, Pagamentos e Pedágio"}),e.jsx("p",{className:"mt-1",children:"Conecta a plataforma à Extratta (meio homologado pela ANTT) para emissão automática de CIOT (Padrão e TAC Agregado), Pagamento Eletrônico de Frete (PEF), Vale-Pedágio em 6 tags, rede de abastecimento (TicketLog, Shell Expers, Truckpag), PIX e diárias. A configuração é global â cada transportadora usa automaticamente o próprio CNPJ cadastrado."})]})]}),l!=null&&l.configured?e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx(Y,{className:"w-6 h-6",style:{color:"#059669"}}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-semibold",style:{color:"var(--page-text)"},children:"Extratta configurada"}),e.jsxs("p",{className:"text-sm",style:{color:"var(--page-text-secondary)"},children:["Ambiente: ",l.environment==="prod"?"Produção":"Homologação"," · CNPJ Aplicação: ",l.cnpjAplicacaoPartial]})]}),e.jsx("button",{onClick:k,className:"btn-danger text-sm",children:"Remover"})]}),e.jsxs("div",{className:"pt-4",style:{borderTop:"1px solid var(--border-primary)"},children:[e.jsx("h4",{className:"text-sm font-semibold mb-2",style:{color:"var(--page-text)"},children:"Testar conexão"}),e.jsx("p",{className:"text-xs mb-3",style:{color:"var(--page-text-muted)"},children:"Verifica se as credenciais estão ativas e consulta os endpoints de produção/homologação."}),e.jsxs("button",{onClick:w,disabled:f,className:"btn-primary flex items-center gap-2",children:[f?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx(ls,{className:"w-4 h-4"}),"Testar agora"]}),u&&e.jsx("div",{className:"mt-3 p-3 rounded-lg text-xs font-mono overflow-auto max-h-48",style:{background:"var(--surface-tertiary)",color:"var(--page-text)"},children:u.success?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#059669"},children:"â Conexão OK"}),e.jsx("br",{}),JSON.stringify(u.data,null,2)]}):e.jsxs("span",{style:{color:"#dc2626"},children:["â Erro: ",u.error]})})]})]}):e.jsxs("div",{className:"card space-y-4",children:[e.jsx("h3",{className:"font-semibold",style:{color:"var(--page-text)"},children:"Configurar credenciais Extratta"}),e.jsxs("div",{children:[e.jsx("label",{className:"label text-sm block mb-1.5",children:"Token *"}),e.jsx("input",{className:"input",type:"password",style:{textTransform:"none"},placeholder:"Token fornecido pela Extratta",value:t.token,onChange:i=>n(O=>({...O,token:i.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label text-sm block mb-1.5",children:"CNPJ Aplicação *"}),e.jsx("input",{className:"input",style:{textTransform:"none"},placeholder:"CNPJ cadastrado junto à Extratta (14 dÃgitos)",value:t.cnpjAplicacao,onChange:i=>n(O=>({...O,cnpjAplicacao:i.target.value})),maxLength:18})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label text-sm block mb-1.5",children:"Ambiente"}),e.jsxs("select",{className:"input",value:t.environment,onChange:i=>n(O=>({...O,environment:i.target.value})),children:[e.jsx("option",{value:"hom",children:"Homologação (teste)"}),e.jsx("option",{value:"prod",children:"Produção"})]})]}),p&&e.jsx("p",{className:"text-sm p-3 rounded-lg",style:{background:p.includes("sucesso")?"#ecfdf5":"#fef2f2",color:p.includes("sucesso")?"#059669":"#dc2626"},children:p}),e.jsxs("button",{onClick:F,disabled:d||!t.token||!t.cnpjAplicacao,className:"btn-primary w-full flex items-center justify-center gap-2",children:[d?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx(U,{className:"w-4 h-4"}),"Salvar Configuração"]})]}),e.jsxs("div",{className:"card",children:[e.jsx("h3",{className:"text-sm font-semibold mb-3",style:{color:"var(--page-text)"},children:"O que esta integração habilita"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[{title:"Emissão automática de CIOT",desc:"Declara CIOT Padrão ou TAC Agregado para cada frete em 1 clique, sem retrabalho com cadastros. Os cadastros de motorista, proprietário, veÃculo e cliente são enviados junto."}
21,{title:"Pagamento Eletrônico de Frete (PEF)",desc:"Adiantamento, saldo e estadia liberados no cartão ou conta virtual do motorista. Com IRRF, INSS e SEST/SENAT calculados e retidos automaticamente."},{title:"Vale-Pedágio Obrigatório (6 fornecedores)",desc:"Carga automática de pedágio em Sem Parar, Move Mais, Veloe, Tag Extratta, ConectCar e Taggy Edenred. Cálculo de rota por quantidade de eixos."},{title:"Rede de Abastecimento",desc:"Postos credenciados TicketLog, Shell Expers e Truckpag â autorização no cartão do motorista e extrato consolidado para conciliação."},{title:"PIX para autônomos",desc:"Pagamento do frete direto na chave PIX do proprietário, sem cartão Extratta, quando o cliente tem o serviço contratado."},{title:"Diárias e despesas de viagem",desc:"Carga avulsa no cartão Extratta para despesas do motorista em viagem, com estorno rastreável."}].map(i=>e.jsxs("div",{className:"p-3 rounded-lg",style:{background:"var(--surface-secondary)"},children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:i.title}),e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--page-text-muted)"},children:i.desc})]},i.title))})]}),(l==null?void 0:l.configured)&&e.jsx(gt,{})]})}function gt(){const{data:s,loading:l}=me(()=>j.extrattaListarCiots(),[]);if(l)return null;const o=(s==null?void 0:s.ciots)||[];return o.length?e.jsxs("div",{className:"card",children:[e.jsx("h3",{className:"text-sm font-semibold mb-3",style:{color:"var(--page-text)"},children:"CIOTs recentes da sua organização"}),e.jsx("div",{className:"space-y-2",children:o.slice(0,10).map(c=>e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg text-xs",style:{background:"var(--surface-secondary)"},children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-mono font-semibold",style:{color:"var(--page-text)"},children:c.ciot}),e.jsx("span",{className:"mx-2",style:{color:"var(--page-text-muted)"},children:"·"}),e.jsx("span",{style:{color:"var(--page-text-secondary)"},children:c.tipoCiot==="tac_agregado"?"TAC Agregado":"Padrão"}),c.emContingencia&&e.jsx("span",{className:"ml-2 px-2 py-0.5 rounded-full text-[10px]",style:{background:"#fef3c7",color:"#92400e"},children:"Contingência"})]}),e.jsx("span",{style:{color:"var(--page-text-muted)"},children:c.dataDeclaracao?new Date(c.dataDeclaracao).toLocaleDateString("pt-BR"):"â"})]},c.id))})]}):null}function ft({orgId:s}){const[l,o]=r.useState([]),[c,t]=r.useState(!0);return r.useEffect(()=>{s&&(async()=>{try{const n=await j.auditLog();o(Array.isArray(n)?n:(n==null?void 0:n.events)||[])}catch{o([])}t(!1)})()},[s]),c?e.jsx("div",{className:"card p-8 text-center",children:e.jsx(R,{className:"w-6 h-6 animate-spin mx-auto",style:{color:"var(--page-text-muted)"}})}):e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"card p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center",style:{background:"rgba(99,102,241,0.12)"},children:e.jsx(sa,{className:"w-5 h-5",style:{color:"#6366F1"}})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold",style:{color:"var(--page-text)"},children:"Histórico de ações da sua empresa"}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"Ãltimas 30 ações realizadas pela sua equipe (quem alterou o quê e quando)"})]})]}),l.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(sa,{className:"w-10 h-10 mx-auto mb-3",style:{color:"var(--page-text-muted)"}}),e.jsx("p",{className:"text-sm",style:{color:"var(--page-text-muted)"},children:"Nenhuma ação registrada ainda"})]}):e.jsx("div",{className:"divide-y",style:{borderColor:"var(--border-primary)"},children:l.map((n,d)=>e.jsxs("div",{className:"py-3 flex items-start gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center shrink-0 mt-0.5",style:{background:"var(--surface-secondary)"},children:e.jsx(Te,{className:"w-4 h-4",style:{color:"var(--page-text-muted)"}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-sm",style:{color:"var(--page-text)"},children:[e.jsx("span",{className:"font-semibold",children:n.userName||n.userEmail||"Usuário"})," ",e.jsx("span",{style:{color:"var(--page-text-muted)"},children:n.description||n.action})]}),e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--page-text-muted)"}
21,children:n.createdAt?new Date(n.createdAt).toLocaleString("pt-BR"):""})]})]},n.id||d))})]})})}function jt(){const s=[{icon:is,color:"#3B82F6",title:"Manual de Uso",desc:"Guia completo da plataforma com exemplos práticos",action:"Abrir manual",onClick:()=>window.open("https://sentinel365.com.br/manual","_blank")},{icon:ss,color:"#10B981",title:"Perguntas Frequentes",desc:"Respostas rápidas para as dúvidas mais comuns",action:"Ver FAQ",onClick:()=>window.open("https://sentinel365.com.br/faq","_blank")},{icon:at,color:"#8B5CF6",title:"Contatar Suporte",desc:"WhatsApp (11) 95500-0000 · seg-sex 8h-18h",action:"Abrir WhatsApp",onClick:()=>window.open("https://wa.me/5511955000000","_blank")},{icon:ke,color:"#F59E0B",title:"Email",desc:"[email protected] â resposta em até 24h úteis",action:"Enviar email",onClick:()=>window.open("mailto:[email protected]","_blank")}];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"card p-6",children:[e.jsx("h3",{className:"text-base font-bold mb-1",style:{color:"var(--page-text)"},children:"Como podemos ajudar?"}),e.jsx("p",{className:"text-xs mb-6",style:{color:"var(--page-text-muted)"},children:"Encontre respostas rápidas ou fale diretamente com nosso time"}),e.jsx("div",{className:"grid md:grid-cols-2 gap-3",children:s.map(l=>e.jsx("button",{onClick:l.onClick,className:"p-4 rounded-xl text-left transition-all hover:scale-[1.01] hover:shadow-md",style:{background:"var(--surface-secondary)",border:"1px solid var(--border-primary)"},children:e.jsxs("div",{className:"flex items-start gap-3 mb-2",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center shrink-0",style:{background:`${l.color}15`},children:e.jsx(l.icon,{className:"w-5 h-5",style:{color:l.color}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-bold",style:{color:"var(--page-text)"},children:l.title}),e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--page-text-muted)"},children:l.desc})]}),e.jsx(Ga,{className:"w-4 h-4 shrink-0 mt-1",style:{color:"var(--page-text-muted)"}})]})},l.title))})]}),e.jsxs("div",{className:"card p-6",children:[e.jsx("h3",{className:"text-sm font-bold mb-3",style:{color:"var(--page-text)"},children:"Recursos rápidos"}),e.jsx("div",{className:"space-y-2",children:[{t:"Como cadastrar meu primeiro veÃculo",url:"#"},{t:"Como convidar motoristas",url:"#"},{t:"Como gerar um despacho",url:"#"},{t:"Como funciona o Copiloto IA",url:"#"},{t:"Como emitir NFe/CTe/MDFe",url:"#"}].map(l=>e.jsxs("a",{href:l.url,className:"flex items-center justify-between p-3 rounded-lg transition-colors hover:bg-white/5",style:{color:"var(--page-text)"},children:[e.jsx("span",{className:"text-sm",children:l.t}),e.jsx(Ga,{className:"w-3.5 h-3.5",style:{color:"var(--page-text-muted)"}})]},l.t))})]})]})}function vt(){const s=Cs(),{data:l,loading:o,refetch:c}
21=me(()=>j.extrattaConfig(),[]),{data:t,loading:n}=me(()=>j.fiscalConfig(),[]),d=!!(l!=null&&l.configured),h=!!(t!=null&&t.focusToken)||!!(t!=null&&t.configured),p=(()=>{try{return!!localStorage.getItem("onboarding-antt-2026:completed")}catch{return!1}})(),x=[{id:"extratta",label:"Extratta â CIOT, PEF, VPO, Diárias",desc:"IPEF credenciada que emite seus CIOTs e processa o pagamento aos motoristas.",status:d?"ok":"pendente",statusLabel:d?`Configurada · ${(l==null?void 0:l.environment)==="prod"?"Produção":"Homologação"}`:"Não configurada",icon:na,action:{label:d?"Gerenciar":"Configurar",onClick:()=>s("/admin?tab=extratta")}},{id:"fiscal",label:"Provedor Fiscal â CT-e, MDF-e, NF-e",desc:"Provedor que emite seus documentos fiscais. Vincula o CIOT ao MDF-e (Resolução 6.078/2026).",status:h?"ok":"pendente",statusLabel:h?"Configurada":"Não configurada",icon:ge,action:{label:h?"Gerenciar":"Configurar",onClick:()=>s("/onboarding/antt")}},{id:"certificado",label:"Certificado Digital A1",desc:"Certificado ICP-Brasil .pfx necessário para emitir NF-e/CT-e/MDF-e.",status:"parcial",statusLabel:"Verificar tab Certificado Digital",icon:ta,action:{label:"Abrir",onClick:()=>s("/settings?tab=certificado")}},{id:"rntrc",label:"RNTRC â Registro ANTT",desc:"Registro Nacional de Transportadores Rodoviários de Cargas. Obrigatório.",status:"parcial",statusLabel:"Ver no painel ANTT",icon:U,action:{label:"Verificar",onClick:()=>s("/configuracoes?tab=antt")}}];if(o||n)return e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(R,{className:"w-6 h-6 text-indigo-400 animate-spin"})});const u=x.every(f=>f.status==="ok"),y=x.filter(f=>f.status==="pendente").length;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("header",{children:[e.jsx("h2",{className:"text-xl font-bold",style:{color:"var(--page-text)"},children:"Compliance ANTT 2026"}),e.jsx("p",{className:"text-sm text-slate-400 mt-1",children:"Status de configuração das integrações regulatórias da plataforma."})]}),e.jsxs("div",{className:"rounded-xl border p-4 flex items-start gap-3 "+(u?"bg-emerald-500/5 border-emerald-500/30":y>0?"bg-amber-500/5 border-amber-500/30":"bg-blue-500/5 border-blue-500/30"),children:[u?e.jsx(Y,{className:"w-5 h-5 text-emerald-400 mt-0.5 shrink-0"}):e.jsx(te,{className:"w-5 h-5 text-amber-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:`font-semibold ${u?"text-emerald-300":"text-amber-300"}`,children:u?"Sua plataforma está pronta para emitir CIOTs e MDF-es.":`${y||x.filter(f=>f.status!=="ok").length} configuração(ões) pendente(s)`}),e.jsx("p",{className:"text-xs text-slate-400 mt-1",children:u?"Todas as integrações regulatórias estão ativas.":"Configure os itens abaixo ou execute o assistente guiado de onboarding."})]}),!p&&e.jsxs("button",{onClick:()=>s("/onboarding/antt"),className:"px-3 py-1.5 rounded-lg bg-indigo-600 hover:bg-indigo-500 text-white text-xs font-medium flex items-center gap-1.5 shrink-0",children:[e.jsx(H,{className:"w-3.5 h-3.5"}),"Iniciar onboarding"]})]}),e.jsx("div",{className:"space-y-2",children:x.map(f=>{const A=f.icon,F=f.status==="ok"?"text-emerald-300":f.status==="pendente"?"text-amber-300":"text-slate-400",w=f.status==="ok"?"bg-emerald-500/10 border-emerald-500/30":f.status==="pendente"?"bg-amber-500/10 border-amber-500/30":"bg-slate-700/30 border-slate-700/50";return e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/40 p-4 flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-slate-800/60 flex items-center justify-center shrink-0",children:e.jsx(A,{className:"w-5 h-5 text-slate-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium",style:{color:"var(--page-text)"},children:f.label}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:f.desc}),e.jsxs("span",{className:`inline-flex items-center gap-1 mt-2 px-2 py-0.5 rounded-full text-[11px] font-medium border ${w} ${F}`,children:[f.status==="ok"?e.jsx(Y,{className:"w-3 h-3"}):f.status==="pendente"?e.jsx(te,{className:"w-3 h-3"}):e.jsx(os,{className:"w-3 h-3"}),f.statusLabel]})]}),e.jsx("button",{onClick:f.action.onClick,className:"shrink-0 px-3 py-1.5 rounded-md bg-slate-800 hover:bg-slate-700 text-slate-200 text-xs font-medium border border-slate-700",children:f.action.label})]},f.id)})}),e.jsxs("div",{className:"rounded-xl border border-indigo-500/20 bg-indigo-500/5 p-4",children:[e.jsx("p",{className:"text-sm font-semibold text-indigo-300 mb-3",children:"Atalhos rápidos"}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-2",children:[e.jsxs("button",{onClick:()=>s("/configuracoes?tab=antt"),className:"flex items-center justify-between gap-2 px-3 py-2 rounded-lg bg-slate-800/40 hover:bg-slate-800/60 text-sm text-slate-200 border border-slate-700/50",children:[e.jsx("span",{children:"Painel de Compliance"}),e.jsx(re,{className:"w-3.5 h-3.5 text-slate-500"})]}),e.jsxs("button",{onClick:()=>s("/configuracoes?tab=antt"),className:"flex items-center justify-between gap-2 px-3 py-2 rounded-lg bg-slate-800/40 hover:bg-slate-800/60 text-sm text-slate-200 border border-slate-700/50",children:[e.jsx("span",{children:"Gestão de TAC-Agregados"}),e.jsx(re,{className:"w-3.5 h-3.5 text-slate-500"})]}),e.jsxs("button",{onClick:()=>s("/onboarding/antt"),className:"flex items-center justify-between gap-2 px-3 py-2 rounded-lg bg-slate-800/40 hover:bg-slate-800/60 text-sm text-slate-200 border border-slate-700/50",children:[e.jsx("span",{children:"Refazer onboarding ANTT"}),e.jsx(re,{className:"w-3.5 h-3.5 text-slate-500"})]}),e.jsxs("button",{onClick:()=>c(),className:"flex items-center justify-between gap-2 px-3 py-2 rounded-lg bg-slate-800/40 hover:bg-slate-800/60 text-sm text-slate-200 border border-slate-700/50",children:[e.jsx("span",{children:"Atualizar status"}),e.jsx(R,{className:"w-3.5 h-3.5 text-slate-500"})]})]})]})]})}export{Mt as ExtrattaConfigTab,Ot as SerproConfigTab,It as SettingsPage};
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.