PageSourceSearch

https://sentinel-365-c9d4f.web.app/assets/ClientesHub-CLg3vCZx.js

js sentinel-365-c9d4f.web.app collected 2026-10-03 12:36:07 UTC 30,968 bytes, 6 lines download raw bytes

1import{r as c,j as e,u as ne}from"./react-vendor-pafHdoJx.js";import{j as ce,u as te,d as h,M as L,I as v,c as ie}from"./index-Db0fDLGN.js";import{u as de}from"./useDeferredAction-86-QvT0b.js";import{ad as X,as as me,L as B,aB as xe,k as he,aY as pe,aC as ue,c as le,bB as G,x as re,an as oe,ao as je,s as ge,ap as H,a5 as Y,a as ve,aw as be,w as q,B as Ne,_ as fe,ak as Ce,aa as we,c6 as ye}from"./ui-vendor-DLXJn6s3.js";import Se from"./SolicitacoesPage-Z768hcyX.js";import ke from"./TabelaFretePage-aDBePhQv.js";import{PixChavePage as Ee,VincularCartaoPage as Pe}from"./ExtrattaPages-DFiYn7hQ.js";import"./map-vendor-Dr8zbd0c.js";import"./firebase-vendor-D3UzkAhn.js";import"./ErrorState-B9i6eo2M.js";import"./pii-mask-CjnkDN7A.js";import"./errors-SShhAJmM.js";const J=`${window.location.origin}/embarcador`;function De({parceiroId:n,parceiroNome:w,variant:N="card"}){const{confirmar:f}=ce(),{toast:R}=te(),[A,z]=c.useState([]),[E,S]=c.useState(!0),[k,i]=c.useState(!1),[T,d]=c.useState(null),y=c.useCallback(async()=>{S(!0);try{const t=await h.portalEmbarcadorLinks(),u=Array.isArray(t)?t:(t==null?void 0:t.links)||[],F=n?u.filter(I=>I.parceiroId===n):u;z(F)}catch{z([])}finally{S(!1)}},[n]);c.useEffect(()=>{y()},[y]);const P=async()=>{if(n){i(!0);try{await h.portalEmbarcadorGenerate({dispatchId:"",parceiroId:n,expiresInDays:90}),await y()}catch(t){R({title:"Não consegui gerar o link",description:(t==null?void 0:t.message)||"Tente novamente.",kind:"error"})}finally{i(!1)}}},g=async t=>{const u=`${J}/${t.token}`;try{await navigator.clipboard.writeText(u),d(t.id),window.setTimeout(()=>d(null),2e3)}catch{window.prompt("Copie o link:",u)}},D=async t=>{if(await f({titulo:"Revogar este link?",descricao:"O embarcador perde o acesso na hora.",confirmar:"Revogar"}))try{await h.portalEmbarcadorDeactivate(t.id),await y()}catch(u){R({title:"Não consegui revogar",description:(u==null?void 0:u.message)||"Tente novamente.",kind:"error"})}},l=N==="card"?"rounded-xl border border-slate-700/50 bg-slate-900/40 p-4":"";return e.jsxs("div",{className:l,children:[e.jsxs("header",{className:"flex items-center justify-between gap-3 mb-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{className:"w-4 h-4 text-indigo-400"}),e.jsx("h3",{className:"text-sm font-semibold",style:{color:"var(--page-text)"},children:"Acessos ao Portal do Embarcador"}),w&&e.jsxs("span",{className:"text-xs text-slate-500",children:["· ",w]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:y,className:"p-1.5 rounded-md text-slate-400 hover:text-slate-200 hover:bg-slate-800/60",title:"Atualizar lista",children:e.jsx(me,{className:"w-3.5 h-3.5"})}),n&&e.jsxs("button",{onClick:P,disabled:k,className:"px-3 py-1.5 rounded-md bg-indigo-600 hover:bg-indigo-500 disabled:opacity-60 text-white text-xs font-medium flex items-center gap-1.5",children:[k?e.jsx(B,{className:"w-3 h-3 animate-spin"}):e.jsx(X,{className:"w-3 h-3"}),"Gerar novo link"]})]})]}),E?e.jsx("div",{className:"flex items-center justify-center py-6",children:e.jsx(B,{className:"w-4 h-4 text-slate-500 animate-spin"})}):A.length===0?e.jsx("p",{className:"text-xs text-slate-500 italic py-3",children:n?'Nenhum acesso gerado para este embarcador. Clique em "Gerar novo link" acima.':"Nenhum acesso ativo. Vá em Embarcadores e gere um link para começar."}):e.jsx("ul",{className:"space-y-1.5",children:A.map(t=>e.jsx("li",{className:"rounded-lg border p-2.5 "+(t.ativo?"bg-slate-800/40 border-slate-700/50":"bg-slate-900/40 border-slate-800/40 opacity-60"),children:e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-xs font-medium truncate",style:{color:"var(--page-text)"},children:t.parceiroNome||t.parceiroId||"Sem embarcador"}),e.jsxs("p",{className:"text-[10px] text-slate-500 font-mono truncate",children:[J,"/",t.token.slice(0,12),"…"]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-[10px] text-slate-500",children:[t.criadoEm&&e.jsxs("span",{children:["Criado: ",new Date(t.criadoEm).toLocaleDateString("pt-BR")]}),t.expiraEm&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(xe,{className:"w-2.5 h-2.5"}),"Expira: ",new Date(t.expiraEm).toLocaleDateString("pt-BR")]}),t.ultimoAcesso&&e.jsxs("span",{children:["Último acesso: ",new Date(t.ultimoAcesso).toLocaleDateString("pt-BR")]})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>g(t),className:"p-1.5 rounded-md text-slate-400 hover:text-emerald-400 hover:bg-emerald-500/10",title:"Copiar link",children:T===t.id?e.jsx(he,{className:"w-3.5 h-3.5 text-emerald-400"}):e.jsx(pe,{className:"w-3.5 h-3.5"})}),e.jsx("a",{href:`${J}/${t.token}`,target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded-md text-slate-400 hover:text-indigo-400 hover:bg-indigo-500/10",title:"Abrir portal",children:e.jsx(ue,{className:"w-3.5 h-3.5"})}),t.ativo&&e.jsx("button",{onClick:()=>D(t),className:"p-1.5 rounded-md text-slate-400 hover:text-red-400 hover:bg-red-500/10",title:"Revogar link",children:e.jsx(le,{className:"w-3.5 h-3.5"})})]})]})},t.id))})]})}const Fe=["AC","AL","AM","AP","BA","CE","DF","ES","GO","MA","MG","MS","MT","PA","PB","PE","PI","PR","RJ","RN","RO","RR","RS","SC","SE","SP","TO"];function ae(n){return n.replace(/\D/g,"").replace(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/,"$1.$2.$3/$4-$5")}
1function W(n){return n.toLocaleString("pt-BR",{style:"currency",currency:"BRL"})}function Re(){var U;const[n,w]=c.useState([]),[N,f]=c.useState(!0),[R,A]=c.useState(""),[z,E]=c.useState(!1),[S,k]=c.useState(null),[i,T]=c.useState(null),[d,y]=c.useState({razaoSocial:"",nomeFantasia:"",cnpj:"",inscricaoEstadual:"",endereco:"",cidade:"",uf:"SP",cep:"",telefone:"",email:"",contato:"",segmento:"",condicaoPagamento:"30 dias",observacoes:""}),[P,g]=c.useState(!1),[D,l]=c.useState(""),{toast:t}=te(),u=async()=>{try{const s=await h.tmsEmbarcadores();w(s||[])}catch(s){t({kind:"error",title:"Falha ao carregar embarcadores",description:s==null?void 0:s.message})}f(!1)};c.useEffect(()=>{u()},[]);const F=n.filter(s=>s.ativo!==!1).filter(s=>{var m,C,V;if(!R)return!0;const r=R.toLowerCase();return((m=s.razaoSocial)==null?void 0:m.toLowerCase().includes(r))||((C=s.cnpj)==null?void 0:C.includes(r))||((V=s.cidade)==null?void 0:V.toLowerCase().includes(r))}),I=()=>{k(null),y({razaoSocial:"",nomeFantasia:"",cnpj:"",inscricaoEstadual:"",endereco:"",cidade:"",uf:"SP",cep:"",telefone:"",email:"",contato:"",segmento:"",condicaoPagamento:"30 dias",observacoes:""}),E(!0)},K=s=>{k(s),y({razaoSocial:s.razaoSocial||"",nomeFantasia:s.nomeFantasia||"",cnpj:s.cnpj||"",inscricaoEstadual:s.inscricaoEstadual||"",endereco:s.endereco||"",cidade:s.cidade||"",uf:s.uf||"SP",cep:s.cep||"",telefone:s.telefone||"",email:s.email||"",contato:s.contato||"",segmento:s.segmento||"",condicaoPagamento:s.condicaoPagamento||"30 dias",observacoes:s.observacoes||""}),E(!0)},$=async()=>{var r;if(l(""),!((r=d.razaoSocial)!=null&&r.trim())){l("Razão Social é obrigatória.");return}if((d.cnpj||"").replace(/\D/g,"").length!==14){l("CNPJ inválido (deve ter 14 dígitos).");return}g(!0);try{S?await h.tmsUpdateEmbarcador(S.id,d):await h.tmsCreateEmbarcador(d),E(!1),t({kind:"success",title:S?"Embarcador atualizado":"Embarcador criado"}),u()}catch(m){t({kind:"error",title:"Falha ao salvar embarcador",description:(m==null?void 0:m.message)||"Erro desconhecido"})}finally{g(!1)}},M=de(),O=s=>{const r=n.find(m=>m.id===s);r&&M.run({toastTitle:`${r.razaoSocial||"Embarcador"} desativado`,toastDescription:"Você tem 6 segundos para desfazer.",onOptimistic:()=>w(m=>m.filter(C=>C.id!==s)),onUndo:()=>w(m=>m.some(C=>C.id===s)?m:[...m,r]),onCommit:()=>h.tmsDeleteEmbarcador(s)})},_=async s=>{try{const r=await h.tmsEmbarcador(s);T(r)}catch{}},x=async s=>{try{const r=await h.portalEmbarcadorGenerate({dispatchId:"",parceiroId:s.id,expiresInDays:90}),m=(r==null?void 0:r.token)||(r==null?void 0:r.id);if(!m){alert("Não foi possível gerar o link agora. Tente novamente em instantes.");return}const C=`${window.location.origin}/embarcador/${m}`;try{await navigator.clipboard.writeText(C),alert(`Link do portal copiado para área de transferência:
2
3${C}
4
5Envie para ${s.razaoSocial}.
6Validade: 90 dias.`)}catch{prompt("Copie o link do portal:",C)}}catch(r){alert(`Erro ao gerar link: ${r.message||"tente novamente"}`)}},j=(s,r)=>y(m=>({...m,[s]:r}));return e.jsxs("div",{className:"space-y-6 max-w-7xl",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-500/15 flex items-center justify-center",children:e.jsx(G,{className:"w-5 h-5 text-blue-400"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",style:{color:"var(--page-text)"},children:"Embarcadores"}),e.jsx("p",{className:"text-sm",style:{color:"var(--page-text-secondary)"},children:"Cadastro de clientes que enviam carga"})]})]}),e.jsxs("button",{onClick:I,className:"btn-primary text-sm flex items-center gap-1",children:[e.jsx(re,{className:"w-4 h-4"})," Novo Embarcador"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(oe,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-500"}),e.jsx("input",{value:R,onChange:s=>A(s.target.value),placeholder:"Buscar por razão social, CNPJ ou cidade...",className:"input pl-10 w-full max-w-md"})]}),N?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(B,{className:"w-6 h-6 text-brand-400 animate-spin"})}):e.jsxs("div",{className:"grid gap-3",children:[F.map(s=>e.jsxs("div",{className:"bg-slate-800/50 border border-slate-700/40 rounded-xl p-4 flex items-center justify-between hover:bg-slate-800/80 transition-colors cursor-pointer",onClick:()=>_(s.id),children:[e.jsxs("div",{className:"flex items-center gap-4 min-w-0",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-500/10 flex items-center justify-center shrink-0",children:e.jsx(G,{className:"w-5 h-5 text-blue-400"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-white truncate",children:s.razaoSocial}),e.jsxs("p",{className:"text-xs",style:{color:"var(--page-text-secondary)"},children:[ae(s.cnpj||"")," · ",s.cidade,"/",s.uf," · ",s.condicaoPagamento]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"text-right hidden sm:block",children:[e.jsx("p",{className:"text-sm font-bold text-emerald-400",children:W(s.totalFaturado||0)}),e.jsxs("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:[s.totalFretes||0," fretes"]})]}),e.jsx("button",{onClick:r=>{r.stopPropagation(),x(s)},className:"p-2 text-slate-400 hover:text-indigo-400",title:"Gerar link do portal do embarcador",children:e.jsx(X,{className:"w-4 h-4"})}),e.jsx("button",{onClick:r=>{r.stopPropagation(),K(s)},className:"p-2 text-slate-400 hover:text-white",children:e.jsx(je,{className:"w-4 h-4"})}),e.jsx("button",{onClick:r=>{r.stopPropagation(),O(s.id)},className:"p-2 text-slate-400 hover:text-red-400",children:e.jsx(le,{className:"w-4 h-4"})}),e.jsx(ge,{className:"w-4 h-4 text-slate-600"})]})]},s.id)),F.length===0&&e.jsx("p",{className:"text-sm text-slate-500 text-center py-8",children:"Nenhum embarcador cadastrado."})]}),e.jsx(L,{open:!!i,onClose:()=>T(null),title:i==null?void 0:i.razaoSocial,description:i?ae(i.cnpj||""):void 0,size:"lg",icon:e.jsx(G,{className:"w-5 h-5"}),intent:"info",children:i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4 text-sm mb-6",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500",children:"Cidade:"})," ",e.jsxs("span",{className:"text-white ml-1",children:[i.cidade,"/",i.uf]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500",children:"Telefone:"})," ",e.jsx("span",{className:"text-white ml-1",children:i.telefone||"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500",children:"Email:"})," ",e.jsx("span",{className:"text-white ml-1",children:i.email||"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500",children:"Contato:"})," ",e.jsx("span",{className:"text-white ml-1",children:i.contato||"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500",children:"Pagamento:"})," ",e.jsx("span",{className:"text-white ml-1",children:i.condicaoPagamento})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500",children:"Total faturado:"})," ",e.jsx("span",{className:"text-emerald-400 ml-1 font-bold",children:W(i.totalFaturado||0)})]})]}),((U=i.fretes)==null?void 0:U.length)>0&&e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-300 mb-2",children:"Últimos fretes"}),e.jsx("div",{className:"space-y-2",children:i.fretes.slice(0,5).map(s=>e.jsxs("div",{className:"bg-slate-800 rounded-lg p-3 text-xs text-slate-400 flex justify-between",children:[e.jsxs("span",{children:[s.origemCidade,"/",s.origemUf," → ",s.destinoCidade,"/",s.destinoUf]}),e.jsx("span",{className:"text-white font-medium",children:W(s.valorFrete||0)})]},s.id))})]}),e.jsx(De,{parceiroId:i.id,parceiroNome:i.razaoSocial,variant:"card"})]})}),e.jsx(L,{open:z,onClose:()=>E(!1),title:`${S?"Editar":"Novo"}
6 Embarcador`,size:"lg",icon:e.jsx(G,{className:"w-5 h-5"}),intent:"default",children:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx("label",{className:"label",children:"Razão Social *"}),e.jsx(v,{value:d.razaoSocial,onChange:s=>j("razaoSocial",s)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Nome Fantasia"}),e.jsx(v,{value:d.nomeFantasia,onChange:s=>j("nomeFantasia",s)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"CNPJ *"}),e.jsx(v,{mask:"cnpj",value:d.cnpj,onChange:s=>j("cnpj",s),placeholder:"00.000.000/0000-00"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Inscrição Estadual"}),e.jsx(v,{value:d.inscricaoEstadual,onChange:s=>j("inscricaoEstadual",s)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Endereço"}),e.jsx(v,{value:d.endereco,onChange:s=>j("endereco",s)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Cidade"}),e.jsx(v,{value:d.cidade,onChange:s=>j("cidade",s)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"UF"}),e.jsx("select",{value:d.uf,onChange:s=>j("uf",s.target.value),className:"input",children:Fe.map(s=>e.jsx("option",{children:s},s))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"CEP"}),e.jsx(v,{mask:"cep",value:d.cep,onChange:s=>j("cep",s),placeholder:"00000-000"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Telefone"}),e.jsx(v,{mask:"telefone",value:d.telefone,onChange:s=>j("telefone",s),placeholder:"(00) 00000-0000"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Email"}),e.jsx(v,{type:"email",value:d.email,onChange:s=>j("email",s)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Contato"}),e.jsx(v,{value:d.contato,onChange:s=>j("contato",s),placeholder:"Nome do responsável"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Segmento"}),e.jsx(v,{value:d.segmento,onChange:s=>j("segmento",s),placeholder:"ex: Indústria, Varejo..."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Condição Pagamento"}),e.jsxs("select",{value:d.condicaoPagamento,onChange:s=>j("condicaoPagamento",s.target.value),className:"input",children:[e.jsx("option",{children:"À vista"}),e.jsx("option",{children:"15 dias"}),e.jsx("option",{children:"30 dias"}),e.jsx("option",{children:"45 dias"}),e.jsx("option",{children:"60 dias"})]})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx("label",{className:"label",children:"Observações"}),e.jsx("textarea",{value:d.observacoes,onChange:s=>j("observacoes",s.target.value),className:"input resize-none",rows:2})]})]}),e.jsxs(L.Footer,{children:[D&&e.jsx("p",{className:"text-xs text-red-300 mr-auto self-center",role:"alert",children:D}),e.jsx("button",{onClick:()=>E(!1),className:"btn-ghost text-sm",children:"Cancelar"}),e.jsxs("button",{onClick:$,disabled:P,className:"btn-primary text-sm",children:[P?e.jsx(B,{className:"w-4 h-4 animate-spin"}):e.jsx(H,{className:"w-4 h-4"})," Salvar"]})]})]})})]})}const Te={draft:{label:"Rascunho",color:"bg-slate-500"},sent:{label:"Enviada",color:"bg-blue-500"},accepted:{label:"Aceita",color:"bg-emerald-500"},dispatched:{label:"Despachada",color:"bg-violet-500"},refused:{label:"Recusada",color:"bg-red-500"}};function se(n){return n.toLocaleString("pt-BR",{style:"currency",currency:"BRL"})}function $e(n){if(!n)return"—";try{return new Date(n).toLocaleDateString("pt-BR")}catch{return"—"}}function Ae(){var Q;const n=ne(),[w,N]=c.useState([]),[f,R]=c.useState(null),[A,z]=c.useState([]),[E,S]=c.useState(!0),[k,i]=c.useState("all"),[T,d]=c.useState(""),[y,P]=c.useState(!1),[g,D]=c.useState(null),[l,t]=c.useState({}),[u,F]=c.useState(!1),[I,K]=c.useState([]),$=async()=>{try{const[a,o,b,p]=await Promise.all([h.tmsCotacoes(k!=="all"?k:void 0),h.tmsCotacaoDashboard(),h.tmsEmbarcadores(),h.drivers()]);N(a||[]),R(o),z(b||[]),K(p||[])}catch{}S(!1)};c.useEffect(()=>{S(!0),$()},[k]);const M=w.filter(a=>{var b,p,Z,ee;if(!T)return!0;const o=T.toLowerCase();return((b=a.numero)==null?void 0:b.toLowerCase().includes(o))||((p=a.embarcadorNome)==null?void 0:p.toLowerCase().includes(o))||((Z=a.origemCidade)==null?void 0:Z.toLowerCase().includes(o))||((ee=a.destinoCidade)==null?void 0:ee.toLowerCase().includes(o))}),O={geral:{2:2.97,3:3.21,4:3.45,5:3.69,6:3.93,7:4.41,9:5.13},granel_solido:{2:2.52,3:2.73,4:2.94,5:3.15,6:3.36,7:3.78,9:4.41},granel_liquido:{2:3.15,3:3.39,4:3.63,5:3.87,6:4.11,7:4.59,9:5.31},frigorificada:{2:3.6,3:3.87,4:4.14,5:4.41,6:4.68,7:5.22,9:6.03},neogranel:{2:2.79,3:3.03,4:3.27,5:3.51,6:3.75,7:4.23,9:4.95},perigosa:{2:3.78,3:4.05,4:4.32,5:4.59,6:4.86,7:5.4,9:6.21}},_=(a,o,b)=>{const p=O[a]||O.geral;return Math.round((p[o]||p[6]||3.93)*b*100)/100},x=(a,o)=>t(b=>{const p={...b,[a]:o};return["valorFrete","valorPedagio","valorSeguro"].includes(a)&&(p.valorTotal=Number(p.valorFrete||0)+Number(p.valorPedagio||0)+Number(p.valorSeguro||0)),["distanciaKm","tipoCarga","eixos"].includes(a)&&(p.pisoMinimo=_(p.tipoCarga||"geral",Number(p.eixos||6),Number(p.distanciaKm||0))),p}),j=()=>{t({embarcadorId:"",embarcadorNome:"",origemCidade:"",origemUf:"SP",destinoCidade:"",destinoUf:"SP",distanciaKm:0,tipoCarga:"geral",descricaoCarga:"",pesoCarga:0,valorCarga:0,eixos:6,valorFrete:0,valorPedagio:0,valorSeguro:0,valorTotal:0,condicaoPagamento:"30 dias",dataColeta:"",dataEntrega:"",observacoes:""}),P(!0)},U=async()=>{F(!0);try{await h.tmsCreateCotacao(l),P(!1),$()}catch(a){alert(`Falha ao criar cotação: ${(a==null?void 0:a.message)||"erro de
6sconhecido"}`)}finally{F(!1)}},s=async a=>{try{const o=await h.tmsCotacaoWhatsApp(a);o.whatsappUrl&&window.open(o.whatsappUrl,"_blank"),$()}catch{alert("Erro ao gerar link WhatsApp")}},r=async a=>{if(confirm("Marcar como aceita pelo embarcador?"))try{await h.tmsAceitarCotacao(a),$()}catch{}},m=async a=>{const o=prompt("Motivo da recusa:");if(o!==null)try{await h.tmsRecusarCotacao(a,o),$()}catch{}},C=async()=>{if(g){F(!0);try{await h.tmsDespacharCotacao(g.id,{driverId:l.driverId,driverName:l.driverName,vehiclePlate:l.vehiclePlate,scheduledDate:l.scheduledDate}),D(null),alert("Despacho criado!"),$(),n("/despacho")}catch(a){alert(`Falha ao despachar: ${(a==null?void 0:a.message)||"erro desconhecido"}`)}finally{F(!1)}}},V=a=>{const o=A.find(b=>b.id===a);o&&(x("embarcadorId",a),t(b=>({...b,embarcadorId:a,embarcadorNome:o.razaoSocial,embarcadorCnpj:o.cnpj,embarcadorEmail:o.email,embarcadorTelefone:o.telefone})))};return e.jsxs("div",{className:"space-y-6 max-w-7xl",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-500/15 flex items-center justify-center",children:e.jsx(Y,{className:"w-5 h-5 text-blue-400"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",style:{color:"var(--page-text)"},children:"Cotações de Frete"}),e.jsx("p",{className:"text-sm",style:{color:"var(--page-text-secondary)"},children:"Da proposta ao despacho"})]})]}),e.jsxs("button",{onClick:j,className:"btn-primary text-sm flex items-center gap-1",children:[e.jsx(re,{className:"w-4 h-4"})," Nova Cotação"]})]}),f&&e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-7 gap-3",children:[{l:"Total",v:f.total,c:"text-white"},{l:"Rascunho",v:f.draft,c:"text-slate-400"},{l:"Enviadas",v:f.sent,c:"text-blue-400"},{l:"Aceitas",v:f.accepted,c:"text-emerald-400"},{l:"Despachadas",v:f.dispatched,c:"text-violet-400"},{l:"Recusadas",v:f.refused,c:"text-red-400"},{l:"Conversão",v:`${f.taxaConversao}%`,c:"text-amber-400"}].map((a,o)=>e.jsxs("div",{className:"bg-slate-800/50 border border-slate-700/40 rounded-xl p-3 text-center",children:[e.jsx("p",{className:`text-xl font-bold ${a.c}`,children:a.v}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:a.l})]},o))}),e.jsxs("div",{className:"flex flex-wrap gap-3 items-center",children:[e.jsx("div",{className:"flex gap-1 bg-slate-800/50 rounded-lg p-1",children:[{v:"all",l:"Todas"},{v:"draft",l:"Rascunho"},{v:"sent",l:"Enviadas"},{v:"accepted",l:"Aceitas"},{v:"dispatched",l:"Despachadas"}].map(a=>e.jsx("button",{onClick:()=>i(a.v),className:`px-3 py-1.5 rounded-md text-xs font-medium transition ${k===a.v?"bg-brand-600 text-white":"text-slate-400 hover:text-white"}`,children:a.l},a.v))}),e.jsxs("div",{className:"relative flex-1 max-w-xs",children:[e.jsx(oe,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-500"}),e.jsx("input",{value:T,onChange:a=>d(a.target.value),placeholder:"Buscar...",className:"input pl-10 w-full"})]})]}),E?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(B,{className:"w-6 h-6 text-brand-400 animate-spin"})}):e.jsxs("div",{className:"space-y-2",children:[M.map(a=>{const o=Te[a.status]||{label:a.status,color:"bg-slate-500"};return e.jsxs("div",{className:"bg-slate-800/50 border border-slate-700/40 rounded-xl p-4 flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-4 min-w-0",children:[e.jsx("div",{children:e.jsx("span",{className:`inline-block px-2 py-0.5 rounded text-[10px] font-bold text-white ${o.color}`,children:o.label})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm font-semibold",style:{color:"var(--page-text)"},children:[a.numero," — ",a.embarcadorNome||"Sem embarcador"]}),e.jsxs("p",{className:"text-xs",style:{color:"var(--page-text-secondary)"},children:[a.origemCidade,"/",a.origemUf," → ",a.destinoCidade,"/",a.destinoUf," · ",a.distanciaKm,"km · ",$e(a.createdAt)]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm font-bold text-emerald-400",children:se(a.valorTotal||0)}),e.jsxs("div",{className:"flex gap-1",children:[a.status==="draft"&&e.jsxs("button",{onClick:()=>s(a.id),className:"text-xs px-2 py-1 bg-blue-500/20 text-blue-400 rounded hover:bg-blue-500/30 flex items-center gap-1",children:[e.jsx(ve,{className:"w-3 h-3"}),"Enviar"]}),a.status==="sent"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>r(a.id),className:"text-xs px-2 py-1 bg-emerald-500/20 text-emerald-400 rounded hover:bg-emerald-500/30",children:[e.jsx(H,{className:"w-3 h-3 inline"})," Aceita"]}),e.jsxs("button",{onClick:()=>m(a.id),className:"text-xs px-2 py-1 bg-red-500/20 text-red-400 rounded hover:bg-red-500/30",children:[e.jsx(be,{className:"w-3 h-3 inline"})," Recusada"]})]}),a.status==="accepted"&&e.jsxs("button",{onClick:()=>{D(a),t({driverId:"",driverName:"",vehiclePlate:"",scheduledDate:""})},className:"text-xs px-2 py-1 bg-violet-500/20 text-violet-400 rounded hover:bg-violet-500/30 flex items-center gap-1",children:[e.jsx(q,{className:"w-3 h-3"}),"Despachar"]})]})]})]},a.id)}),M.length===0&&e.jsx("p",{className:"text-sm text-slate-500 text-center py-8",children:"Nenhuma cotação encontrada."})]}),e.jsx(L,{open:y,onClose:()=>P(!1),title:"Nova Cotação",size:"lg",icon:e.jsx(Y,{className:"w-5 h-5"}),intent:"default",children:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx("label",{className:"label",children:"Embarcador"}),e.jsxs("select",{value:l.embarcadorId,onChange:a=>V(a.target.value),className:"input",children:[e.jsx("option",{value:"",children:"— Selecionar —"}),A.map(a=>e.jsx("option",{value:a.id,children:a.razaoSocial},a.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Origem Cidade"}),e.jsx(v,{value:l.origemCidade,onChange:a=>x("origemCidade",a)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Destino Cidade"}),e.jsx(v,{value:l.destinoCidade,onChange:a=>x("destinoCidade",a)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Distância (km)"}),e.jsx("input",{type:"number",value:l.distanciaKm,onChange:a=>x("distanciaKm",Number(a.target.value)),className:"input"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Descrição da Carga"}),e.jsx(v,{value:l.descricaoCarga,onChange:a=>x("descricaoCarga",a)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Peso (kg)"}),e.jsx("input",{type:"number",value:l.pesoCarga,onChange:a=>x("pesoCarga",Number(a.target.value)),className:"input"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Valor Carga (R$)"}),e.jsx("input",{type:"number",value:l.valorCarga,onChange:a=>x("valorCarga",Number(a.target.value)),className:"input"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Valor Frete (R$)"}),e.jsx("input",{type:"number",step:"0.01",value:l.valorFrete,onChange:a=>x("valorFrete",Number(a.target.value)),className:"input"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Pedágio (R$)"}),e.jsx("input",{type:"number",step:"0.01",value:l.valorPedagio,onChange:a=>x("valorPedagio",Number(a.target.value)),className:"input"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Valor Total (R$)"}),e.jsx("input",{type:"number",step:"0.01",value:l.valorTotal,className:"input bg-slate-700/50 font-bold text-emerald-400",readOnly:!0})]}),l.pisoMinimo>0&&e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Piso Mínimo ANTT"}),e.jsxs("div",{className:`input bg-slate-700/50 font-bold ${l.valorTotal<l.pisoMinimo?"text-red-400":"text-emerald-400"}`,children:["R$ ",(Q=l.pisoMinimo)==null?void 0:Q.toFixed(2)," ",l.valorTotal<l.pisoMinimo&&e.jsx("span",{className:"text-xs ml-2",children:"⚠️ ABAIXO DO PISO"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Condição Pgto"}),e.jsxs("select",{value:l.condicaoPagamento,onChange:a=>x("condicaoPagamento",a.target.value),className:"input",children:[e.jsx("option",{children:"À vista"}),e.jsx("option",{children:"15 dias"}),e.jsx("option",{children:"30 dias"}),e.jsx("option",{children:"45 dias"}),e.jsx("option",{children:"60 dias"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Data Coleta"}),e.jsx("input",{type:"date",value:l.dataColeta,onChange:a=>x("dataColeta",a.target.value),className:"input"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Data Entrega"}),e.jsx("input",{type:"date",value:l.dataEntrega,onChange:a=>x("dataEntrega",a.target.value),className:"input"})]})]}),e.jsxs(L.Footer,{children:[e.jsx("button",{onClick:()=>P(!1),className:"btn-ghost text-sm",children:"Cancelar"}),e.jsxs("button",{onClick:U,disabled:u,className:"btn-primary text-sm",children:[u?e.jsx(B,{className:"w-4 h-4 animate-spin"}):e.jsx(H,{className:"w-4 h-4"})," Criar Cotação"]})]})]})}),e.jsx(L,{open:!!g,onClose:()=>D(null),title:g?`Despachar Cotação ${g.numero}`:"",description:g?`${g.origemCidade} → ${g.destinoCidade} · ${se(g.valorTotal||0)}`:void 0,size:"md",icon:e.jsx(q,{className:"w-5 h-5"}),intent:"default",children:g&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Motorista"}),e.jsxs("select",{value:l.driverId,onChange:a=>{const o=I.find(b=>b.id===a.target.value);x("driverId",a.target.value),o&&x("driverName",o.name||o.driverName)}
6,className:"input",children:[e.jsx("option",{value:"",children:"— Selecionar —"}),I.map(a=>e.jsx("option",{value:a.id,children:a.name||a.driverName},a.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Placa"}),e.jsx(v,{mask:"placa",value:l.vehiclePlate,onChange:a=>x("vehiclePlate",a),placeholder:"ABC-1234"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Data Saída"}),e.jsx("input",{type:"date",value:l.scheduledDate,onChange:a=>x("scheduledDate",a.target.value),className:"input"})]})]}),e.jsxs(L.Footer,{children:[e.jsx("button",{onClick:()=>D(null),className:"btn-ghost text-sm",children:"Cancelar"}),e.jsxs("button",{onClick:C,disabled:u,className:"btn-primary text-sm",children:[e.jsx(q,{className:"w-4 h-4 mr-1"})," Criar Despacho"]})]})]})})]})}const Le=[{key:"embarcadores",label:"Embarcadores",icon:Ne},{key:"cotacoes",label:"Cotações",icon:fe},{key:"solicitacoes",label:"Solicitações",icon:Ce},{key:"tabela",label:"Tabela de Frete",icon:Y},{key:"pix",label:"Chaves PIX",icon:we},{key:"cartao",label:"Cartão PASS",icon:ye}];function We(){const[n,w]=c.useState("embarcadores");return e.jsxs("div",{className:"max-w-7xl",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsx("h1",{className:"text-2xl font-bold",style:{color:"var(--page-text)"},children:"Clientes"})}),e.jsx("div",{className:"flex gap-1 mb-6 overflow-x-auto pb-1 scrollbar-hide",children:Le.map(N=>e.jsxs("button",{onClick:()=>w(N.key),className:ie("flex items-center gap-1.5 px-4 py-2 rounded-lg text-sm font-medium whitespace-nowrap transition-colors",n===N.key?"shadow-sm":"hover-surface"),style:n===N.key?{background:"var(--accent-brand)",color:"#ffffff"}:{color:"var(--page-text-secondary)"},children:[e.jsx(N.icon,{className:"w-4 h-4"}),N.label]},N.key))}),n==="embarcadores"&&e.jsx(Re,{}),n==="cotacoes"&&e.jsx(Ae,{}),n==="solicitacoes"&&e.jsx(Se,{}),n==="tabela"&&e.jsx(ke,{}),n==="pix"&&e.jsx(Ee,{}),n==="cartao"&&e.jsx(Pe,{})]})}export{We as default};

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